@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,418 @@
|
|
|
1
|
+
# Chunking Library - Configuration Guide
|
|
2
|
+
|
|
3
|
+
Complete guide to configuring and tuning the chunking library for optimal results.
|
|
4
|
+
|
|
5
|
+
## ⚙️ Configuration Overview
|
|
6
|
+
|
|
7
|
+
Every strategy accepts a configuration object at construction time. All options use sensible defaults so you can start with minimal configuration and tune as needed.
|
|
8
|
+
|
|
9
|
+
| Option | Strategies | Required | Default | Description |
|
|
10
|
+
|--------|-----------|----------|---------|-------------|
|
|
11
|
+
| `maxTokens` | All | Yes | - | Maximum tokens per chunk |
|
|
12
|
+
| `encoding` | All | No | `cl100k_base` | Token encoding name |
|
|
13
|
+
| `overlapTokens` | Sliding Window | Yes | - | Overlap between chunks |
|
|
14
|
+
| `minChunkRatio` | Sliding Window | No | `0.5` | Min chunk size ratio |
|
|
15
|
+
| `preferParagraphBoundaries` | Sliding Window | No | `true` | Prefer paragraph breaks |
|
|
16
|
+
| `minTokens` | Semantic | No | `100` | Minimum tokens per chunk |
|
|
17
|
+
| `mergeSmallChunks` | Semantic | No | `true` | Auto-merge small chunks |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Token Limits
|
|
22
|
+
|
|
23
|
+
### maxTokens
|
|
24
|
+
|
|
25
|
+
The most important configuration option. Sets the upper bound on tokens per chunk.
|
|
26
|
+
|
|
27
|
+
**Guidelines:**
|
|
28
|
+
- Match your embedding model's maximum input size
|
|
29
|
+
- Leave headroom for metadata if you prepend context to chunks
|
|
30
|
+
- Smaller chunks = more precise retrieval but less context
|
|
31
|
+
- Larger chunks = more context but less precise retrieval
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Conservative (good retrieval precision)
|
|
35
|
+
{ maxTokens: 256 }
|
|
36
|
+
|
|
37
|
+
// Balanced (recommended default)
|
|
38
|
+
{ maxTokens: 512 }
|
|
39
|
+
|
|
40
|
+
// Large context (more context per chunk)
|
|
41
|
+
{ maxTokens: 1024 }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Embedding Model Alignment
|
|
45
|
+
|
|
46
|
+
Choose `maxTokens` based on your embedding model:
|
|
47
|
+
|
|
48
|
+
| Embedding Model | Max Input Tokens | Recommended maxTokens |
|
|
49
|
+
|-----------------|-----------------|----------------------|
|
|
50
|
+
| OpenAI `text-embedding-3-small` | 8,191 | 512 |
|
|
51
|
+
| OpenAI `text-embedding-3-large` | 8,191 | 512 - 1,024 |
|
|
52
|
+
| OpenAI `text-embedding-ada-002` | 8,191 | 512 |
|
|
53
|
+
| Cohere `embed-english-v3.0` | 512 | 480 |
|
|
54
|
+
| Cohere `embed-multilingual-v3.0` | 512 | 480 |
|
|
55
|
+
| Google `text-embedding-004` | 2,048 | 512 - 1,024 |
|
|
56
|
+
| BGE models | 512 | 480 |
|
|
57
|
+
| E5 models | 512 | 480 |
|
|
58
|
+
| Nomic `nomic-embed-text-v1.5` | 8,192 | 512 - 1,024 |
|
|
59
|
+
|
|
60
|
+
> **Tip:** Even when models support large inputs, 512 tokens is often the sweet spot for RAG retrieval quality. Larger chunks provide more context but can dilute relevance.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Token Encodings
|
|
65
|
+
|
|
66
|
+
### Supported Encodings
|
|
67
|
+
|
|
68
|
+
The `encoding` option controls how text is tokenized. This should match your target model's tokenizer.
|
|
69
|
+
|
|
70
|
+
| Encoding | Models | Tokens/Word (avg) |
|
|
71
|
+
|----------|--------|-------------------|
|
|
72
|
+
| `cl100k_base` | GPT-3.5-turbo, GPT-4, text-embedding-3-* | ~1.3 |
|
|
73
|
+
| `p50k_base` | Code models, older GPT-3 | ~1.3 |
|
|
74
|
+
| `r50k_base` | Older GPT-3 (davinci, curie) | ~1.3 |
|
|
75
|
+
| `gpt2` | GPT-2 models | ~1.5 |
|
|
76
|
+
|
|
77
|
+
**Default:** `cl100k_base` (best for modern OpenAI models)
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// Default (GPT-3.5/4 compatible)
|
|
81
|
+
{ maxTokens: 512, encoding: "cl100k_base" }
|
|
82
|
+
|
|
83
|
+
// For older models
|
|
84
|
+
{ maxTokens: 512, encoding: "p50k_base" }
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Encoding Fallback
|
|
88
|
+
|
|
89
|
+
If an invalid encoding name is provided, the library automatically falls back to `gpt-3.5-turbo` encoding (which uses `cl100k_base`):
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// This won't throw - falls back gracefully
|
|
93
|
+
{ maxTokens: 512, encoding: "invalid_encoding_name" }
|
|
94
|
+
// → Uses cl100k_base internally
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Overlap Configuration
|
|
100
|
+
|
|
101
|
+
### overlapTokens (Sliding Window only)
|
|
102
|
+
|
|
103
|
+
Controls how many tokens overlap between adjacent chunks. Overlap provides context continuity at chunk boundaries.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
{
|
|
107
|
+
maxTokens: 512,
|
|
108
|
+
overlapTokens: 80, // ~15% overlap
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**How overlap works:**
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
stepSize = maxTokens - overlapTokens
|
|
116
|
+
= 512 - 80 = 432
|
|
117
|
+
|
|
118
|
+
Chunk 1: tokens[0..512]
|
|
119
|
+
Chunk 2: tokens[432..944] ← starts 432 tokens later
|
|
120
|
+
Chunk 3: tokens[864..1376] ← starts 432 tokens later
|
|
121
|
+
↑
|
|
122
|
+
80 tokens shared between adjacent chunks
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Recommendations:**
|
|
126
|
+
|
|
127
|
+
| Overlap % | overlapTokens (512 max) | Use Case |
|
|
128
|
+
|-----------|------------------------|----------|
|
|
129
|
+
| 10% | ~50 | Short, independent paragraphs |
|
|
130
|
+
| 15% | ~80 | **General purpose (recommended)** |
|
|
131
|
+
| 20% | ~100 | Dense technical or legal text |
|
|
132
|
+
| 25% | ~128 | Highly interconnected content |
|
|
133
|
+
|
|
134
|
+
**Tradeoffs:**
|
|
135
|
+
- More overlap = better context preservation at boundaries
|
|
136
|
+
- More overlap = more total chunks (increases storage and embedding costs)
|
|
137
|
+
- More overlap = slower processing (smaller step size)
|
|
138
|
+
|
|
139
|
+
**Constraints:**
|
|
140
|
+
- Must be less than `maxTokens`
|
|
141
|
+
- Recommended: 10-25% of `maxTokens`
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Boundary Configuration
|
|
146
|
+
|
|
147
|
+
### preferParagraphBoundaries (Sliding Window only)
|
|
148
|
+
|
|
149
|
+
When `true`, the sliding window strategy tries to end chunks at paragraph boundaries (double newlines) before falling back to sentence boundaries.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Prefer paragraph boundaries (default)
|
|
153
|
+
{ maxTokens: 512, overlapTokens: 80, preferParagraphBoundaries: true }
|
|
154
|
+
|
|
155
|
+
// Only use sentence boundaries
|
|
156
|
+
{ maxTokens: 512, overlapTokens: 80, preferParagraphBoundaries: false }
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**When to disable:**
|
|
160
|
+
- Content has very long paragraphs (would create undersized chunks)
|
|
161
|
+
- Content doesn't use paragraph breaks
|
|
162
|
+
- You want more consistent chunk sizes
|
|
163
|
+
|
|
164
|
+
### minChunkRatio (Sliding Window only)
|
|
165
|
+
|
|
166
|
+
Controls the minimum acceptable chunk size when snapping to boundaries. Expressed as a ratio of the full chunk length.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Default: chunks must be at least 50% of maxTokens
|
|
170
|
+
{ maxTokens: 512, overlapTokens: 80, minChunkRatio: 0.5 }
|
|
171
|
+
|
|
172
|
+
// More aggressive boundary snapping (smaller chunks OK)
|
|
173
|
+
{ maxTokens: 512, overlapTokens: 80, minChunkRatio: 0.3 }
|
|
174
|
+
|
|
175
|
+
// Conservative (larger minimum chunks)
|
|
176
|
+
{ maxTokens: 512, overlapTokens: 80, minChunkRatio: 0.7 }
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Valid range:** 0.1 to 0.9
|
|
180
|
+
|
|
181
|
+
**How it works:**
|
|
182
|
+
- When a paragraph/sentence boundary is found, check if the resulting chunk size is >= `minChunkRatio * chunkLength`
|
|
183
|
+
- If too small, skip that boundary and use the next one or fall back to no adjustment
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Semantic Configuration
|
|
188
|
+
|
|
189
|
+
### minTokens (Semantic only)
|
|
190
|
+
|
|
191
|
+
Sets the minimum token count for chunks. Chunks smaller than this threshold are merged with adjacent chunks (if `mergeSmallChunks` is true).
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// Default: merge chunks under 100 tokens
|
|
195
|
+
{ maxTokens: 512, minTokens: 100 }
|
|
196
|
+
|
|
197
|
+
// Stricter: merge chunks under 150 tokens
|
|
198
|
+
{ maxTokens: 512, minTokens: 150 }
|
|
199
|
+
|
|
200
|
+
// Lenient: allow small chunks down to 50 tokens
|
|
201
|
+
{ maxTokens: 512, minTokens: 50 }
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Guidelines:**
|
|
205
|
+
- Higher values = fewer, larger chunks (less fragmentation)
|
|
206
|
+
- Lower values = more chunks that closely match document structure
|
|
207
|
+
- Too high = forces unrelated content together
|
|
208
|
+
- Too low = creates tiny, low-quality chunks
|
|
209
|
+
|
|
210
|
+
**Constraint:** Must be less than `maxTokens`
|
|
211
|
+
|
|
212
|
+
### mergeSmallChunks (Semantic only)
|
|
213
|
+
|
|
214
|
+
Controls whether chunks below `minTokens` are automatically merged with their neighbors.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// Enable merging (default - recommended)
|
|
218
|
+
{ maxTokens: 512, minTokens: 100, mergeSmallChunks: true }
|
|
219
|
+
|
|
220
|
+
// Disable merging (preserve exact structure)
|
|
221
|
+
{ maxTokens: 512, minTokens: 100, mergeSmallChunks: false }
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**When to disable:**
|
|
225
|
+
- You want chunks to exactly mirror the document structure
|
|
226
|
+
- Each semantic unit is independently meaningful regardless of size
|
|
227
|
+
- You're doing per-section processing rather than RAG
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Performance Tuning
|
|
232
|
+
|
|
233
|
+
### Chunk Size vs. Performance
|
|
234
|
+
|
|
235
|
+
| maxTokens | Chunks per 10KB | Processing Time | Memory |
|
|
236
|
+
|-----------|----------------|-----------------|--------|
|
|
237
|
+
| 128 | ~30 | Higher | Lower |
|
|
238
|
+
| 256 | ~15 | Medium | Lower |
|
|
239
|
+
| 512 | ~8 | Medium | Medium |
|
|
240
|
+
| 1024 | ~4 | Lower | Higher |
|
|
241
|
+
| 2048 | ~2 | Lowest | Higher |
|
|
242
|
+
|
|
243
|
+
### Memory Management
|
|
244
|
+
|
|
245
|
+
The tiktoken encoder uses native memory. Always dispose:
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
// Pattern 1: try/finally
|
|
249
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
250
|
+
try {
|
|
251
|
+
return await service.chunk(text);
|
|
252
|
+
} finally {
|
|
253
|
+
service.dispose();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Pattern 2: Reuse the service
|
|
257
|
+
class DocumentProcessor {
|
|
258
|
+
private chunkingService: ChunkingService;
|
|
259
|
+
|
|
260
|
+
constructor() {
|
|
261
|
+
this.chunkingService = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async processDocument(text: string): Promise<TextChunk[]> {
|
|
265
|
+
return await this.chunkingService.chunk(text);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
destroy(): void {
|
|
269
|
+
this.chunkingService.dispose();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Batch Processing
|
|
275
|
+
|
|
276
|
+
For large document sets, reuse a single service instance:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
280
|
+
|
|
281
|
+
try {
|
|
282
|
+
for (const document of documents) {
|
|
283
|
+
const chunks = await service.chunk(document.content);
|
|
284
|
+
await storeChunks(document.id, chunks);
|
|
285
|
+
}
|
|
286
|
+
} finally {
|
|
287
|
+
service.dispose();
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
## Quality Metrics
|
|
294
|
+
|
|
295
|
+
### Measuring Chunk Quality
|
|
296
|
+
|
|
297
|
+
After configuring your chunking pipeline, evaluate quality using these metrics:
|
|
298
|
+
|
|
299
|
+
| Metric | What It Measures | Target |
|
|
300
|
+
|--------|-----------------|--------|
|
|
301
|
+
| **Avg chunk size** | Token utilization | 60-90% of maxTokens |
|
|
302
|
+
| **Size variance** | Consistency | Low (< 30% coefficient of variation) |
|
|
303
|
+
| **Boundary coherence** | Semantic completeness | Chunks end at natural breaks |
|
|
304
|
+
| **Retrieval accuracy** | End-to-end quality | Measured by your eval suite |
|
|
305
|
+
|
|
306
|
+
### Quick Quality Check
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512, minTokens: 100 });
|
|
310
|
+
const chunks = await service.chunk(document);
|
|
311
|
+
|
|
312
|
+
// Calculate statistics
|
|
313
|
+
const tokenCounts = chunks.map(c => c.tokenCount);
|
|
314
|
+
const avg = tokenCounts.reduce((a, b) => a + b, 0) / tokenCounts.length;
|
|
315
|
+
const min = Math.min(...tokenCounts);
|
|
316
|
+
const max = Math.max(...tokenCounts);
|
|
317
|
+
const variance = tokenCounts.reduce((sum, t) => sum + (t - avg) ** 2, 0) / tokenCounts.length;
|
|
318
|
+
const stddev = Math.sqrt(variance);
|
|
319
|
+
|
|
320
|
+
console.log(`Chunks: ${chunks.length}`);
|
|
321
|
+
console.log(`Avg tokens: ${avg.toFixed(0)}`);
|
|
322
|
+
console.log(`Min tokens: ${min}`);
|
|
323
|
+
console.log(`Max tokens: ${max}`);
|
|
324
|
+
console.log(`Std deviation: ${stddev.toFixed(0)}`);
|
|
325
|
+
console.log(`Utilization: ${(avg / 512 * 100).toFixed(1)}%`);
|
|
326
|
+
|
|
327
|
+
service.dispose();
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Recommended Configurations
|
|
333
|
+
|
|
334
|
+
### Production RAG (General Purpose)
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
const service = ChunkingService.createWithSemantic({
|
|
338
|
+
maxTokens: 512,
|
|
339
|
+
minTokens: 100,
|
|
340
|
+
mergeSmallChunks: true,
|
|
341
|
+
encoding: "cl100k_base",
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### Technical Documentation
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
const service = ChunkingService.createWithSemantic({
|
|
349
|
+
maxTokens: 512,
|
|
350
|
+
minTokens: 150, // Technical sections tend to be longer
|
|
351
|
+
mergeSmallChunks: true,
|
|
352
|
+
encoding: "cl100k_base",
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Narrative Content / Articles
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
const service = ChunkingService.createWithSlidingWindow({
|
|
360
|
+
maxTokens: 512,
|
|
361
|
+
overlapTokens: 80,
|
|
362
|
+
preferParagraphBoundaries: true,
|
|
363
|
+
minChunkRatio: 0.5,
|
|
364
|
+
encoding: "cl100k_base",
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Code Documentation / READMEs
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
const service = ChunkingService.createWithSemantic({
|
|
372
|
+
maxTokens: 1024, // Code blocks can be large
|
|
373
|
+
minTokens: 100,
|
|
374
|
+
mergeSmallChunks: true,
|
|
375
|
+
encoding: "cl100k_base",
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Short-Form Content (FAQs, Product Descriptions)
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
const service = ChunkingService.createWithSemantic({
|
|
383
|
+
maxTokens: 256,
|
|
384
|
+
minTokens: 50,
|
|
385
|
+
mergeSmallChunks: true,
|
|
386
|
+
encoding: "cl100k_base",
|
|
387
|
+
});
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### High-Overlap Retrieval (Legal, Academic)
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
const service = ChunkingService.createWithSlidingWindow({
|
|
394
|
+
maxTokens: 512,
|
|
395
|
+
overlapTokens: 128, // 25% overlap
|
|
396
|
+
preferParagraphBoundaries: true,
|
|
397
|
+
minChunkRatio: 0.4,
|
|
398
|
+
encoding: "cl100k_base",
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Fast Batch Processing
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
const service = ChunkingService.createWithFixedLength({
|
|
406
|
+
maxTokens: 512,
|
|
407
|
+
encoding: "cl100k_base",
|
|
408
|
+
});
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## Related Documentation
|
|
414
|
+
|
|
415
|
+
- [API Reference](api-reference.md) - Complete class and method docs
|
|
416
|
+
- [Strategies Guide](strategies.md) - Strategy deep dive
|
|
417
|
+
- [Best Practices](best-practices.md) - Production optimization
|
|
418
|
+
- [Troubleshooting](troubleshooting.md) - Common issues and solutions
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Chunking Library - Documentation Index
|
|
2
|
+
|
|
3
|
+
Complete guide to all documentation in the chunking library.
|
|
4
|
+
|
|
5
|
+
## 📚 Documentation Overview
|
|
6
|
+
|
|
7
|
+
| Document | Description | When to Read |
|
|
8
|
+
|----------|-------------|--------------|
|
|
9
|
+
| **[README.md](../README.md)** | Complete library overview | First read, reference |
|
|
10
|
+
| **[quick-start.md](quick-start.md)** | Get started in 5 minutes | Start here! |
|
|
11
|
+
| **[strategies.md](strategies.md)** | Strategy deep dive & comparison | Choosing a strategy |
|
|
12
|
+
| **[api-reference.md](api-reference.md)** | Complete API documentation | API integration |
|
|
13
|
+
| **[configuration.md](configuration.md)** | Configuration & tuning | Optimizing performance |
|
|
14
|
+
| **[code-organization.md](code-organization.md)** | Code structure & patterns | Contributing / extending |
|
|
15
|
+
| **[troubleshooting.md](troubleshooting.md)** | Common issues & solutions | When things break |
|
|
16
|
+
| **[best-practices.md](best-practices.md)** | Production best practices | Production deployment |
|
|
17
|
+
|
|
18
|
+
## 🎯 Documentation by Role
|
|
19
|
+
|
|
20
|
+
### For Developers (Using the Library)
|
|
21
|
+
|
|
22
|
+
**Start here:**
|
|
23
|
+
1. [quick-start.md](quick-start.md) - Basic usage (5 min)
|
|
24
|
+
2. [strategies.md](strategies.md) - Choose the right strategy
|
|
25
|
+
3. [api-reference.md](api-reference.md) - Full API reference
|
|
26
|
+
|
|
27
|
+
**Common tasks:**
|
|
28
|
+
- [Create a chunking service](quick-start.md#-quick-start)
|
|
29
|
+
- [Chunk a document](quick-start.md#2-chunk-your-text)
|
|
30
|
+
- [Switch strategies](api-reference.md#setstrategy)
|
|
31
|
+
- [Configure token limits](configuration.md#token-limits)
|
|
32
|
+
|
|
33
|
+
### For AI/ML Engineers (RAG & Embeddings)
|
|
34
|
+
|
|
35
|
+
**Start here:**
|
|
36
|
+
1. [strategies.md](strategies.md) - Strategy comparison & selection
|
|
37
|
+
2. [configuration.md](configuration.md) - Tuning for your use case
|
|
38
|
+
3. [best-practices.md](best-practices.md) - Production optimization
|
|
39
|
+
|
|
40
|
+
**Common tasks:**
|
|
41
|
+
- [Choose the right strategy](strategies.md#-strategy-comparison)
|
|
42
|
+
- [Optimize chunk size for embeddings](configuration.md#embedding-model-alignment)
|
|
43
|
+
- [Handle different content types](strategies.md#content-type-recommendations)
|
|
44
|
+
- [Measure chunking quality](configuration.md#quality-metrics)
|
|
45
|
+
|
|
46
|
+
### For Contributors (Extending the Library)
|
|
47
|
+
|
|
48
|
+
**Start here:**
|
|
49
|
+
1. [code-organization.md](code-organization.md) - Architecture & patterns
|
|
50
|
+
2. [api-reference.md](api-reference.md) - Interface contracts
|
|
51
|
+
3. [strategies.md](strategies.md) - Existing implementations
|
|
52
|
+
|
|
53
|
+
**Common tasks:**
|
|
54
|
+
- [Understand the architecture](code-organization.md#architecture)
|
|
55
|
+
- [Create a custom strategy](code-organization.md#creating-a-custom-strategy)
|
|
56
|
+
- [Run tests](code-organization.md#testing)
|
|
57
|
+
- [Follow conventions](code-organization.md#conventions)
|
|
58
|
+
|
|
59
|
+
## 📖 Documentation by Task
|
|
60
|
+
|
|
61
|
+
### Getting Started
|
|
62
|
+
| Task | Documentation |
|
|
63
|
+
|------|---------------|
|
|
64
|
+
| Install the library | [quick-start.md](quick-start.md#1-install) |
|
|
65
|
+
| First chunking example | [quick-start.md](quick-start.md#2-chunk-your-text) |
|
|
66
|
+
| Understand the output | [quick-start.md](quick-start.md#3-understand-the-output) |
|
|
67
|
+
| Clean up resources | [quick-start.md](quick-start.md#4-clean-up) |
|
|
68
|
+
|
|
69
|
+
### Choosing a Strategy
|
|
70
|
+
| Task | Documentation |
|
|
71
|
+
|------|---------------|
|
|
72
|
+
| Compare strategies | [strategies.md](strategies.md#-strategy-comparison) |
|
|
73
|
+
| Use Fixed Length | [strategies.md](strategies.md#fixed-length-strategy) |
|
|
74
|
+
| Use Sliding Window | [strategies.md](strategies.md#sliding-window-strategy) |
|
|
75
|
+
| Use Semantic (recommended) | [strategies.md](strategies.md#semantic-strategy) |
|
|
76
|
+
| Match strategy to content | [strategies.md](strategies.md#content-type-recommendations) |
|
|
77
|
+
|
|
78
|
+
### Configuration & Tuning
|
|
79
|
+
| Task | Documentation |
|
|
80
|
+
|------|---------------|
|
|
81
|
+
| Set token limits | [configuration.md](configuration.md#token-limits) |
|
|
82
|
+
| Choose token encoding | [configuration.md](configuration.md#token-encodings) |
|
|
83
|
+
| Tune overlap settings | [configuration.md](configuration.md#overlap-configuration) |
|
|
84
|
+
| Optimize for performance | [configuration.md](configuration.md#performance-tuning) |
|
|
85
|
+
| Align with embedding models | [configuration.md](configuration.md#embedding-model-alignment) |
|
|
86
|
+
|
|
87
|
+
### Advanced Topics
|
|
88
|
+
| Task | Documentation |
|
|
89
|
+
|------|---------------|
|
|
90
|
+
| Switch strategies at runtime | [api-reference.md](api-reference.md#setstrategy) |
|
|
91
|
+
| Use auto-detection factory | [api-reference.md](api-reference.md#static-create) |
|
|
92
|
+
| Handle edge cases | [troubleshooting.md](troubleshooting.md) |
|
|
93
|
+
| Production deployment | [best-practices.md](best-practices.md) |
|
|
94
|
+
| Create a custom strategy | [code-organization.md](code-organization.md#creating-a-custom-strategy) |
|
|
95
|
+
|
|
96
|
+
### Testing & Development
|
|
97
|
+
| Task | Documentation |
|
|
98
|
+
|------|---------------|
|
|
99
|
+
| Run tests | [code-organization.md](code-organization.md#testing) |
|
|
100
|
+
| Write strategy tests | [code-organization.md](code-organization.md#writing-tests) |
|
|
101
|
+
| Mock the service | [code-organization.md](code-organization.md#mocking) |
|
|
102
|
+
|
|
103
|
+
## 🔍 Quick Reference
|
|
104
|
+
|
|
105
|
+
### Key Concepts
|
|
106
|
+
|
|
107
|
+
- **[Strategy Pattern](strategies.md#architecture)** - Pluggable chunking algorithms
|
|
108
|
+
- **[Token Counting](configuration.md#token-encodings)** - Accurate token measurement with tiktoken
|
|
109
|
+
- **[Semantic Boundaries](strategies.md#semantic-strategy)** - Structure-aware chunking
|
|
110
|
+
- **[Chunk Overlap](configuration.md#overlap-configuration)** - Context preservation between chunks
|
|
111
|
+
|
|
112
|
+
### Strategies at a Glance
|
|
113
|
+
|
|
114
|
+
| Strategy | Best For | Speed | Quality |
|
|
115
|
+
|----------|----------|-------|---------|
|
|
116
|
+
| **Fixed Length** | Prototyping, uniform text | Fastest | Basic |
|
|
117
|
+
| **Sliding Window** | Narrative content, context overlap | Medium | Good |
|
|
118
|
+
| **Semantic** | Production RAG, structured docs | Slower | Best |
|
|
119
|
+
|
|
120
|
+
### Factory Methods
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// Quick creation
|
|
124
|
+
const service = ChunkingService.createWithSemantic({ maxTokens: 512 });
|
|
125
|
+
const service = ChunkingService.createWithSlidingWindow({ maxTokens: 512, overlapTokens: 80 });
|
|
126
|
+
const service = ChunkingService.createWithFixedLength({ maxTokens: 512 });
|
|
127
|
+
|
|
128
|
+
// Auto-detection
|
|
129
|
+
const service = ChunkingService.create(options);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Common Configuration
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// Production RAG (recommended)
|
|
136
|
+
{ maxTokens: 512, minTokens: 100, mergeSmallChunks: true }
|
|
137
|
+
|
|
138
|
+
// Narrative content with overlap
|
|
139
|
+
{ maxTokens: 512, overlapTokens: 80, preferParagraphBoundaries: true }
|
|
140
|
+
|
|
141
|
+
// Fast prototyping
|
|
142
|
+
{ maxTokens: 512 }
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## 📝 Documentation Structure
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
libraries/chunking/
|
|
149
|
+
├── 📖 README.md Library overview & entry point
|
|
150
|
+
│
|
|
151
|
+
├── docs/
|
|
152
|
+
│ ├── 📚 index.md This file - navigation hub
|
|
153
|
+
│ ├── 📝 summary.md Quick reference card
|
|
154
|
+
│ ├── 🚀 quick-start.md 5-minute getting started
|
|
155
|
+
│ ├── 📖 api-reference.md Complete API documentation
|
|
156
|
+
│ ├── 🎯 strategies.md Strategy deep dive
|
|
157
|
+
│ ├── ⚙️ configuration.md Configuration & tuning
|
|
158
|
+
│ ├── 🏆 best-practices.md Production best practices
|
|
159
|
+
│ ├── 🏗️ code-organization.md Code structure & patterns
|
|
160
|
+
│ └── 🔧 troubleshooting.md Common issues & solutions
|
|
161
|
+
│
|
|
162
|
+
├── ChunkingService.ts Main service class
|
|
163
|
+
├── strategies/
|
|
164
|
+
│ ├── ChunkingStrategy.ts Base strategy interface
|
|
165
|
+
│ ├── FixedLengthChunkingStrategy.ts
|
|
166
|
+
│ ├── SlidingWindowChunkingStrategy.ts
|
|
167
|
+
│ └── SemanticChunkingStrategy.ts
|
|
168
|
+
└── types/
|
|
169
|
+
└── index.ts Type definitions
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## 🆘 Need Help?
|
|
173
|
+
|
|
174
|
+
### Quick Answers
|
|
175
|
+
|
|
176
|
+
**Q: Which strategy should I use?**
|
|
177
|
+
A: Use **Semantic** for production RAG. See [strategies.md](strategies.md#-strategy-comparison)
|
|
178
|
+
|
|
179
|
+
**Q: How do I set chunk size?**
|
|
180
|
+
A: Use the `maxTokens` option. See [configuration.md](configuration.md#token-limits)
|
|
181
|
+
|
|
182
|
+
**Q: How do I handle large documents?**
|
|
183
|
+
A: All strategies handle large documents automatically. See [troubleshooting.md](troubleshooting.md#large-documents)
|
|
184
|
+
|
|
185
|
+
**Q: Do I need to call dispose()?**
|
|
186
|
+
A: Yes, always call `dispose()` when done. See [quick-start.md](quick-start.md#4-clean-up)
|
|
187
|
+
|
|
188
|
+
**Q: Can I switch strategies at runtime?**
|
|
189
|
+
A: Yes, use `setStrategy()`. See [api-reference.md](api-reference.md#setstrategy)
|
|
190
|
+
|
|
191
|
+
### Common Issues
|
|
192
|
+
|
|
193
|
+
| Issue | Solution |
|
|
194
|
+
|-------|----------|
|
|
195
|
+
| Empty chunks returned | [troubleshooting.md](troubleshooting.md#empty-chunks) |
|
|
196
|
+
| Token count mismatch | [troubleshooting.md](troubleshooting.md#token-count-mismatch) |
|
|
197
|
+
| Memory usage high | [troubleshooting.md](troubleshooting.md#memory-usage) |
|
|
198
|
+
| Chunks too small/large | [troubleshooting.md](troubleshooting.md#chunk-size-issues) |
|
|
199
|
+
|
|
200
|
+
## 🎓 Learning Path
|
|
201
|
+
|
|
202
|
+
### Beginner (Day 1)
|
|
203
|
+
1. Read [quick-start.md](quick-start.md)
|
|
204
|
+
2. Chunk your first document
|
|
205
|
+
3. Explore the output structure
|
|
206
|
+
4. Try different strategies
|
|
207
|
+
|
|
208
|
+
### Intermediate (Week 1)
|
|
209
|
+
1. Read [strategies.md](strategies.md)
|
|
210
|
+
2. Read [configuration.md](configuration.md)
|
|
211
|
+
3. Tune settings for your content type
|
|
212
|
+
4. Integrate with your embedding pipeline
|
|
213
|
+
|
|
214
|
+
### Advanced (Month 1)
|
|
215
|
+
1. Read [best-practices.md](best-practices.md)
|
|
216
|
+
2. Read [code-organization.md](code-organization.md)
|
|
217
|
+
3. Create custom strategies
|
|
218
|
+
4. Optimize for production workloads
|
|
219
|
+
|
|
220
|
+
## 📊 Documentation Stats
|
|
221
|
+
|
|
222
|
+
- **Total Pages:** 9 docs + README
|
|
223
|
+
- **Code Examples:** 50+
|
|
224
|
+
- **Quick Start Time:** 5 minutes
|
|
225
|
+
- **Full Read Time:** ~3 hours
|
|
226
|
+
- **Last Updated:** 2026-02-16
|
|
227
|
+
|
|
228
|
+
## 🔗 Related Resources
|
|
229
|
+
|
|
230
|
+
- [Ship-API Framework](../../../README.md)
|
|
231
|
+
- [Weaviate Library](../../weaviate/README.md)
|
|
232
|
+
- [tiktoken Documentation](https://github.com/openai/tiktoken)
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
**Pro Tip:** Bookmark this page and use it as your starting point for any chunking library questions!
|