@sixthsummit/ship-api 0.0.0-stage → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +605 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +58 -2
- package/cli/commands/add.js +537 -0
- package/cli/commands/contract.js +2 -0
- package/cli/commands/create.js +250 -0
- package/cli/commands/dev.js +227 -0
- package/cli/commands/doctor.js +286 -0
- package/cli/commands/generate.js +937 -0
- package/cli/commands/graph.js +2 -0
- package/cli/commands/migrate-orm.js +1171 -0
- package/cli/commands/update.js +37 -0
- package/cli/ship-api.js +285 -0
- package/lib/app/auth/AuthProvider.d.ts +91 -0
- package/lib/app/auth/AuthProvider.d.ts.map +1 -0
- package/lib/app/auth/AuthProvider.js +13 -0
- package/lib/app/auth/AuthProvider.js.map +1 -0
- package/lib/app/auth/adapters/firebase.d.ts +79 -0
- package/lib/app/auth/adapters/firebase.d.ts.map +1 -0
- package/lib/app/auth/adapters/firebase.js +122 -0
- package/lib/app/auth/adapters/firebase.js.map +1 -0
- package/lib/app/auth/adapters/jwtCookie.d.ts +55 -0
- package/lib/app/auth/adapters/jwtCookie.d.ts.map +1 -0
- package/lib/app/auth/adapters/jwtCookie.js +120 -0
- package/lib/app/auth/adapters/jwtCookie.js.map +1 -0
- package/lib/app/auth/index.d.ts +8 -0
- package/lib/app/auth/index.d.ts.map +1 -0
- package/lib/app/auth/index.js +7 -0
- package/lib/app/auth/index.js.map +1 -0
- package/lib/app/auth/jwt/AuthFlow.d.ts +94 -0
- package/lib/app/auth/jwt/AuthFlow.d.ts.map +1 -0
- package/lib/app/auth/jwt/AuthFlow.js +127 -0
- package/lib/app/auth/jwt/AuthFlow.js.map +1 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts +80 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.d.ts.map +1 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js +134 -0
- package/lib/app/auth/jwt/DrizzleRefreshTokenStore.js.map +1 -0
- package/lib/app/auth/jwt/JwtSigner.d.ts +123 -0
- package/lib/app/auth/jwt/JwtSigner.d.ts.map +1 -0
- package/lib/app/auth/jwt/JwtSigner.js +118 -0
- package/lib/app/auth/jwt/JwtSigner.js.map +1 -0
- package/lib/app/auth/jwt/RefreshTokenStore.d.ts +97 -0
- package/lib/app/auth/jwt/RefreshTokenStore.d.ts.map +1 -0
- package/lib/app/auth/jwt/RefreshTokenStore.js +122 -0
- package/lib/app/auth/jwt/RefreshTokenStore.js.map +1 -0
- package/lib/app/auth/permissionDefinition.d.ts +20 -0
- package/lib/app/auth/permissionDefinition.d.ts.map +1 -0
- package/lib/app/auth/permissionDefinition.js +2 -0
- package/lib/app/auth/permissionDefinition.js.map +1 -0
- package/lib/app/context/RequestContext.d.ts +59 -0
- package/lib/app/context/RequestContext.d.ts.map +1 -0
- package/lib/app/context/RequestContext.js +25 -0
- package/lib/app/context/RequestContext.js.map +1 -0
- package/lib/app/db/QueryOptions.d.ts +82 -0
- package/lib/app/db/QueryOptions.d.ts.map +1 -0
- package/lib/app/db/QueryOptions.js +37 -0
- package/lib/app/db/QueryOptions.js.map +1 -0
- package/lib/app/db/baseFields.d.ts +60 -0
- package/lib/app/db/baseFields.d.ts.map +1 -0
- package/lib/app/db/baseFields.js +54 -0
- package/lib/app/db/baseFields.js.map +1 -0
- package/lib/app/db/buildWhere.d.ts +22 -0
- package/lib/app/db/buildWhere.d.ts.map +1 -0
- package/lib/app/db/buildWhere.js +75 -0
- package/lib/app/db/buildWhere.js.map +1 -0
- package/lib/app/db/client.d.ts +111 -0
- package/lib/app/db/client.d.ts.map +1 -0
- package/lib/app/db/client.js +99 -0
- package/lib/app/db/client.js.map +1 -0
- package/lib/app/db/tenantScoped.d.ts +59 -0
- package/lib/app/db/tenantScoped.d.ts.map +1 -0
- package/lib/app/db/tenantScoped.js +54 -0
- package/lib/app/db/tenantScoped.js.map +1 -0
- package/lib/app/db/transaction.d.ts +58 -0
- package/lib/app/db/transaction.d.ts.map +1 -0
- package/lib/app/db/transaction.js +106 -0
- package/lib/app/db/transaction.js.map +1 -0
- package/lib/app/health/HealthCheck.d.ts +121 -0
- package/lib/app/health/HealthCheck.d.ts.map +1 -0
- package/lib/app/health/HealthCheck.js +151 -0
- package/lib/app/health/HealthCheck.js.map +1 -0
- package/lib/app/health/redisHealthCheck.d.ts +14 -0
- package/lib/app/health/redisHealthCheck.d.ts.map +1 -0
- package/lib/app/health/redisHealthCheck.js +21 -0
- package/lib/app/health/redisHealthCheck.js.map +1 -0
- package/lib/app/lifecycle/Bootstrapper.d.ts +92 -0
- package/lib/app/lifecycle/Bootstrapper.d.ts.map +1 -0
- package/lib/app/lifecycle/Bootstrapper.js +99 -0
- package/lib/app/lifecycle/Bootstrapper.js.map +1 -0
- package/lib/app/registry/routes.d.ts +89 -0
- package/lib/app/registry/routes.d.ts.map +1 -0
- package/lib/app/registry/routes.js +72 -0
- package/lib/app/registry/routes.js.map +1 -0
- package/lib/app/services/DrizzleEntityService.d.ts +123 -0
- package/lib/app/services/DrizzleEntityService.d.ts.map +1 -0
- package/lib/app/services/DrizzleEntityService.js +342 -0
- package/lib/app/services/DrizzleEntityService.js.map +1 -0
- package/lib/app/services/RedisProvider.d.ts +52 -0
- package/lib/app/services/RedisProvider.d.ts.map +1 -0
- package/lib/app/services/RedisProvider.js +75 -0
- package/lib/app/services/RedisProvider.js.map +1 -0
- package/lib/app/services/cache/Cache.d.ts +70 -0
- package/lib/app/services/cache/Cache.d.ts.map +1 -0
- package/lib/app/services/cache/Cache.js +18 -0
- package/lib/app/services/cache/Cache.js.map +1 -0
- package/lib/app/services/cache/InMemoryCache.d.ts +35 -0
- package/lib/app/services/cache/InMemoryCache.d.ts.map +1 -0
- package/lib/app/services/cache/InMemoryCache.js +76 -0
- package/lib/app/services/cache/InMemoryCache.js.map +1 -0
- package/lib/app/services/cache/RedisCache.d.ts +99 -0
- package/lib/app/services/cache/RedisCache.d.ts.map +1 -0
- package/lib/app/services/cache/RedisCache.js +150 -0
- package/lib/app/services/cache/RedisCache.js.map +1 -0
- package/lib/app/services/cache/cached.d.ts +30 -0
- package/lib/app/services/cache/cached.d.ts.map +1 -0
- package/lib/app/services/cache/cached.js +38 -0
- package/lib/app/services/cache/cached.js.map +1 -0
- package/lib/app/services/cache/index.d.ts +5 -0
- package/lib/app/services/cache/index.d.ts.map +1 -0
- package/lib/app/services/cache/index.js +4 -0
- package/lib/app/services/cache/index.js.map +1 -0
- package/lib/app/services/cron/defineCron.d.ts +57 -0
- package/lib/app/services/cron/defineCron.d.ts.map +1 -0
- package/lib/app/services/cron/defineCron.js +15 -0
- package/lib/app/services/cron/defineCron.js.map +1 -0
- package/lib/app/services/cron/index.d.ts +2 -0
- package/lib/app/services/cron/index.d.ts.map +1 -0
- package/lib/app/services/cron/index.js +2 -0
- package/lib/app/services/cron/index.js.map +1 -0
- package/lib/app/services/hooks/LifecycleHooks.d.ts +61 -0
- package/lib/app/services/hooks/LifecycleHooks.d.ts.map +1 -0
- package/lib/app/services/hooks/LifecycleHooks.js +85 -0
- package/lib/app/services/hooks/LifecycleHooks.js.map +1 -0
- package/lib/app/services/jobs/JobsManager.d.ts +67 -0
- package/lib/app/services/jobs/JobsManager.d.ts.map +1 -0
- package/lib/app/services/jobs/JobsManager.js +121 -0
- package/lib/app/services/jobs/JobsManager.js.map +1 -0
- package/lib/app/services/jobs/bullBoard.d.ts +72 -0
- package/lib/app/services/jobs/bullBoard.d.ts.map +1 -0
- package/lib/app/services/jobs/bullBoard.js +96 -0
- package/lib/app/services/jobs/bullBoard.js.map +1 -0
- package/lib/app/services/jobs/defineJob.d.ts +81 -0
- package/lib/app/services/jobs/defineJob.d.ts.map +1 -0
- package/lib/app/services/jobs/defineJob.js +49 -0
- package/lib/app/services/jobs/defineJob.js.map +1 -0
- package/lib/app/services/jobs/index.d.ts +4 -0
- package/lib/app/services/jobs/index.d.ts.map +1 -0
- package/lib/app/services/jobs/index.js +4 -0
- package/lib/app/services/jobs/index.js.map +1 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts +23 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.d.ts.map +1 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js +51 -0
- package/lib/app/services/rateLimit/InMemorySlidingWindowBackend.js.map +1 -0
- package/lib/app/services/rateLimit/RateLimitBackend.d.ts +41 -0
- package/lib/app/services/rateLimit/RateLimitBackend.d.ts.map +1 -0
- package/lib/app/services/rateLimit/RateLimitBackend.js +19 -0
- package/lib/app/services/rateLimit/RateLimitBackend.js.map +1 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts +16 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.d.ts.map +1 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js +80 -0
- package/lib/app/services/rateLimit/RedisSlidingWindowBackend.js.map +1 -0
- package/lib/app/services/rateLimit/index.d.ts +4 -0
- package/lib/app/services/rateLimit/index.d.ts.map +1 -0
- package/lib/app/services/rateLimit/index.js +3 -0
- package/lib/app/services/rateLimit/index.js.map +1 -0
- package/lib/app/services/storage/DiskStorageAdapter.d.ts +62 -0
- package/lib/app/services/storage/DiskStorageAdapter.d.ts.map +1 -0
- package/lib/app/services/storage/DiskStorageAdapter.js +295 -0
- package/lib/app/services/storage/DiskStorageAdapter.js.map +1 -0
- package/lib/app/services/storage/GCSStorageAdapter.d.ts +44 -0
- package/lib/app/services/storage/GCSStorageAdapter.d.ts.map +1 -0
- package/lib/app/services/storage/GCSStorageAdapter.js +133 -0
- package/lib/app/services/storage/GCSStorageAdapter.js.map +1 -0
- package/lib/app/services/storage/S3StorageAdapter.d.ts +57 -0
- package/lib/app/services/storage/S3StorageAdapter.d.ts.map +1 -0
- package/lib/app/services/storage/S3StorageAdapter.js +162 -0
- package/lib/app/services/storage/S3StorageAdapter.js.map +1 -0
- package/lib/app/services/storage/StorageService.d.ts +88 -0
- package/lib/app/services/storage/StorageService.d.ts.map +1 -0
- package/lib/app/services/storage/StorageService.js +18 -0
- package/lib/app/services/storage/StorageService.js.map +1 -0
- package/lib/app/services/storage/index.d.ts +5 -0
- package/lib/app/services/storage/index.d.ts.map +1 -0
- package/lib/app/services/storage/index.js +4 -0
- package/lib/app/services/storage/index.js.map +1 -0
- package/lib/app/utils/ContextValidators.d.ts +46 -0
- package/lib/app/utils/ContextValidators.d.ts.map +1 -0
- package/lib/app/utils/ContextValidators.js +81 -0
- package/lib/app/utils/ContextValidators.js.map +1 -0
- package/lib/app/utils/defineEnv.d.ts +80 -0
- package/lib/app/utils/defineEnv.d.ts.map +1 -0
- package/lib/app/utils/defineEnv.js +95 -0
- package/lib/app/utils/defineEnv.js.map +1 -0
- package/lib/client.d.ts +139 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +98 -0
- package/lib/client.js.map +1 -0
- package/lib/contract/application.d.ts +3 -0
- package/lib/contract/application.d.ts.map +1 -0
- package/lib/contract/application.js +2 -0
- package/lib/contract/application.js.map +1 -0
- package/lib/contract/client.d.ts +3 -0
- package/lib/contract/client.d.ts.map +1 -0
- package/lib/contract/client.js +3 -0
- package/lib/contract/client.js.map +1 -0
- package/lib/contract/index.d.ts +3 -0
- package/lib/contract/index.d.ts.map +1 -0
- package/lib/contract/index.js +3 -0
- package/lib/contract/index.js.map +1 -0
- package/lib/contract/manifest.d.ts +3 -0
- package/lib/contract/manifest.d.ts.map +1 -0
- package/lib/contract/manifest.js +2 -0
- package/lib/contract/manifest.js.map +1 -0
- package/lib/contract/openapi.d.ts +3 -0
- package/lib/contract/openapi.d.ts.map +1 -0
- package/lib/contract/openapi.js +3 -0
- package/lib/contract/openapi.js.map +1 -0
- package/lib/contract/project.d.ts +3 -0
- package/lib/contract/project.d.ts.map +1 -0
- package/lib/contract/project.js +3 -0
- package/lib/contract/project.js.map +1 -0
- package/lib/contract/schema.d.ts +3 -0
- package/lib/contract/schema.d.ts.map +1 -0
- package/lib/contract/schema.js +3 -0
- package/lib/contract/schema.js.map +1 -0
- package/lib/drizzle/index.d.ts +3 -0
- package/lib/drizzle/index.d.ts.map +1 -0
- package/lib/drizzle/index.js +3 -0
- package/lib/drizzle/index.js.map +1 -0
- package/lib/hono/auth.d.ts +6 -0
- package/lib/hono/auth.d.ts.map +1 -0
- package/lib/hono/auth.js +54 -0
- package/lib/hono/auth.js.map +1 -0
- package/lib/hono/index.d.ts +4 -0
- package/lib/hono/index.d.ts.map +1 -0
- package/lib/hono/index.js +4 -0
- package/lib/hono/index.js.map +1 -0
- package/lib/http/app/createApp.d.ts +132 -0
- package/lib/http/app/createApp.d.ts.map +1 -0
- package/lib/http/app/createApp.js +215 -0
- package/lib/http/app/createApp.js.map +1 -0
- package/lib/http/app/devRoutes.d.ts +31 -0
- package/lib/http/app/devRoutes.d.ts.map +1 -0
- package/lib/http/app/devRoutes.js +145 -0
- package/lib/http/app/devRoutes.js.map +1 -0
- package/lib/http/app/errors.d.ts +45 -0
- package/lib/http/app/errors.d.ts.map +1 -0
- package/lib/http/app/errors.js +93 -0
- package/lib/http/app/errors.js.map +1 -0
- package/lib/http/app/health.d.ts +66 -0
- package/lib/http/app/health.d.ts.map +1 -0
- package/lib/http/app/health.js +104 -0
- package/lib/http/app/health.js.map +1 -0
- package/lib/http/errors/AppError.d.ts +10 -0
- package/lib/http/errors/AppError.d.ts.map +1 -0
- package/lib/http/errors/AppError.js +19 -0
- package/lib/http/errors/AppError.js.map +1 -0
- package/lib/http/errors/AuthenticationError.d.ts +8 -0
- package/lib/http/errors/AuthenticationError.d.ts.map +1 -0
- package/lib/http/errors/AuthenticationError.js +10 -0
- package/lib/http/errors/AuthenticationError.js.map +1 -0
- package/lib/http/errors/AuthorizationError.d.ts +8 -0
- package/lib/http/errors/AuthorizationError.d.ts.map +1 -0
- package/lib/http/errors/AuthorizationError.js +10 -0
- package/lib/http/errors/AuthorizationError.js.map +1 -0
- package/lib/http/errors/BadRequestError.d.ts +8 -0
- package/lib/http/errors/BadRequestError.d.ts.map +1 -0
- package/lib/http/errors/BadRequestError.js +10 -0
- package/lib/http/errors/BadRequestError.js.map +1 -0
- package/lib/http/errors/ConflictError.d.ts +8 -0
- package/lib/http/errors/ConflictError.d.ts.map +1 -0
- package/lib/http/errors/ConflictError.js +10 -0
- package/lib/http/errors/ConflictError.js.map +1 -0
- package/lib/http/errors/InternalServerError.d.ts +8 -0
- package/lib/http/errors/InternalServerError.d.ts.map +1 -0
- package/lib/http/errors/InternalServerError.js +10 -0
- package/lib/http/errors/InternalServerError.js.map +1 -0
- package/lib/http/errors/NotFoundError.d.ts +8 -0
- package/lib/http/errors/NotFoundError.d.ts.map +1 -0
- package/lib/http/errors/NotFoundError.js +10 -0
- package/lib/http/errors/NotFoundError.js.map +1 -0
- package/lib/http/errors/RateLimitError.d.ts +13 -0
- package/lib/http/errors/RateLimitError.d.ts.map +1 -0
- package/lib/http/errors/RateLimitError.js +16 -0
- package/lib/http/errors/RateLimitError.js.map +1 -0
- package/lib/http/errors/ServiceUnavailableError.d.ts +8 -0
- package/lib/http/errors/ServiceUnavailableError.d.ts.map +1 -0
- package/lib/http/errors/ServiceUnavailableError.js +10 -0
- package/lib/http/errors/ServiceUnavailableError.js.map +1 -0
- package/lib/http/errors/ValidationError.d.ts +9 -0
- package/lib/http/errors/ValidationError.d.ts.map +1 -0
- package/lib/http/errors/ValidationError.js +12 -0
- package/lib/http/errors/ValidationError.js.map +1 -0
- package/lib/http/errors/index.d.ts +11 -0
- package/lib/http/errors/index.d.ts.map +1 -0
- package/lib/http/errors/index.js +12 -0
- package/lib/http/errors/index.js.map +1 -0
- package/lib/http/middleware/apiKey.d.ts +9 -0
- package/lib/http/middleware/apiKey.d.ts.map +1 -0
- package/lib/http/middleware/apiKey.js +71 -0
- package/lib/http/middleware/apiKey.js.map +1 -0
- package/lib/http/middleware/csrf.d.ts +63 -0
- package/lib/http/middleware/csrf.d.ts.map +1 -0
- package/lib/http/middleware/csrf.js +169 -0
- package/lib/http/middleware/csrf.js.map +1 -0
- package/lib/http/middleware/httpLogger.d.ts +39 -0
- package/lib/http/middleware/httpLogger.d.ts.map +1 -0
- package/lib/http/middleware/httpLogger.js +118 -0
- package/lib/http/middleware/httpLogger.js.map +1 -0
- package/lib/http/middleware/idempotency.d.ts +48 -0
- package/lib/http/middleware/idempotency.d.ts.map +1 -0
- package/lib/http/middleware/idempotency.js +180 -0
- package/lib/http/middleware/idempotency.js.map +1 -0
- package/lib/http/middleware/rateLimit.d.ts +105 -0
- package/lib/http/middleware/rateLimit.d.ts.map +1 -0
- package/lib/http/middleware/rateLimit.js +84 -0
- package/lib/http/middleware/rateLimit.js.map +1 -0
- package/lib/http/middleware/requireAuth.d.ts +58 -0
- package/lib/http/middleware/requireAuth.d.ts.map +1 -0
- package/lib/http/middleware/requireAuth.js +63 -0
- package/lib/http/middleware/requireAuth.js.map +1 -0
- package/lib/http/middleware/requirePermission.d.ts +23 -0
- package/lib/http/middleware/requirePermission.d.ts.map +1 -0
- package/lib/http/middleware/requirePermission.js +50 -0
- package/lib/http/middleware/requirePermission.js.map +1 -0
- package/lib/http/middleware/resolveTenant.d.ts +41 -0
- package/lib/http/middleware/resolveTenant.d.ts.map +1 -0
- package/lib/http/middleware/resolveTenant.js +17 -0
- package/lib/http/middleware/resolveTenant.js.map +1 -0
- package/lib/http/streaming/sse.d.ts +31 -0
- package/lib/http/streaming/sse.d.ts.map +1 -0
- package/lib/http/streaming/sse.js +11 -0
- package/lib/http/streaming/sse.js.map +1 -0
- package/lib/http/streaming/streamLLM.d.ts +94 -0
- package/lib/http/streaming/streamLLM.d.ts.map +1 -0
- package/lib/http/streaming/streamLLM.js +94 -0
- package/lib/http/streaming/streamLLM.js.map +1 -0
- package/lib/http/utils/authCookies.d.ts +74 -0
- package/lib/http/utils/authCookies.d.ts.map +1 -0
- package/lib/http/utils/authCookies.js +102 -0
- package/lib/http/utils/authCookies.js.map +1 -0
- package/lib/http/utils/clientIp.d.ts +85 -0
- package/lib/http/utils/clientIp.d.ts.map +1 -0
- package/lib/http/utils/clientIp.js +249 -0
- package/lib/http/utils/clientIp.js.map +1 -0
- package/lib/http/utils/index.d.ts +4 -0
- package/lib/http/utils/index.d.ts.map +1 -0
- package/lib/http/utils/index.js +5 -0
- package/lib/http/utils/index.js.map +1 -0
- package/lib/http/utils/metaTags.d.ts +49 -0
- package/lib/http/utils/metaTags.d.ts.map +1 -0
- package/lib/http/utils/metaTags.js +32 -0
- package/lib/http/utils/metaTags.js.map +1 -0
- package/lib/http/utils/publicSuffix.d.ts +34 -0
- package/lib/http/utils/publicSuffix.d.ts.map +1 -0
- package/lib/http/utils/publicSuffix.js +276 -0
- package/lib/http/utils/publicSuffix.js.map +1 -0
- package/lib/http/utils/uploads.d.ts +92 -0
- package/lib/http/utils/uploads.d.ts.map +1 -0
- package/lib/http/utils/uploads.js +126 -0
- package/lib/http/utils/uploads.js.map +1 -0
- package/lib/http/utils/validate.d.ts +41 -0
- package/lib/http/utils/validate.d.ts.map +1 -0
- package/lib/http/utils/validate.js +55 -0
- package/lib/http/utils/validate.js.map +1 -0
- package/lib/http/utils/webhooks.d.ts +63 -0
- package/lib/http/utils/webhooks.d.ts.map +1 -0
- package/lib/http/utils/webhooks.js +133 -0
- package/lib/http/utils/webhooks.js.map +1 -0
- package/lib/http/ws/auth.d.ts +46 -0
- package/lib/http/ws/auth.d.ts.map +1 -0
- package/lib/http/ws/auth.js +123 -0
- package/lib/http/ws/auth.js.map +1 -0
- package/lib/index.d.ts +80 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +61 -0
- package/lib/index.js.map +1 -0
- package/lib/kernel/index.d.ts +3 -0
- package/lib/kernel/index.d.ts.map +1 -0
- package/lib/kernel/index.js +3 -0
- package/lib/kernel/index.js.map +1 -0
- package/lib/libraries/.gitkeep +0 -0
- package/lib/libraries/ai/CHANGELOG.md +17 -0
- package/lib/libraries/ai/README.md +164 -0
- package/lib/libraries/ai/adapters/AnthropicAdapter.ts +382 -0
- package/lib/libraries/ai/adapters/LLMProvider.ts +76 -0
- package/lib/libraries/ai/adapters/OpenAIAdapter.ts +466 -0
- package/lib/libraries/ai/experimental/index.ts +20 -0
- package/lib/libraries/ai/index.ts +128 -0
- package/lib/libraries/ai/library.json +19 -0
- package/lib/libraries/ai/loop/agentLoop.ts +377 -0
- package/lib/libraries/ai/prompts/definePrompt.ts +0 -0
- package/lib/libraries/ai/rag/retrieveAndAnswer.ts +177 -0
- package/lib/libraries/ai/streaming/streamLLM.ts +94 -0
- package/lib/libraries/ai/structured/completeStructured.ts +143 -0
- package/lib/libraries/ai/tokens/Tokenizer.ts +216 -0
- package/lib/libraries/ai/tools/defineTool.ts +208 -0
- package/lib/libraries/ai/types.ts +260 -0
- package/lib/libraries/chunking/ChunkingService.ts +103 -0
- package/lib/libraries/chunking/README.md +104 -0
- package/lib/libraries/chunking/docs/api-reference.md +549 -0
- package/lib/libraries/chunking/docs/best-practices.md +321 -0
- package/lib/libraries/chunking/docs/code-organization.md +538 -0
- package/lib/libraries/chunking/docs/configuration.md +418 -0
- package/lib/libraries/chunking/docs/index.md +236 -0
- package/lib/libraries/chunking/docs/quick-start.md +298 -0
- package/lib/libraries/chunking/docs/strategies.md +407 -0
- package/lib/libraries/chunking/docs/summary.md +258 -0
- package/lib/libraries/chunking/docs/troubleshooting.md +527 -0
- package/lib/libraries/chunking/index.ts +17 -0
- package/lib/libraries/chunking/library.json +16 -0
- package/lib/libraries/chunking/strategies/ChunkingStrategy.ts +13 -0
- package/lib/libraries/chunking/strategies/FixedLengthChunkingStrategy.ts +88 -0
- package/lib/libraries/chunking/strategies/SemanticChunkingStrategy.ts +389 -0
- package/lib/libraries/chunking/strategies/SlidingWindowChunkingStrategy.ts +258 -0
- package/lib/libraries/chunking/types/index.ts +63 -0
- package/lib/libraries/email/EmailService.ts +591 -0
- package/lib/libraries/email/README.md +777 -0
- package/lib/libraries/email/TemplateRegistry.ts +148 -0
- package/lib/libraries/email/TemplateRenderer.ts +273 -0
- package/lib/libraries/email/index.ts +4 -0
- package/lib/libraries/email/initializeEmailService.ts +60 -0
- package/lib/libraries/email/library.json +12 -0
- package/lib/libraries/email/types/EmailAddress.ts +4 -0
- package/lib/libraries/email/types/EmailAttachment.ts +11 -0
- package/lib/libraries/email/types/EmailTag.ts +9 -0
- package/lib/libraries/email/types/EmailTemplate.ts +124 -0
- package/lib/libraries/email/types/SendBatchEmailsOptions.ts +9 -0
- package/lib/libraries/email/types/SendBatchEmailsResult.ts +9 -0
- package/lib/libraries/email/types/SendEmailOptions.ts +33 -0
- package/lib/libraries/email/types/SendEmailResult.ts +9 -0
- package/lib/libraries/email/types/index.ts +8 -0
- package/lib/libraries/weaviate/QueryBuilder.ts +292 -0
- package/lib/libraries/weaviate/README.md +284 -0
- package/lib/libraries/weaviate/Weaviate.ts +1419 -0
- package/lib/libraries/weaviate/WeaviateConfig.ts +268 -0
- package/lib/libraries/weaviate/docs/.gitkeep +1 -0
- package/lib/libraries/weaviate/docs/API_REFERENCE.md +1067 -0
- package/lib/libraries/weaviate/docs/CONFIGURATION.md +320 -0
- package/lib/libraries/weaviate/docs/ERROR_HANDLING.md +271 -0
- package/lib/libraries/weaviate/docs/MULTI_TENANCY.md +348 -0
- package/lib/libraries/weaviate/docs/PERFORMANCE.md +602 -0
- package/lib/libraries/weaviate/docs/PLUGIN_DEVELOPMENT.md +547 -0
- package/lib/libraries/weaviate/docs/QUICK_START.md +443 -0
- package/lib/libraries/weaviate/docs/README.md +269 -0
- package/lib/libraries/weaviate/docs/SCHEMA_GUIDE.md +630 -0
- package/lib/libraries/weaviate/docs/WEAVIATE_README.md +520 -0
- package/lib/libraries/weaviate/errors/WeaviateError.ts +92 -0
- package/lib/libraries/weaviate/errors/index.ts +1 -0
- package/lib/libraries/weaviate/index.ts +35 -0
- package/lib/libraries/weaviate/library.json +26 -0
- package/lib/libraries/weaviate/plugins/index.ts +2 -0
- package/lib/libraries/weaviate/schemas/SchemaRegistry.ts +284 -0
- package/lib/libraries/weaviate/schemas/index.ts +2 -0
- package/lib/libraries/weaviate/types/BM25SearchOptions.ts +9 -0
- package/lib/libraries/weaviate/types/ExtendedWeaviateClient.ts +7 -0
- package/lib/libraries/weaviate/types/HybridSearchOptions.ts +11 -0
- package/lib/libraries/weaviate/types/MultiTenancy.ts +81 -0
- package/lib/libraries/weaviate/types/Plugin.ts +17 -0
- package/lib/libraries/weaviate/types/SchemaConfig.ts +25 -0
- package/lib/libraries/weaviate/types/SearchMethod.ts +8 -0
- package/lib/libraries/weaviate/types/SearchOptions.ts +16 -0
- package/lib/libraries/weaviate/types/SearchRequest.ts +19 -0
- package/lib/libraries/weaviate/types/SearchResult.ts +16 -0
- package/lib/libraries/weaviate/types/SearchableField.ts +87 -0
- package/lib/libraries/weaviate/types/VectorIndexConfig.ts +19 -0
- package/lib/libraries/weaviate/types/VectorSearchOptions.ts +18 -0
- package/lib/libraries/weaviate/types/VectorizerConfig.ts +8 -0
- package/lib/libraries/weaviate/types/index.ts +29 -0
- package/lib/libraries/weaviate/utils/TenantContextManager.ts +94 -0
- package/lib/modules/accounts/index.ts +47 -0
- package/lib/modules/accounts/module.json +15 -0
- package/lib/modules/accounts/permissions.ts +33 -0
- package/lib/modules/accounts/routes.ts +200 -0
- package/lib/modules/accounts/schema.ts +219 -0
- package/lib/modules/accounts/services/AccountService.ts +44 -0
- package/lib/modules/accounts/validation/schemas.ts +70 -0
- package/lib/modules/oauth/adapters/GmailOAuthAdapter.ts +35 -0
- package/lib/modules/oauth/adapters/GoogleOAuthAdapter.ts +278 -0
- package/lib/modules/oauth/adapters/MicrosoftOAuthAdapter.ts +269 -0
- package/lib/modules/oauth/adapters/MockOAuthAdapter.ts +138 -0
- package/lib/modules/oauth/adapters/OAuthAdapter.ts +211 -0
- package/lib/modules/oauth/adapters/OAuthAdapterRegistry.ts +77 -0
- package/lib/modules/oauth/adapters/OutlookOAuthAdapter.ts +38 -0
- package/lib/modules/oauth/index.ts +79 -0
- package/lib/modules/oauth/module.json +23 -0
- package/lib/modules/oauth/permissions.ts +39 -0
- package/lib/modules/oauth/routes.ts +497 -0
- package/lib/modules/oauth/schema.ts +127 -0
- package/lib/modules/oauth/services/OAuthConnectionService.ts +147 -0
- package/lib/modules/oauth/state.ts +234 -0
- package/lib/modules/oauth/stateJtiCache.ts +85 -0
- package/lib/modules/oauth/verifyIdToken.ts +178 -0
- package/lib/modules/outbox/EventEmitter.ts +106 -0
- package/lib/modules/outbox/OutboxDrainer.ts +163 -0
- package/lib/modules/outbox/handlers/EventHandler.ts +115 -0
- package/lib/modules/outbox/index.ts +43 -0
- package/lib/modules/outbox/module.json +15 -0
- package/lib/modules/outbox/permissions.ts +36 -0
- package/lib/modules/outbox/routes.ts +219 -0
- package/lib/modules/outbox/schema.ts +207 -0
- package/lib/modules/outbox/services/OutboxEventService.ts +223 -0
- package/lib/observability/logger.d.ts +30 -0
- package/lib/observability/logger.d.ts.map +1 -0
- package/lib/observability/logger.js +110 -0
- package/lib/observability/logger.js.map +1 -0
- package/lib/observability/metrics.d.ts +3 -0
- package/lib/observability/metrics.d.ts.map +1 -0
- package/lib/observability/metrics.js +3 -0
- package/lib/observability/metrics.js.map +1 -0
- package/lib/observability/otel.d.ts +3 -0
- package/lib/observability/otel.d.ts.map +1 -0
- package/lib/observability/otel.js +3 -0
- package/lib/observability/otel.js.map +1 -0
- package/lib/observability/safeErrorFields.d.ts +14 -0
- package/lib/observability/safeErrorFields.d.ts.map +1 -0
- package/lib/observability/safeErrorFields.js +14 -0
- package/lib/observability/safeErrorFields.js.map +1 -0
- package/lib/observability/tracing.d.ts +3 -0
- package/lib/observability/tracing.d.ts.map +1 -0
- package/lib/observability/tracing.js +3 -0
- package/lib/observability/tracing.js.map +1 -0
- package/lib/package.json +4 -0
- package/lib/testing.d.ts +3 -0
- package/lib/testing.d.ts.map +1 -0
- package/lib/testing.js +3 -0
- package/lib/testing.js.map +1 -0
- package/package.json +193 -3
- package/templates/default/.claude/agents/qa-brief.md +106 -0
- package/templates/default/.claude/commands/sherpa-brief.md +23 -0
- package/templates/default/.cursor/rules/api.mdc +80 -0
- package/templates/default/.cursor/rules/commits.mdc +88 -0
- package/templates/default/.cursor/rules/security.mdc +92 -0
- package/templates/default/.cursor/rules/testing.mdc +123 -0
- package/templates/default/.cursor/rules/typescript.mdc +86 -0
- package/templates/default/.env.example +79 -0
- package/templates/default/.github/workflows/sherpa-brief.yml +180 -0
- package/templates/default/AGENTS.md +166 -0
- package/templates/default/CLAUDE.md +17 -0
- package/templates/default/README.md +97 -0
- package/templates/default/_gitignore +27 -0
- package/templates/default/docker-compose.yml +83 -0
- package/templates/default/drizzle.config.ts +34 -0
- package/templates/default/eslint.config.mjs +106 -0
- package/templates/default/package.json +57 -0
- package/templates/default/ship-api.config.ts +21 -0
- package/templates/default/src/client.ts +34 -0
- package/templates/default/src/config/modules.ts +23 -0
- package/templates/default/src/db/schema.ts +26 -0
- package/templates/default/src/environment.ts +81 -0
- package/templates/default/src/index.test.ts +53 -0
- package/templates/default/src/index.ts +11 -0
- package/templates/default/src/instrumentation.ts +13 -0
- package/templates/default/src/server.ts +90 -0
- package/templates/default/tsconfig.json +24 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# Chunking Library - Quick Start Guide
|
|
2
|
+
|
|
3
|
+
Get up and running with the chunking library in 5 minutes.
|
|
4
|
+
|
|
5
|
+
## 📦 What You Get
|
|
6
|
+
|
|
7
|
+
The chunking library provides:
|
|
8
|
+
- ✅ Three chunking strategies (Fixed Length, Sliding Window, Semantic)
|
|
9
|
+
- ✅ Accurate token counting via tiktoken (OpenAI-compatible)
|
|
10
|
+
- ✅ Structure-aware chunking that preserves meaning
|
|
11
|
+
- ✅ Strategy pattern for runtime flexibility
|
|
12
|
+
- ✅ Factory methods for quick setup
|
|
13
|
+
- ✅ Full TypeScript type safety
|
|
14
|
+
|
|
15
|
+
## 🚀 Quick Start
|
|
16
|
+
|
|
17
|
+
### 1. Import the Library
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ChunkingService } from "@sixthsummit/ship-api/libraries/chunking";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or import specific pieces:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import {
|
|
27
|
+
ChunkingService,
|
|
28
|
+
SemanticChunkingStrategy,
|
|
29
|
+
SlidingWindowChunkingStrategy,
|
|
30
|
+
FixedLengthChunkingStrategy,
|
|
31
|
+
} from "@sixthsummit/ship-api/libraries/chunking";
|
|
32
|
+
import type { TextChunk, SemanticChunkingOptions } from "@sixthsummit/ship-api/libraries/chunking";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Chunk Your Text
|
|
36
|
+
|
|
37
|
+
**Recommended: Semantic Chunking (best for RAG)**
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
const service = ChunkingService.createWithSemantic({
|
|
41
|
+
maxTokens: 512,
|
|
42
|
+
minTokens: 100,
|
|
43
|
+
mergeSmallChunks: true,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const chunks = await service.chunk(documentText);
|
|
47
|
+
|
|
48
|
+
console.log(`Created ${chunks.length} chunks`);
|
|
49
|
+
for (const chunk of chunks) {
|
|
50
|
+
console.log(`Chunk ${chunk.chunkIndex}: ${chunk.tokenCount} tokens`);
|
|
51
|
+
console.log(chunk.content.substring(0, 100) + "...");
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**That's it!** Your document is now chunked and ready for embedding.
|
|
56
|
+
|
|
57
|
+
### 3. Understand the Output
|
|
58
|
+
|
|
59
|
+
Each chunk is a `TextChunk` object:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
interface TextChunk {
|
|
63
|
+
content: string; // The text content of the chunk
|
|
64
|
+
startIndex: number; // Starting character position in original document
|
|
65
|
+
endIndex: number; // Ending character position in original document
|
|
66
|
+
tokenCount: number; // Number of tokens in this chunk
|
|
67
|
+
chunkIndex: number; // Chunk number (0-indexed)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Example output:**
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
[
|
|
75
|
+
{
|
|
76
|
+
"content": "# Introduction\n\nThis document covers...",
|
|
77
|
+
"startIndex": 0,
|
|
78
|
+
"endIndex": 1523,
|
|
79
|
+
"tokenCount": 487,
|
|
80
|
+
"chunkIndex": 0
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"content": "## Architecture\n\nThe system uses...",
|
|
84
|
+
"startIndex": 1524,
|
|
85
|
+
"endIndex": 2891,
|
|
86
|
+
"tokenCount": 412,
|
|
87
|
+
"chunkIndex": 1
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 4. Clean Up
|
|
93
|
+
|
|
94
|
+
Always dispose the service when done to free tokenizer resources:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
service.dispose();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 🎯 Common Use Cases
|
|
101
|
+
|
|
102
|
+
### Use Case 1: Chunk for Embedding Pipeline
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const service = ChunkingService.createWithSemantic({
|
|
106
|
+
maxTokens: 512, // Match your embedding model's limit
|
|
107
|
+
minTokens: 100, // Avoid tiny, meaningless chunks
|
|
108
|
+
mergeSmallChunks: true,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const chunks = await service.chunk(document);
|
|
112
|
+
|
|
113
|
+
// Send chunks to your embedding service
|
|
114
|
+
for (const chunk of chunks) {
|
|
115
|
+
const embedding = await embeddingService.embed(chunk.content);
|
|
116
|
+
await vectorStore.upsert({
|
|
117
|
+
id: `doc-${docId}-chunk-${chunk.chunkIndex}`,
|
|
118
|
+
content: chunk.content,
|
|
119
|
+
embedding,
|
|
120
|
+
metadata: {
|
|
121
|
+
docId,
|
|
122
|
+
chunkIndex: chunk.chunkIndex,
|
|
123
|
+
startIndex: chunk.startIndex,
|
|
124
|
+
endIndex: chunk.endIndex,
|
|
125
|
+
tokenCount: chunk.tokenCount,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
service.dispose();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Use Case 2: Narrative Content with Context Overlap
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const service = ChunkingService.createWithSlidingWindow({
|
|
137
|
+
maxTokens: 512,
|
|
138
|
+
overlapTokens: 80, // ~15% overlap for context
|
|
139
|
+
preferParagraphBoundaries: true, // End at paragraph breaks
|
|
140
|
+
minChunkRatio: 0.5, // Minimum 50% of maxTokens
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const chunks = await service.chunk(articleText);
|
|
144
|
+
|
|
145
|
+
// Chunks overlap, so search results have better context
|
|
146
|
+
for (const chunk of chunks) {
|
|
147
|
+
console.log(`Chunk ${chunk.chunkIndex}: ${chunk.tokenCount} tokens`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
service.dispose();
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Use Case 3: Fast Prototyping
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const service = ChunkingService.createWithFixedLength({
|
|
157
|
+
maxTokens: 256,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const chunks = await service.chunk(text);
|
|
161
|
+
console.log(`Split into ${chunks.length} chunks`);
|
|
162
|
+
|
|
163
|
+
service.dispose();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Use Case 4: Auto-Detect Strategy from Options
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// The factory auto-detects the strategy based on which options are provided
|
|
170
|
+
const service = ChunkingService.create({
|
|
171
|
+
maxTokens: 512,
|
|
172
|
+
overlapTokens: 80, // Presence of overlapTokens → Sliding Window
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Or:
|
|
176
|
+
const service2 = ChunkingService.create({
|
|
177
|
+
maxTokens: 512,
|
|
178
|
+
minTokens: 100, // Presence of minTokens → Semantic
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Or:
|
|
182
|
+
const service3 = ChunkingService.create({
|
|
183
|
+
maxTokens: 512, // Only maxTokens → Fixed Length
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Use Case 5: Switch Strategy at Runtime
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
191
|
+
|
|
192
|
+
// Chunk structured documents with semantic strategy
|
|
193
|
+
const structuredChunks = await service.chunk(technicalDoc);
|
|
194
|
+
|
|
195
|
+
// Switch to sliding window for narrative content
|
|
196
|
+
service.setStrategy(
|
|
197
|
+
new SlidingWindowChunkingStrategy({
|
|
198
|
+
maxTokens: 512,
|
|
199
|
+
overlapTokens: 80,
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const narrativeChunks = await service.chunk(blogPost);
|
|
204
|
+
|
|
205
|
+
service.dispose();
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## 🧪 Testing
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { ChunkingService } from "@sixthsummit/ship-api/libraries/chunking";
|
|
212
|
+
|
|
213
|
+
// Quick test
|
|
214
|
+
const service = ChunkingService.createWithSemantic({
|
|
215
|
+
maxTokens: 256,
|
|
216
|
+
minTokens: 50,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const testText = `
|
|
220
|
+
# Test Document
|
|
221
|
+
|
|
222
|
+
This is the first paragraph with some content that should be
|
|
223
|
+
kept together as a semantic unit.
|
|
224
|
+
|
|
225
|
+
## Section Two
|
|
226
|
+
|
|
227
|
+
This is another section with different content. It should be
|
|
228
|
+
in a separate chunk if possible.
|
|
229
|
+
|
|
230
|
+
- Item one in a list
|
|
231
|
+
- Item two in a list
|
|
232
|
+
- Item three in a list
|
|
233
|
+
`;
|
|
234
|
+
|
|
235
|
+
const chunks = await service.chunk(testText);
|
|
236
|
+
|
|
237
|
+
console.log(`Created ${chunks.length} chunks:`);
|
|
238
|
+
chunks.forEach((chunk) => {
|
|
239
|
+
console.log(` Chunk ${chunk.chunkIndex}: ${chunk.tokenCount} tokens`);
|
|
240
|
+
console.log(` "${chunk.content.substring(0, 60)}..."`);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
service.dispose();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 📚 Next Steps
|
|
247
|
+
|
|
248
|
+
### Learn More
|
|
249
|
+
|
|
250
|
+
1. **[Strategies Guide](strategies.md)** - Deep dive into each strategy
|
|
251
|
+
2. **[Configuration Guide](configuration.md)** - Tune for your use case
|
|
252
|
+
3. **[API Reference](api-reference.md)** - Complete API documentation
|
|
253
|
+
4. **[Best Practices](best-practices.md)** - Production optimization
|
|
254
|
+
|
|
255
|
+
### Common Tasks
|
|
256
|
+
|
|
257
|
+
**Choose the right strategy:**
|
|
258
|
+
```
|
|
259
|
+
Structured docs (markdown, HTML, code) → Semantic
|
|
260
|
+
Narrative text (articles, stories) → Sliding Window
|
|
261
|
+
Quick prototype or uniform text → Fixed Length
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Set chunk size for your embedding model:**
|
|
265
|
+
|
|
266
|
+
| Embedding Model | Recommended maxTokens |
|
|
267
|
+
|-----------------|----------------------|
|
|
268
|
+
| OpenAI text-embedding-3-small | 512 |
|
|
269
|
+
| OpenAI text-embedding-3-large | 512 - 1024 |
|
|
270
|
+
| Cohere embed-v3 | 512 |
|
|
271
|
+
| BGE / E5 models | 512 |
|
|
272
|
+
| Custom models | Check model's max input |
|
|
273
|
+
|
|
274
|
+
**Handle different document types:**
|
|
275
|
+
|
|
276
|
+
| Document Type | Strategy | Key Options |
|
|
277
|
+
|---------------|----------|-------------|
|
|
278
|
+
| Technical docs | Semantic | `maxTokens: 512, minTokens: 100` |
|
|
279
|
+
| Blog posts | Sliding Window | `overlapTokens: 80` |
|
|
280
|
+
| Code files | Semantic | `maxTokens: 1024, mergeSmallChunks: true` |
|
|
281
|
+
| Legal documents | Sliding Window | `overlapTokens: 128` |
|
|
282
|
+
| Chat transcripts | Fixed Length | `maxTokens: 256` |
|
|
283
|
+
|
|
284
|
+
## ✅ Checklist
|
|
285
|
+
|
|
286
|
+
- [ ] Import the library
|
|
287
|
+
- [ ] Choose a strategy (Semantic recommended)
|
|
288
|
+
- [ ] Configure token limits for your embedding model
|
|
289
|
+
- [ ] Chunk your documents
|
|
290
|
+
- [ ] Store chunk metadata alongside embeddings
|
|
291
|
+
- [ ] Call `dispose()` when done
|
|
292
|
+
- [ ] Test with representative documents
|
|
293
|
+
|
|
294
|
+
## 🚀 You're Ready!
|
|
295
|
+
|
|
296
|
+
Start chunking documents for your RAG pipeline. The semantic strategy handles most use cases out of the box with sensible defaults.
|
|
297
|
+
|
|
298
|
+
**Questions?** See the [API Reference](api-reference.md) or [Strategies Guide](strategies.md).
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
# Chunking Library - Strategies Guide
|
|
2
|
+
|
|
3
|
+
Deep dive into each chunking strategy, when to use them, and how they work internally.
|
|
4
|
+
|
|
5
|
+
## 🏗️ Architecture
|
|
6
|
+
|
|
7
|
+
The chunking library uses the **Strategy pattern** to provide interchangeable chunking algorithms:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
ChunkingService
|
|
11
|
+
│
|
|
12
|
+
├── setStrategy() / constructor
|
|
13
|
+
│
|
|
14
|
+
└── ChunkingStrategy (interface)
|
|
15
|
+
│
|
|
16
|
+
├── FixedLengthChunkingStrategy (simple, fast)
|
|
17
|
+
├── SlidingWindowChunkingStrategy (overlapping, boundary-aware)
|
|
18
|
+
└── SemanticChunkingStrategy (structure-aware, highest quality)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
All strategies:
|
|
22
|
+
- Implement the `ChunkingStrategy` interface
|
|
23
|
+
- Accept text input and return `TextChunk[]`
|
|
24
|
+
- Use tiktoken for accurate token counting
|
|
25
|
+
- Provide a `dispose()` method for resource cleanup
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 📊 Strategy Comparison
|
|
30
|
+
|
|
31
|
+
| Feature | Fixed Length | Sliding Window | Semantic |
|
|
32
|
+
|---------|:-----------:|:--------------:|:--------:|
|
|
33
|
+
| **Speed** | ⚡ Fastest | 🔄 Medium | 🧠 Slower |
|
|
34
|
+
| **Quality** | Basic | Good | Best |
|
|
35
|
+
| **Overlap support** | ❌ | ✅ | ❌ |
|
|
36
|
+
| **Boundary detection** | ❌ | ✅ Sentence/paragraph | ✅ Structural |
|
|
37
|
+
| **Code block handling** | ❌ | ✅ Protects | ✅ Preserves |
|
|
38
|
+
| **List handling** | ❌ | ❌ | ✅ Preserves |
|
|
39
|
+
| **Header awareness** | ❌ | ❌ | ✅ Recognizes |
|
|
40
|
+
| **Small chunk merging** | ❌ | ❌ | ✅ Automatic |
|
|
41
|
+
| **Chunk size consistency** | Very consistent | Mostly consistent | Variable |
|
|
42
|
+
| **Best for** | Prototyping | Narrative text | Structured docs |
|
|
43
|
+
|
|
44
|
+
### Performance Benchmarks
|
|
45
|
+
|
|
46
|
+
| Strategy | 1KB | 10KB | 100KB | 1MB |
|
|
47
|
+
|----------|-----|------|-------|-----|
|
|
48
|
+
| Fixed Length | ~10ms | ~100ms | ~500ms | ~2s |
|
|
49
|
+
| Sliding Window | ~15ms | ~200ms | ~800ms | ~4s |
|
|
50
|
+
| Semantic | ~20ms | ~300ms | ~1.2s | ~6s |
|
|
51
|
+
|
|
52
|
+
> Benchmarks are approximate and vary by content type and hardware.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Fixed Length Strategy
|
|
57
|
+
|
|
58
|
+
### Overview
|
|
59
|
+
|
|
60
|
+
The simplest strategy. Splits text into equal-sized chunks based purely on token count with no awareness of content structure.
|
|
61
|
+
|
|
62
|
+
### How It Works
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
Input: "The quick brown fox jumps over the lazy dog. It was a sunny day."
|
|
66
|
+
maxTokens: 5
|
|
67
|
+
|
|
68
|
+
Step 1: Tokenize → [The, quick, brown, fox, jumps, over, the, lazy, dog, ., It, ...]
|
|
69
|
+
Step 2: Split → [The quick brown fox jumps] [over the lazy dog .] [It was a sunny day.]
|
|
70
|
+
Step 3: Decode → Three chunks with character indices
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Algorithm
|
|
74
|
+
|
|
75
|
+
1. **Tokenize** the entire text using tiktoken
|
|
76
|
+
2. **Split** the token array into groups of `maxTokens`
|
|
77
|
+
3. **Decode** each token group back to text
|
|
78
|
+
4. **Calculate** character start/end indices for each chunk
|
|
79
|
+
|
|
80
|
+
### Configuration
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const service = ChunkingService.createWithFixedLength({
|
|
84
|
+
maxTokens: 512, // Required: maximum tokens per chunk
|
|
85
|
+
encoding: "cl100k_base", // Optional: token encoding
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### When to Use
|
|
90
|
+
|
|
91
|
+
- ✅ Quick prototyping and experimentation
|
|
92
|
+
- ✅ Uniform text with no structure (e.g., raw data dumps)
|
|
93
|
+
- ✅ Maximum speed is required
|
|
94
|
+
- ✅ You need consistent chunk sizes
|
|
95
|
+
- ❌ Structured documents (headers, lists, code)
|
|
96
|
+
- ❌ Narrative text where meaning matters
|
|
97
|
+
- ❌ Production RAG applications
|
|
98
|
+
|
|
99
|
+
### Limitations
|
|
100
|
+
|
|
101
|
+
- May split mid-sentence, mid-word, or mid-code block
|
|
102
|
+
- No overlap between chunks (context loss at boundaries)
|
|
103
|
+
- No awareness of document structure
|
|
104
|
+
- Poor retrieval accuracy for semantic search
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Sliding Window Strategy
|
|
109
|
+
|
|
110
|
+
### Overview
|
|
111
|
+
|
|
112
|
+
Creates overlapping chunks with intelligent boundary detection. Tries to end chunks at natural paragraph or sentence breaks while maintaining configurable overlap between adjacent chunks.
|
|
113
|
+
|
|
114
|
+
### How It Works
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
Input: "Paragraph one text... Paragraph two text... Paragraph three text..."
|
|
118
|
+
maxTokens: 100, overlapTokens: 20
|
|
119
|
+
|
|
120
|
+
Step 1: Tokenize entire text
|
|
121
|
+
Step 2: Create window (tokens 0-100)
|
|
122
|
+
Step 3: Adjust to nearest paragraph/sentence boundary
|
|
123
|
+
Step 4: Emit chunk 1
|
|
124
|
+
Step 5: Advance by stepSize (80 tokens), creating overlap
|
|
125
|
+
Step 6: Create window (tokens 80-180)
|
|
126
|
+
Step 7: Adjust boundary, emit chunk 2
|
|
127
|
+
...
|
|
128
|
+
|
|
129
|
+
Result: Overlapping chunks that end at natural boundaries
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Algorithm
|
|
133
|
+
|
|
134
|
+
1. **Tokenize** the entire text
|
|
135
|
+
2. **Calculate** step size: `maxTokens - overlapTokens`
|
|
136
|
+
3. **For each window:**
|
|
137
|
+
a. Extract token window of `maxTokens` size
|
|
138
|
+
b. Decode to text
|
|
139
|
+
c. If not the last chunk:
|
|
140
|
+
- Try to find a paragraph boundary (double newline)
|
|
141
|
+
- Fall back to sentence boundary
|
|
142
|
+
- Validate boundary position against `minChunkRatio`
|
|
143
|
+
d. Emit the adjusted chunk
|
|
144
|
+
4. **Advance** by step size (creating overlap)
|
|
145
|
+
|
|
146
|
+
### Boundary Detection Details
|
|
147
|
+
|
|
148
|
+
**Paragraph boundaries** (highest priority when `preferParagraphBoundaries` is true):
|
|
149
|
+
- Pattern: `\n\s*\n` (double newline with optional whitespace)
|
|
150
|
+
- Found by scanning backward from the chunk end
|
|
151
|
+
|
|
152
|
+
**Sentence boundaries** (fallback):
|
|
153
|
+
- Pattern handles these edge cases:
|
|
154
|
+
- Standard endings: `.`, `!`, `?` followed by space and uppercase letter
|
|
155
|
+
- Abbreviations: `Dr.`, `Mr.`, `Mrs.`, `St.`, `Ph.D.` (not treated as sentence ends)
|
|
156
|
+
- Decimal numbers: `3.14`, `2.5` (not treated as sentence ends)
|
|
157
|
+
- URLs: `https://example.com` (not treated as sentence ends)
|
|
158
|
+
- Email addresses: `user@domain.com` (not treated as sentence ends)
|
|
159
|
+
- Quotations: `"Hello."` followed by new sentence
|
|
160
|
+
- End of text: `.`, `!`, `?` at end of string
|
|
161
|
+
|
|
162
|
+
**Code block protection:**
|
|
163
|
+
- Pattern: `` ```...``` `` and `` `...` ``
|
|
164
|
+
- If the last 20% of a chunk is inside a code block, sentence boundary detection is skipped to avoid splitting code
|
|
165
|
+
|
|
166
|
+
**Minimum chunk ratio:**
|
|
167
|
+
- A boundary is only used if the resulting chunk is at least `minChunkRatio * fullChunkLength` characters
|
|
168
|
+
- Default: 0.5 (chunk must be at least 50% of the window)
|
|
169
|
+
- Prevents creating very small chunks from aggressive boundary snapping
|
|
170
|
+
|
|
171
|
+
### Configuration
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const service = ChunkingService.createWithSlidingWindow({
|
|
175
|
+
maxTokens: 512, // Required: maximum tokens per chunk
|
|
176
|
+
overlapTokens: 80, // Required: overlap between chunks
|
|
177
|
+
encoding: "cl100k_base", // Optional: token encoding
|
|
178
|
+
minChunkRatio: 0.5, // Optional: minimum chunk size ratio (0.1-0.9)
|
|
179
|
+
preferParagraphBoundaries: true, // Optional: prefer paragraph over sentence
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Overlap Explained
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
Chunk 1: [====================]
|
|
187
|
+
Chunk 2: [====================]
|
|
188
|
+
Chunk 3: [====================]
|
|
189
|
+
↑ overlap ↑ ↑ overlap ↑
|
|
190
|
+
|
|
191
|
+
The overlap region appears in both adjacent chunks, providing:
|
|
192
|
+
- Context continuity for embedding models
|
|
193
|
+
- Better retrieval for queries spanning chunk boundaries
|
|
194
|
+
- Reduced information loss at boundary points
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### When to Use
|
|
198
|
+
|
|
199
|
+
- ✅ Narrative content (articles, stories, essays)
|
|
200
|
+
- ✅ Content where context flows across paragraphs
|
|
201
|
+
- ✅ Search queries that may span chunk boundaries
|
|
202
|
+
- ✅ Documents with natural paragraph structure
|
|
203
|
+
- ✅ Legal or academic documents with flowing text
|
|
204
|
+
- ❌ Highly structured documents (prefer Semantic)
|
|
205
|
+
- ❌ Maximum storage efficiency needed (overlap increases total chunks)
|
|
206
|
+
- ❌ Code-heavy documents (prefer Semantic)
|
|
207
|
+
|
|
208
|
+
### Overlap Recommendations
|
|
209
|
+
|
|
210
|
+
| Content Type | Recommended Overlap | Rationale |
|
|
211
|
+
|-------------|-------------------|-----------|
|
|
212
|
+
| General text | 15% (~80 of 512) | Good context with minimal redundancy |
|
|
213
|
+
| Legal documents | 20% (~100 of 512) | Dense text needs more context |
|
|
214
|
+
| Conversational | 10% (~50 of 512) | Natural turn boundaries |
|
|
215
|
+
| Technical docs | 15% (~80 of 512) | Balance between context and size |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Semantic Strategy
|
|
220
|
+
|
|
221
|
+
### Overview
|
|
222
|
+
|
|
223
|
+
The most sophisticated strategy. Parses documents into structural semantic units (headers, paragraphs, code blocks, lists) and groups them into chunks that preserve meaning and document hierarchy. **Recommended for production RAG applications.**
|
|
224
|
+
|
|
225
|
+
### How It Works
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
Input Document:
|
|
229
|
+
# Title → header unit
|
|
230
|
+
Intro paragraph... → paragraph unit
|
|
231
|
+
## Section → header unit
|
|
232
|
+
Content... → paragraph unit
|
|
233
|
+
```code``` → code unit (never split)
|
|
234
|
+
- item 1 → list unit
|
|
235
|
+
- item 2
|
|
236
|
+
|
|
237
|
+
Step 1: Parse into semantic units (in priority order)
|
|
238
|
+
Step 2: Group units into chunks respecting maxTokens
|
|
239
|
+
Step 3: Split oversized units by sentence
|
|
240
|
+
Step 4: Merge small chunks with neighbors
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Algorithm
|
|
244
|
+
|
|
245
|
+
**Phase 1 - Parse Semantic Units** (priority order):
|
|
246
|
+
|
|
247
|
+
1. **Code blocks** (highest priority - never split):
|
|
248
|
+
- Pattern: `` ```[\s\S]*?``` ``
|
|
249
|
+
- Extracted first to prevent other patterns from splitting them
|
|
250
|
+
|
|
251
|
+
2. **Numbered lists**:
|
|
252
|
+
- Pattern: Lines starting with `\d+.\s`
|
|
253
|
+
- Grouped with their continuation lines
|
|
254
|
+
|
|
255
|
+
3. **Bullet lists**:
|
|
256
|
+
- Pattern: Lines starting with `-`, `*`, `+`, or `bullet`
|
|
257
|
+
- Grouped with their continuation lines
|
|
258
|
+
|
|
259
|
+
4. **Headers and paragraphs** (remaining text):
|
|
260
|
+
- Headers: `# Title` (ATX) or `Title\n===` (Setext)
|
|
261
|
+
- Paragraphs: Text separated by blank lines
|
|
262
|
+
- Processed last to handle remaining text
|
|
263
|
+
|
|
264
|
+
**Phase 2 - Group Into Chunks:**
|
|
265
|
+
|
|
266
|
+
1. Sort semantic units by document position
|
|
267
|
+
2. Accumulate units into the current chunk
|
|
268
|
+
3. When adding a unit would exceed `maxTokens`:
|
|
269
|
+
- Save the current chunk
|
|
270
|
+
- Start a new chunk with the current unit
|
|
271
|
+
4. If a single unit exceeds `maxTokens`:
|
|
272
|
+
- Split it by sentence boundaries
|
|
273
|
+
- Each sentence group becomes a separate chunk
|
|
274
|
+
|
|
275
|
+
**Phase 3 - Merge Small Chunks** (if `mergeSmallChunks` is true):
|
|
276
|
+
|
|
277
|
+
1. Scan through chunks sequentially
|
|
278
|
+
2. If a chunk has fewer than `minTokens` tokens:
|
|
279
|
+
- Try to merge with the next chunk
|
|
280
|
+
- Only merge if combined size is under `maxTokens`
|
|
281
|
+
3. Reindex chunk numbers after merging
|
|
282
|
+
|
|
283
|
+
### Configuration
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
const service = ChunkingService.createWithSemantic({
|
|
287
|
+
maxTokens: 512, // Required: maximum tokens per chunk
|
|
288
|
+
minTokens: 100, // Optional: minimum tokens (triggers merging)
|
|
289
|
+
encoding: "cl100k_base", // Optional: token encoding
|
|
290
|
+
mergeSmallChunks: true, // Optional: auto-merge small chunks
|
|
291
|
+
});
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Semantic Unit Examples
|
|
295
|
+
|
|
296
|
+
**Headers:**
|
|
297
|
+
```markdown
|
|
298
|
+
# This is an ATX header → Recognized as "header" unit
|
|
299
|
+
## This is also a header → Recognized as "header" unit
|
|
300
|
+
|
|
301
|
+
This is a Setext header → Recognized as "header" unit
|
|
302
|
+
====================
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Code blocks:**
|
|
306
|
+
```markdown
|
|
307
|
+
```python → Entire block is a single "code" unit
|
|
308
|
+
def hello(): → (never split across chunks)
|
|
309
|
+
print("Hello!")
|
|
310
|
+
``` →
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
**Lists:**
|
|
314
|
+
```markdown
|
|
315
|
+
- Item one → Entire list is a single "list" unit
|
|
316
|
+
- Item two → (kept together when possible)
|
|
317
|
+
- Item three
|
|
318
|
+
|
|
319
|
+
1. First step → Entire list is a "numbered_list" unit
|
|
320
|
+
2. Second step
|
|
321
|
+
3. Third step
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Paragraphs:**
|
|
325
|
+
```markdown
|
|
326
|
+
This is a paragraph that → Single "paragraph" unit
|
|
327
|
+
contains multiple sentences.
|
|
328
|
+
|
|
329
|
+
This is another paragraph. → Separate "paragraph" unit
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### When to Use
|
|
333
|
+
|
|
334
|
+
- ✅ **Production RAG systems** (recommended)
|
|
335
|
+
- ✅ Technical documentation (markdown, structured text)
|
|
336
|
+
- ✅ Content with code blocks (preserves code integrity)
|
|
337
|
+
- ✅ Documents with headers, lists, and sections
|
|
338
|
+
- ✅ Knowledge base articles
|
|
339
|
+
- ✅ API documentation
|
|
340
|
+
- ✅ When retrieval accuracy matters most
|
|
341
|
+
- ❌ Pure narrative with no structure (Sliding Window may be better)
|
|
342
|
+
- ❌ Speed is the only priority (Fixed Length is faster)
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## 🎯 Content Type Recommendations
|
|
347
|
+
|
|
348
|
+
| Content Type | Recommended Strategy | Configuration |
|
|
349
|
+
|-------------|---------------------|---------------|
|
|
350
|
+
| **Technical docs / Markdown** | Semantic | `maxTokens: 512, minTokens: 100` |
|
|
351
|
+
| **Blog posts / Articles** | Sliding Window | `maxTokens: 512, overlapTokens: 80` |
|
|
352
|
+
| **Code files** | Semantic | `maxTokens: 1024, mergeSmallChunks: true` |
|
|
353
|
+
| **Legal documents** | Sliding Window | `maxTokens: 512, overlapTokens: 128` |
|
|
354
|
+
| **Academic papers** | Semantic | `maxTokens: 512, minTokens: 150` |
|
|
355
|
+
| **Chat transcripts** | Fixed Length | `maxTokens: 256` |
|
|
356
|
+
| **Product descriptions** | Semantic | `maxTokens: 256, minTokens: 50` |
|
|
357
|
+
| **FAQ / Q&A** | Semantic | `maxTokens: 512, mergeSmallChunks: true` |
|
|
358
|
+
| **Emails / Messages** | Fixed Length | `maxTokens: 512` |
|
|
359
|
+
| **Mixed content** | Semantic | `maxTokens: 512, minTokens: 100` |
|
|
360
|
+
|
|
361
|
+
## 🔄 Strategy Decision Tree
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
Start
|
|
365
|
+
│
|
|
366
|
+
├── Need maximum speed?
|
|
367
|
+
│ └── YES → Fixed Length
|
|
368
|
+
│
|
|
369
|
+
├── Content has structure? (headers, lists, code)
|
|
370
|
+
│ └── YES → Semantic ⭐
|
|
371
|
+
│
|
|
372
|
+
├── Content is narrative? (articles, essays, stories)
|
|
373
|
+
│ ├── Need context overlap? → Sliding Window
|
|
374
|
+
│ └── No overlap needed? → Semantic
|
|
375
|
+
│
|
|
376
|
+
├── Just prototyping?
|
|
377
|
+
│ └── YES → Fixed Length
|
|
378
|
+
│
|
|
379
|
+
└── Not sure?
|
|
380
|
+
└── Semantic (best default) ⭐
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## 📈 Quality vs. Speed Tradeoffs
|
|
384
|
+
|
|
385
|
+
```
|
|
386
|
+
Quality ▲
|
|
387
|
+
│ ★ Semantic
|
|
388
|
+
│
|
|
389
|
+
│ ★ Sliding Window
|
|
390
|
+
│
|
|
391
|
+
│ ★ Fixed Length
|
|
392
|
+
│
|
|
393
|
+
└──────────────────────────────► Speed
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
- **Fixed Length:** Maximum throughput, minimum quality. Good for batch processing where you need results fast and can tolerate some quality loss.
|
|
397
|
+
|
|
398
|
+
- **Sliding Window:** Balanced approach. Overlap improves retrieval at chunk boundaries. Boundary detection prevents mid-sentence splits. Good general-purpose choice.
|
|
399
|
+
|
|
400
|
+
- **Semantic:** Maximum quality, slightly slower. Structure-aware chunking preserves meaning. Recommended for any application where retrieval accuracy matters.
|
|
401
|
+
|
|
402
|
+
## Related Documentation
|
|
403
|
+
|
|
404
|
+
- [API Reference](api-reference.md) - Complete class and method documentation
|
|
405
|
+
- [Configuration Guide](configuration.md) - Tuning options for each strategy
|
|
406
|
+
- [Best Practices](best-practices.md) - Production optimization
|
|
407
|
+
- [Quick Start](quick-start.md) - Get started quickly
|