agentfootprint 8.19.0 → 9.0.0
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/README.md +2 -2
- package/bin/agentfootprint-index.mjs +28 -3
- package/dist/adapters/hosting/agentcore.js +1 -1
- package/dist/adapters/identity/agentcore.js +1 -1
- package/dist/adapters/llm/AnthropicProvider.js +1 -1
- package/dist/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/adapters/llm/MockProvider.js +1 -1
- package/dist/adapters/llm/OpenAIProvider.js +2 -2
- package/dist/adapters/memory/agentcore.js +1 -1
- package/dist/adapters/memory/bedrockAgentMemory.js +1 -1
- package/dist/adapters/memory/redis.js +1 -1
- package/dist/adapters/observability/agentcore.js +2 -2
- package/dist/adapters/observability/audit.js +1 -1
- package/dist/adapters/observability/cloudwatch.js +2 -2
- package/dist/adapters/observability/otel.js +3 -3
- package/dist/adapters/observability/xray.js +2 -2
- package/dist/core/Agent.js +1 -1
- package/dist/core/agent/AgentBuilder.js +35 -23
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/core/agent/stages/window.js +11 -13
- package/dist/core/agent/stages/window.js.map +1 -1
- package/dist/core/agent/watch.js +1 -1
- package/dist/core/agent/window/index.js.map +1 -1
- package/dist/core/agent/window/strategies/summarizeOldest.js +0 -5
- package/dist/core/agent/window/strategies/summarizeOldest.js.map +1 -1
- package/dist/core/slots/helpers.js +4 -7
- package/dist/core/slots/helpers.js.map +1 -1
- package/dist/debug/finders.js +7 -10
- package/dist/debug/finders.js.map +1 -1
- package/dist/debug.js +4 -4
- package/dist/doors/context.js +3 -3
- package/dist/esm/adapters/hosting/agentcore.d.ts +1 -1
- package/dist/esm/adapters/hosting/agentcore.js +1 -1
- package/dist/esm/adapters/identity/agentcore.d.ts +1 -1
- package/dist/esm/adapters/identity/agentcore.js +1 -1
- package/dist/esm/adapters/llm/AnthropicProvider.d.ts +1 -1
- package/dist/esm/adapters/llm/AnthropicProvider.js +1 -1
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +1 -1
- package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +1 -1
- package/dist/esm/adapters/llm/MockProvider.d.ts +1 -1
- package/dist/esm/adapters/llm/MockProvider.js +1 -1
- package/dist/esm/adapters/llm/OpenAIProvider.d.ts +2 -2
- package/dist/esm/adapters/llm/OpenAIProvider.js +2 -2
- package/dist/esm/adapters/memory/agentcore.d.ts +1 -1
- package/dist/esm/adapters/memory/agentcore.js +1 -1
- package/dist/esm/adapters/memory/bedrockAgentMemory.d.ts +1 -1
- package/dist/esm/adapters/memory/bedrockAgentMemory.js +1 -1
- package/dist/esm/adapters/memory/redis.d.ts +1 -1
- package/dist/esm/adapters/memory/redis.js +1 -1
- package/dist/esm/adapters/observability/agentcore.d.ts +2 -2
- package/dist/esm/adapters/observability/agentcore.js +2 -2
- package/dist/esm/adapters/observability/audit.d.ts +1 -1
- package/dist/esm/adapters/observability/audit.js +1 -1
- package/dist/esm/adapters/observability/cloudwatch.d.ts +2 -2
- package/dist/esm/adapters/observability/cloudwatch.js +2 -2
- package/dist/esm/adapters/observability/otel.d.ts +4 -4
- package/dist/esm/adapters/observability/otel.js +3 -3
- package/dist/esm/adapters/observability/xray.d.ts +2 -2
- package/dist/esm/adapters/observability/xray.js +2 -2
- package/dist/esm/core/Agent.js +1 -1
- package/dist/esm/core/agent/AgentBuilder.d.ts +17 -14
- package/dist/esm/core/agent/AgentBuilder.js +35 -23
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/core/agent/stages/window.js +11 -13
- package/dist/esm/core/agent/stages/window.js.map +1 -1
- package/dist/esm/core/agent/types.d.ts +2 -2
- package/dist/esm/core/agent/watch.d.ts +1 -1
- package/dist/esm/core/agent/watch.js +1 -1
- package/dist/esm/core/agent/window/index.d.ts +1 -1
- package/dist/esm/core/agent/window/index.js.map +1 -1
- package/dist/esm/core/agent/window/strategies/summarizeOldest.js +0 -5
- package/dist/esm/core/agent/window/strategies/summarizeOldest.js.map +1 -1
- package/dist/esm/core/agent/window/types.d.ts +0 -30
- package/dist/esm/core/runner.d.ts +1 -1
- package/dist/esm/core/slots/helpers.d.ts +3 -4
- package/dist/esm/core/slots/helpers.js +4 -7
- package/dist/esm/core/slots/helpers.js.map +1 -1
- package/dist/esm/debug/finders.d.ts +7 -10
- package/dist/esm/debug/finders.js +7 -10
- package/dist/esm/debug/finders.js.map +1 -1
- package/dist/esm/debug.d.ts +4 -4
- package/dist/esm/debug.js +4 -4
- package/dist/esm/doors/context.d.ts +3 -3
- package/dist/esm/doors/context.js +3 -3
- package/dist/esm/embedders/index.d.ts +4 -4
- package/dist/esm/events/payloads.d.ts +10 -14
- package/dist/esm/hosting-providers.d.ts +16 -16
- package/dist/esm/hosting-providers.js +16 -16
- package/dist/esm/identity/types.d.ts +1 -1
- package/dist/esm/identity/types.js +1 -1
- package/dist/esm/identity/withCredentialRetry.d.ts +1 -1
- package/dist/esm/identity/withCredentialRetry.js +1 -1
- package/dist/esm/identity.d.ts +5 -5
- package/dist/esm/identity.js +5 -5
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/injection-engine.d.ts +4 -4
- package/dist/esm/injection-engine.js +4 -4
- package/dist/esm/lib/context-ledger/gates.d.ts +1 -1
- package/dist/esm/lib/context-ledger/gates.js +1 -1
- package/dist/esm/lib/injection-engine/SkillRegistry.d.ts +1 -1
- package/dist/esm/lib/injection-engine/SkillRegistry.js +1 -1
- package/dist/esm/lib/injection-engine/factories/defineSkill.d.ts +1 -16
- package/dist/esm/lib/injection-engine/factories/defineSkill.js +29 -1
- package/dist/esm/lib/injection-engine/factories/defineSkill.js.map +1 -1
- package/dist/esm/lib/injection-engine/skillsFromDir.d.ts +1 -11
- package/dist/esm/lib/injection-engine/skillsFromDir.js +22 -2
- package/dist/esm/lib/injection-engine/skillsFromDir.js.map +1 -1
- package/dist/esm/lib/injection-engine/types.d.ts +1 -1
- package/dist/esm/lib/mcp/gatewayTransport.d.ts +2 -2
- package/dist/esm/lib/mcp/gatewayTransport.js +2 -2
- package/dist/esm/lib/rag/defineRAG.d.ts +9 -6
- package/dist/esm/lib/rag/defineRAG.js.map +1 -1
- package/dist/esm/lib/recorded-chat/index.d.ts +1 -1
- package/dist/esm/lib/recorded-chat/index.js +1 -1
- package/dist/esm/llm-providers.d.ts +5 -19
- package/dist/esm/llm-providers.js +5 -19
- package/dist/esm/llm-providers.js.map +1 -1
- package/dist/esm/locales/index.d.ts +7 -7
- package/dist/esm/locales/index.js +7 -7
- package/dist/esm/memory/causal/evidenceRecorder.d.ts +1 -1
- package/dist/esm/memory/causal/evidenceRecorder.js +1 -1
- package/dist/esm/memory/define.types.d.ts +3 -2
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/index.d.ts +0 -10
- package/dist/esm/memory/index.js +6 -0
- package/dist/esm/memory/index.js.map +1 -1
- package/dist/esm/memory/retrieval/topK.d.ts +12 -6
- package/dist/esm/memory/retrieval/topK.js.map +1 -1
- package/dist/esm/memory/store/index.d.ts +1 -0
- package/dist/esm/memory/store/index.js +1 -0
- package/dist/esm/memory/store/index.js.map +1 -1
- package/dist/esm/memory/store/staticVectorStore.d.ts +83 -0
- package/dist/esm/memory/store/staticVectorStore.js +224 -0
- package/dist/esm/memory/store/staticVectorStore.js.map +1 -0
- package/dist/esm/memory-providers.d.ts +8 -24
- package/dist/esm/memory-providers.js +8 -24
- package/dist/esm/memory-providers.js.map +1 -1
- package/dist/esm/observability/contextError/finders/index.d.ts +4 -4
- package/dist/esm/observability-providers.d.ts +5 -5
- package/dist/esm/observability-providers.js +5 -5
- package/dist/esm/observe.d.ts +1 -0
- package/dist/esm/observe.js +11 -6
- package/dist/esm/observe.js.map +1 -1
- package/dist/esm/providers.d.ts +2 -2
- package/dist/esm/providers.js +2 -2
- package/dist/esm/rag/exportCorpus.d.ts +64 -0
- package/dist/esm/rag/exportCorpus.js +172 -0
- package/dist/esm/rag/exportCorpus.js.map +1 -0
- package/dist/esm/rag/index.d.ts +3 -1
- package/dist/esm/rag/index.js +8 -1
- package/dist/esm/rag/index.js.map +1 -1
- package/dist/esm/rag/splitters/byHeading.d.ts +39 -0
- package/dist/esm/rag/splitters/byHeading.js +133 -15
- package/dist/esm/rag/splitters/byHeading.js.map +1 -1
- package/dist/esm/rag/splitters/byParagraph.d.ts +14 -0
- package/dist/esm/rag/splitters/byParagraph.js +4 -2
- package/dist/esm/rag/splitters/byParagraph.js.map +1 -1
- package/dist/esm/rag/splitters/constants.d.ts +24 -1
- package/dist/esm/rag/splitters/constants.js +24 -1
- package/dist/esm/rag/splitters/constants.js.map +1 -1
- package/dist/esm/rag/splitters/index.d.ts +15 -1
- package/dist/esm/rag/splitters/index.js +15 -1
- package/dist/esm/rag/splitters/index.js.map +1 -1
- package/dist/esm/rag/splitters/shared.d.ts +32 -0
- package/dist/esm/rag/splitters/shared.js +77 -1
- package/dist/esm/rag/splitters/shared.js.map +1 -1
- package/dist/esm/recorders/core/ContextRecorder.js +47 -11
- package/dist/esm/recorders/core/ContextRecorder.js.map +1 -1
- package/dist/esm/recorders/core/types.d.ts +16 -18
- package/dist/esm/recorders/core/types.js.map +1 -1
- package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +24 -0
- package/dist/esm/recorders/observability/BoundaryRecorder.js +19 -6
- package/dist/esm/recorders/observability/BoundaryRecorder.js.map +1 -1
- package/dist/esm/recorders/observability/RouteRecorder.d.ts +1 -1
- package/dist/esm/recorders/observability/RouteRecorder.js +1 -1
- package/dist/esm/recorders/observability/ToolChoiceRecorder.d.ts +1 -1
- package/dist/esm/recorders/observability/ToolChoiceRecorder.js +1 -1
- package/dist/esm/recorders/observability/embeddingSummary.d.ts +56 -0
- package/dist/esm/recorders/observability/embeddingSummary.js +114 -0
- package/dist/esm/recorders/observability/embeddingSummary.js.map +1 -0
- package/dist/esm/recorders/observability/recordRun.d.ts +16 -0
- package/dist/esm/recorders/observability/recordRun.js +17 -3
- package/dist/esm/recorders/observability/recordRun.js.map +1 -1
- package/dist/esm/reliability/index.d.ts +15 -3
- package/dist/esm/reliability/index.js +15 -3
- package/dist/esm/reliability/index.js.map +1 -1
- package/dist/esm/resilience/fallbackProvider.d.ts +1 -1
- package/dist/esm/resilience/fallbackProvider.js +1 -1
- package/dist/esm/resilience/withCircuitBreaker.d.ts +1 -1
- package/dist/esm/resilience/withCircuitBreaker.js +1 -1
- package/dist/esm/resilience/withRetry.d.ts +1 -1
- package/dist/esm/resilience/withRetry.js +1 -1
- package/dist/esm/security/PermissionPolicy.d.ts +2 -2
- package/dist/esm/security/PermissionPolicy.js +2 -2
- package/dist/esm/security/index.d.ts +3 -3
- package/dist/esm/security/index.js +3 -3
- package/dist/esm/status.d.ts +14 -24
- package/dist/esm/status.js +15 -25
- package/dist/esm/status.js.map +1 -1
- package/dist/esm/strategies/index.d.ts +9 -16
- package/dist/esm/strategies/index.js +9 -16
- package/dist/esm/strategies/index.js.map +1 -1
- package/dist/esm/strategies/registry.d.ts +1 -1
- package/dist/esm/strategies/registry.js +1 -1
- package/dist/esm/stream.d.ts +4 -4
- package/dist/esm/stream.js +4 -4
- package/dist/esm/thinking/index.d.ts +5 -5
- package/dist/esm/thinking/index.js +5 -5
- package/dist/esm/tool-providers/index.d.ts +4 -4
- package/dist/esm/tool-providers/index.js +4 -4
- package/dist/hosting-providers.js +16 -16
- package/dist/identity/types.js +1 -1
- package/dist/identity/withCredentialRetry.js +1 -1
- package/dist/identity.js +5 -5
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/injection-engine.js +4 -4
- package/dist/lib/context-ledger/gates.js +1 -1
- package/dist/lib/injection-engine/SkillRegistry.js +1 -1
- package/dist/lib/injection-engine/factories/defineSkill.js +29 -1
- package/dist/lib/injection-engine/factories/defineSkill.js.map +1 -1
- package/dist/lib/injection-engine/skillsFromDir.js +22 -2
- package/dist/lib/injection-engine/skillsFromDir.js.map +1 -1
- package/dist/lib/mcp/gatewayTransport.js +2 -2
- package/dist/lib/rag/defineRAG.js.map +1 -1
- package/dist/lib/recorded-chat/index.js +1 -1
- package/dist/llm-providers.js +5 -19
- package/dist/llm-providers.js.map +1 -1
- package/dist/locales/index.js +6 -6
- package/dist/memory/causal/evidenceRecorder.js +1 -1
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/index.js +6 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/retrieval/topK.js.map +1 -1
- package/dist/memory/store/index.js +6 -1
- package/dist/memory/store/index.js.map +1 -1
- package/dist/memory/store/staticVectorStore.js +230 -0
- package/dist/memory/store/staticVectorStore.js.map +1 -0
- package/dist/memory-providers.js +8 -24
- package/dist/memory-providers.js.map +1 -1
- package/dist/observability-providers.js +5 -5
- package/dist/observe.js +14 -7
- package/dist/observe.js.map +1 -1
- package/dist/providers.js +2 -2
- package/dist/rag/exportCorpus.js +177 -0
- package/dist/rag/exportCorpus.js.map +1 -0
- package/dist/rag/index.js +13 -1
- package/dist/rag/index.js.map +1 -1
- package/dist/rag/splitters/byHeading.js +132 -14
- package/dist/rag/splitters/byHeading.js.map +1 -1
- package/dist/rag/splitters/byParagraph.js +3 -1
- package/dist/rag/splitters/byParagraph.js.map +1 -1
- package/dist/rag/splitters/constants.js +25 -2
- package/dist/rag/splitters/constants.js.map +1 -1
- package/dist/rag/splitters/index.js +16 -1
- package/dist/rag/splitters/index.js.map +1 -1
- package/dist/rag/splitters/shared.js +79 -1
- package/dist/rag/splitters/shared.js.map +1 -1
- package/dist/recorders/core/ContextRecorder.js +47 -11
- package/dist/recorders/core/ContextRecorder.js.map +1 -1
- package/dist/recorders/core/types.js.map +1 -1
- package/dist/recorders/observability/BoundaryRecorder.js +19 -6
- package/dist/recorders/observability/BoundaryRecorder.js.map +1 -1
- package/dist/recorders/observability/RouteRecorder.js +1 -1
- package/dist/recorders/observability/ToolChoiceRecorder.js +1 -1
- package/dist/recorders/observability/embeddingSummary.js +119 -0
- package/dist/recorders/observability/embeddingSummary.js.map +1 -0
- package/dist/recorders/observability/recordRun.js +17 -3
- package/dist/recorders/observability/recordRun.js.map +1 -1
- package/dist/reliability/index.js +15 -3
- package/dist/reliability/index.js.map +1 -1
- package/dist/resilience/fallbackProvider.js +1 -1
- package/dist/resilience/withCircuitBreaker.js +1 -1
- package/dist/resilience/withRetry.js +1 -1
- package/dist/security/PermissionPolicy.js +2 -2
- package/dist/security/index.js +3 -3
- package/dist/status.js +14 -24
- package/dist/status.js.map +1 -1
- package/dist/strategies/index.js +9 -16
- package/dist/strategies/index.js.map +1 -1
- package/dist/strategies/registry.js +1 -1
- package/dist/stream.js +4 -4
- package/dist/thinking/index.js +5 -5
- package/dist/tool-providers/index.js +4 -4
- package/dist/types/adapters/hosting/agentcore.d.ts +1 -1
- package/dist/types/adapters/identity/agentcore.d.ts +1 -1
- package/dist/types/adapters/llm/AnthropicProvider.d.ts +1 -1
- package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +1 -1
- package/dist/types/adapters/llm/MockProvider.d.ts +1 -1
- package/dist/types/adapters/llm/OpenAIProvider.d.ts +2 -2
- package/dist/types/adapters/memory/agentcore.d.ts +1 -1
- package/dist/types/adapters/memory/bedrockAgentMemory.d.ts +1 -1
- package/dist/types/adapters/memory/redis.d.ts +1 -1
- package/dist/types/adapters/observability/agentcore.d.ts +2 -2
- package/dist/types/adapters/observability/audit.d.ts +1 -1
- package/dist/types/adapters/observability/cloudwatch.d.ts +2 -2
- package/dist/types/adapters/observability/otel.d.ts +4 -4
- package/dist/types/adapters/observability/xray.d.ts +2 -2
- package/dist/types/core/agent/AgentBuilder.d.ts +17 -14
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/core/agent/stages/window.d.ts.map +1 -1
- package/dist/types/core/agent/types.d.ts +2 -2
- package/dist/types/core/agent/watch.d.ts +1 -1
- package/dist/types/core/agent/window/index.d.ts +1 -1
- package/dist/types/core/agent/window/index.d.ts.map +1 -1
- package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts.map +1 -1
- package/dist/types/core/agent/window/types.d.ts +0 -30
- package/dist/types/core/agent/window/types.d.ts.map +1 -1
- package/dist/types/core/runner.d.ts +1 -1
- package/dist/types/core/slots/helpers.d.ts +3 -4
- package/dist/types/core/slots/helpers.d.ts.map +1 -1
- package/dist/types/debug/finders.d.ts +7 -10
- package/dist/types/debug/finders.d.ts.map +1 -1
- package/dist/types/debug.d.ts +4 -4
- package/dist/types/doors/context.d.ts +3 -3
- package/dist/types/embedders/index.d.ts +4 -4
- package/dist/types/events/payloads.d.ts +10 -14
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/hosting-providers.d.ts +16 -16
- package/dist/types/identity/types.d.ts +1 -1
- package/dist/types/identity/withCredentialRetry.d.ts +1 -1
- package/dist/types/identity.d.ts +5 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/injection-engine.d.ts +4 -4
- package/dist/types/lib/context-ledger/gates.d.ts +1 -1
- package/dist/types/lib/injection-engine/SkillRegistry.d.ts +1 -1
- package/dist/types/lib/injection-engine/factories/defineSkill.d.ts +1 -16
- package/dist/types/lib/injection-engine/factories/defineSkill.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/skillsFromDir.d.ts +1 -11
- package/dist/types/lib/injection-engine/skillsFromDir.d.ts.map +1 -1
- package/dist/types/lib/injection-engine/types.d.ts +1 -1
- package/dist/types/lib/mcp/gatewayTransport.d.ts +2 -2
- package/dist/types/lib/rag/defineRAG.d.ts +9 -6
- package/dist/types/lib/rag/defineRAG.d.ts.map +1 -1
- package/dist/types/lib/recorded-chat/index.d.ts +1 -1
- package/dist/types/llm-providers.d.ts +5 -19
- package/dist/types/llm-providers.d.ts.map +1 -1
- package/dist/types/locales/index.d.ts +7 -7
- package/dist/types/memory/causal/evidenceRecorder.d.ts +1 -1
- package/dist/types/memory/define.types.d.ts +3 -2
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/index.d.ts +0 -10
- package/dist/types/memory/index.d.ts.map +1 -1
- package/dist/types/memory/retrieval/topK.d.ts +12 -6
- package/dist/types/memory/retrieval/topK.d.ts.map +1 -1
- package/dist/types/memory/store/index.d.ts +1 -0
- package/dist/types/memory/store/index.d.ts.map +1 -1
- package/dist/types/memory/store/staticVectorStore.d.ts +84 -0
- package/dist/types/memory/store/staticVectorStore.d.ts.map +1 -0
- package/dist/types/memory-providers.d.ts +8 -24
- package/dist/types/memory-providers.d.ts.map +1 -1
- package/dist/types/observability/contextError/finders/index.d.ts +4 -4
- package/dist/types/observability-providers.d.ts +5 -5
- package/dist/types/observe.d.ts +1 -0
- package/dist/types/observe.d.ts.map +1 -1
- package/dist/types/providers.d.ts +2 -2
- package/dist/types/rag/exportCorpus.d.ts +65 -0
- package/dist/types/rag/exportCorpus.d.ts.map +1 -0
- package/dist/types/rag/index.d.ts +3 -1
- package/dist/types/rag/index.d.ts.map +1 -1
- package/dist/types/rag/splitters/byHeading.d.ts +39 -0
- package/dist/types/rag/splitters/byHeading.d.ts.map +1 -1
- package/dist/types/rag/splitters/byParagraph.d.ts +14 -0
- package/dist/types/rag/splitters/byParagraph.d.ts.map +1 -1
- package/dist/types/rag/splitters/constants.d.ts +24 -1
- package/dist/types/rag/splitters/constants.d.ts.map +1 -1
- package/dist/types/rag/splitters/index.d.ts +15 -1
- package/dist/types/rag/splitters/index.d.ts.map +1 -1
- package/dist/types/rag/splitters/shared.d.ts +32 -0
- package/dist/types/rag/splitters/shared.d.ts.map +1 -1
- package/dist/types/recorders/core/ContextRecorder.d.ts.map +1 -1
- package/dist/types/recorders/core/types.d.ts +16 -18
- package/dist/types/recorders/core/types.d.ts.map +1 -1
- package/dist/types/recorders/observability/BoundaryRecorder.d.ts +24 -0
- package/dist/types/recorders/observability/BoundaryRecorder.d.ts.map +1 -1
- package/dist/types/recorders/observability/RouteRecorder.d.ts +1 -1
- package/dist/types/recorders/observability/ToolChoiceRecorder.d.ts +1 -1
- package/dist/types/recorders/observability/embeddingSummary.d.ts +57 -0
- package/dist/types/recorders/observability/embeddingSummary.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordRun.d.ts +16 -0
- package/dist/types/recorders/observability/recordRun.d.ts.map +1 -1
- package/dist/types/reliability/index.d.ts +15 -3
- package/dist/types/reliability/index.d.ts.map +1 -1
- package/dist/types/resilience/fallbackProvider.d.ts +1 -1
- package/dist/types/resilience/withCircuitBreaker.d.ts +1 -1
- package/dist/types/resilience/withRetry.d.ts +1 -1
- package/dist/types/security/PermissionPolicy.d.ts +2 -2
- package/dist/types/security/index.d.ts +3 -3
- package/dist/types/status.d.ts +14 -24
- package/dist/types/status.d.ts.map +1 -1
- package/dist/types/strategies/index.d.ts +9 -16
- package/dist/types/strategies/index.d.ts.map +1 -1
- package/dist/types/strategies/registry.d.ts +1 -1
- package/dist/types/stream.d.ts +4 -4
- package/dist/types/thinking/index.d.ts +5 -5
- package/dist/types/tool-providers/index.d.ts +4 -4
- package/package.json +1 -209
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { assertServesVectors } from '../memory/store/capability.js';
|
|
2
|
+
import { identityNamespace } from '../memory/identity/index.js';
|
|
3
|
+
import { chunkText } from '../memory/retrieval/provenance.js';
|
|
4
|
+
import { CORPUS_BUNDLE_FORMAT, assertCorpusBundle, bundleEntryToMemoryEntry, } from '../memory/store/staticVectorStore.js';
|
|
5
|
+
import { DEFAULT_CORPUS_IDENTITY } from '../lib/rag/defineRAG.js';
|
|
6
|
+
/**
|
|
7
|
+
* Export every entry of a corpus namespace as a plain-JSON bundle.
|
|
8
|
+
*
|
|
9
|
+
* @param store the store the corpus was indexed into. Any `MemoryStore`
|
|
10
|
+
* that can `list` — the reference stores and the durable one
|
|
11
|
+
* all can.
|
|
12
|
+
* @param identity the namespace to export. Defaults to the same
|
|
13
|
+
* `{ conversationId: '_global' }` that `indexCorpus`,
|
|
14
|
+
* `indexFolder`, `indexDocuments` and `defineRAG` default to,
|
|
15
|
+
* so the plain path needs no argument anywhere.
|
|
16
|
+
*
|
|
17
|
+
* @throws when the namespace is empty (almost always an identity mismatch,
|
|
18
|
+
* named as such), when an entry carries no vector or no passage (a
|
|
19
|
+
* bundle never ships an unservable entry), or when the namespace
|
|
20
|
+
* mixes embedding spaces (two spaces in one bundle could never be
|
|
21
|
+
* served by one embedder).
|
|
22
|
+
*/
|
|
23
|
+
export async function exportCorpus(store, identity = DEFAULT_CORPUS_IDENTITY) {
|
|
24
|
+
if (!store)
|
|
25
|
+
throw new Error('exportCorpus: `store` is required.');
|
|
26
|
+
const namespace = identityNamespace(identity);
|
|
27
|
+
const collected = [];
|
|
28
|
+
let cursor;
|
|
29
|
+
do {
|
|
30
|
+
const page = await store.list(identity, {
|
|
31
|
+
limit: 500,
|
|
32
|
+
...(cursor !== undefined && { cursor }),
|
|
33
|
+
});
|
|
34
|
+
collected.push(...page.entries);
|
|
35
|
+
cursor = page.cursor;
|
|
36
|
+
} while (cursor !== undefined);
|
|
37
|
+
if (collected.length === 0) {
|
|
38
|
+
throw new Error(`exportCorpus: namespace '${namespace}' holds no entries at all. The usual cause is an ` +
|
|
39
|
+
`identity mismatch: the corpus was indexed under a different identity than the one ` +
|
|
40
|
+
`being exported. indexCorpus/indexFolder/indexDocuments default to ` +
|
|
41
|
+
`{ conversationId: '_global' } — pass the same \`identity\` here that you indexed ` +
|
|
42
|
+
`under.`);
|
|
43
|
+
}
|
|
44
|
+
// Every entry must be servable: a vector (or it can never be retrieved) and
|
|
45
|
+
// a passage (or its retrieval renders a blank citation). Named, bounded.
|
|
46
|
+
const noVector = [];
|
|
47
|
+
const noPassage = [];
|
|
48
|
+
const spaces = new Map(); // '<id>@<dims>' → count
|
|
49
|
+
for (const entry of collected) {
|
|
50
|
+
const vector = entry.embedding;
|
|
51
|
+
if (!vector || vector.length === 0) {
|
|
52
|
+
noVector.push(entry.id);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (chunkText(entry.value).trim().length === 0)
|
|
56
|
+
noPassage.push(entry.id);
|
|
57
|
+
const space = `${entry.embeddingModel ?? 'default-embedder'}@${vector.length}`;
|
|
58
|
+
spaces.set(space, (spaces.get(space) ?? 0) + 1);
|
|
59
|
+
}
|
|
60
|
+
if (noVector.length > 0) {
|
|
61
|
+
throw new Error(`exportCorpus: ${noVector.length} entr${noVector.length === 1 ? 'y' : 'ies'} in ` +
|
|
62
|
+
`'${namespace}' carr${noVector.length === 1 ? 'ies' : 'y'} no embedding vector: ` +
|
|
63
|
+
`${sample(noVector)}. A bundle entry without a vector could never be retrieved. ` +
|
|
64
|
+
`This namespace holds more than an indexed corpus (conversation memory shares it?) — ` +
|
|
65
|
+
`export a namespace that holds only the corpus, or re-index it.`);
|
|
66
|
+
}
|
|
67
|
+
if (noPassage.length > 0) {
|
|
68
|
+
throw new Error(`exportCorpus: ${noPassage.length} entr${noPassage.length === 1 ? 'y' : 'ies'} in ` +
|
|
69
|
+
`'${namespace}' carr${noPassage.length === 1 ? 'ies' : 'y'} no passage (neither ` +
|
|
70
|
+
`\`content\` nor \`text\` on the value): ${sample(noPassage)}. A citable id with ` +
|
|
71
|
+
`nothing to cite is the blank-citation bug; a bundle never ships one.`);
|
|
72
|
+
}
|
|
73
|
+
if (spaces.size > 1) {
|
|
74
|
+
throw new Error(`exportCorpus: namespace '${namespace}' mixes ${spaces.size} embedding spaces ` +
|
|
75
|
+
`(${[...spaces.entries()].map(([s, n]) => `'${s}' ×${n}`).join(', ')}). One bundle ` +
|
|
76
|
+
`serves one space — no single query embedder could search both. Re-index the ` +
|
|
77
|
+
`namespace with one embedder, then export.`);
|
|
78
|
+
}
|
|
79
|
+
// Exactly one space — parse it back apart. The id may itself contain '@'
|
|
80
|
+
// (provider-prefixed ids do), so split on the LAST one.
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
82
|
+
const space = [...spaces.keys()][0];
|
|
83
|
+
const at = space.lastIndexOf('@');
|
|
84
|
+
const embedderId = space.slice(0, at);
|
|
85
|
+
const dimensions = Number(space.slice(at + 1));
|
|
86
|
+
const entries = collected.map((entry) => {
|
|
87
|
+
const metadata = flattenMetadata(entry);
|
|
88
|
+
return {
|
|
89
|
+
id: entry.id,
|
|
90
|
+
text: chunkText(entry.value),
|
|
91
|
+
// Validated non-empty above.
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
93
|
+
vector: [...entry.embedding],
|
|
94
|
+
...(metadata !== undefined && { metadata }),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
format: CORPUS_BUNDLE_FORMAT,
|
|
99
|
+
embedder: { id: embedderId, dimensions },
|
|
100
|
+
namespace,
|
|
101
|
+
exportedAt: Date.now(),
|
|
102
|
+
entries,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Load a bundle into a WRITABLE vector-capable store — the inverse of
|
|
107
|
+
* `exportCorpus`. Use it to seed an `InMemoryStore` at boot from a shipped
|
|
108
|
+
* bundle, or to migrate a corpus between machines without re-embedding.
|
|
109
|
+
*
|
|
110
|
+
* Entries are written in the same formatter-ready shape `staticVectorStore`
|
|
111
|
+
* serves, so the two paths render identically.
|
|
112
|
+
*
|
|
113
|
+
* @returns the number of entries written.
|
|
114
|
+
*/
|
|
115
|
+
export async function importCorpus(store, bundle, identity) {
|
|
116
|
+
if (!store)
|
|
117
|
+
throw new Error('importCorpus: `store` is required.');
|
|
118
|
+
assertCorpusBundle(bundle, 'importCorpus');
|
|
119
|
+
assertServesVectors(store, 'importCorpus');
|
|
120
|
+
// Default to the namespace the bundle was exported from. An explicit
|
|
121
|
+
// identity re-homes the corpus (per-tenant seeding).
|
|
122
|
+
const target = identity ?? { conversationId: bundleConversationId(bundle) };
|
|
123
|
+
const rows = bundle.entries.map((entry) => bundleEntryToMemoryEntry(entry, bundle));
|
|
124
|
+
for (let i = 0; i < rows.length; i += 100) {
|
|
125
|
+
await store.putMany(target, rows.slice(i, i + 100));
|
|
126
|
+
}
|
|
127
|
+
return rows.length;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The `conversationId` that reproduces the bundle's namespace under the
|
|
131
|
+
* default identity scheme (`identityNamespace({ conversationId: X })` ===
|
|
132
|
+
* bundle.namespace for the default exports). Falls back to the namespace
|
|
133
|
+
* string itself, which keeps import/export round-trips stable even for
|
|
134
|
+
* exotic identities — pass an explicit `identity` to `importCorpus` when the
|
|
135
|
+
* corpus was indexed under one.
|
|
136
|
+
*/
|
|
137
|
+
function bundleConversationId(bundle) {
|
|
138
|
+
const probe = identityNamespace(DEFAULT_CORPUS_IDENTITY);
|
|
139
|
+
if (bundle.namespace === probe) {
|
|
140
|
+
return DEFAULT_CORPUS_IDENTITY.conversationId;
|
|
141
|
+
}
|
|
142
|
+
return bundle.namespace;
|
|
143
|
+
}
|
|
144
|
+
/** First few ids, so a refusal is findable without being a wall. */
|
|
145
|
+
function sample(ids) {
|
|
146
|
+
const shown = ids.slice(0, 5).join(', ');
|
|
147
|
+
return ids.length > 5 ? `${shown}, and ${ids.length - 5} more` : shown;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Everything the stored value carried EXCEPT the passage, flattened into one
|
|
151
|
+
* metadata record: nested `metadata` first, then the value's own top-level
|
|
152
|
+
* fields (`docUri`, `heading`, `page`, offsets, hashes — a `Chunk` keeps its
|
|
153
|
+
* provenance at the top level). The provenance reader accepts either level,
|
|
154
|
+
* and flattening keeps re-exports stable.
|
|
155
|
+
*/
|
|
156
|
+
function flattenMetadata(entry) {
|
|
157
|
+
const value = entry.value;
|
|
158
|
+
if (value === null || typeof value !== 'object')
|
|
159
|
+
return undefined;
|
|
160
|
+
const record = value;
|
|
161
|
+
const nested = typeof record.metadata === 'object' && record.metadata !== null
|
|
162
|
+
? record.metadata
|
|
163
|
+
: undefined;
|
|
164
|
+
const out = { ...(nested ?? {}) };
|
|
165
|
+
for (const [key, field] of Object.entries(record)) {
|
|
166
|
+
if (key === 'content' || key === 'text' || key === 'metadata')
|
|
167
|
+
continue;
|
|
168
|
+
out[key] = field;
|
|
169
|
+
}
|
|
170
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=exportCorpus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exportCorpus.js","sourceRoot":"","sources":["../../../src/rag/exportCorpus.ts"],"names":[],"mappings":"AAiCA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GAGzB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAkB,EAClB,WAA2B,uBAAuB;IAElD,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAClE,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAE9C,MAAM,SAAS,GAA2B,EAAE,CAAC;IAC7C,IAAI,MAA0B,CAAC;IAC/B,GAAG,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;YACtC,KAAK,EAAE,GAAG;YACV,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC;SACxC,CAAC,CAAC;QACH,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC,QAAQ,MAAM,KAAK,SAAS,EAA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AAC,QAAoC;QAC9C,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,GAAG,GAA4B,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAAC;IAC3D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,UAAU;YAAE,SAAS;QACxE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
|
package/dist/esm/rag/index.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export { splitDocuments, type SplitDocumentsOptions } from './splitDocuments.js'
|
|
|
11
11
|
export { indexCorpus, buildIndexChart, type IndexCorpusConfig } from './indexCorpus.js';
|
|
12
12
|
export { indexFolder, type IndexFolderOptions } from './indexFolder.js';
|
|
13
13
|
export { sha256 } from './hash.js';
|
|
14
|
+
export { exportCorpus, importCorpus } from './exportCorpus.js';
|
|
15
|
+
export { staticVectorStore, CORPUS_BUNDLE_FORMAT, type CorpusBundle, type CorpusBundleEntry, type EmbedderFingerprint, } from '../memory/store/staticVectorStore.js';
|
|
14
16
|
export { DEFAULT_LOADERS, textLoader, markdownLoader, htmlLoader, pdfLoader, mockLoader, MissingPdfSupportError, type PdfLoaderOptions, type MockLoaderOptions, } from './loaders/index.js';
|
|
15
17
|
export { stripTags } from './loaders/html.js';
|
|
16
|
-
export { byParagraph, byHeading, fixedWithOverlap, wholeDocument, DEFAULT_MAX_CHARS, DEFAULT_OVERLAP_CHARS, type ByParagraphOptions, type ByHeadingOptions, type FixedWithOverlapOptions, } from './splitters/index.js';
|
|
18
|
+
export { byParagraph, byHeading, fixedWithOverlap, wholeDocument, DEFAULT_MAX_CHARS, DEFAULT_OVERLAP_CHARS, DEFAULT_MIN_CHARS, type ByParagraphOptions, type ByHeadingOptions, type FixedWithOverlapOptions, } from './splitters/index.js';
|
|
17
19
|
export type { Chunk, DocumentInput, DocumentLoader, DocumentSource, FailedDocument, IndexReport, LoadedDocument, LoadedDocumentDraft, Splitter, SplitPiece, TruncatedChunk, } from './types.js';
|
package/dist/esm/rag/index.js
CHANGED
|
@@ -11,7 +11,14 @@ export { splitDocuments } from './splitDocuments.js';
|
|
|
11
11
|
export { indexCorpus, buildIndexChart } from './indexCorpus.js';
|
|
12
12
|
export { indexFolder } from './indexFolder.js';
|
|
13
13
|
export { sha256 } from './hash.js';
|
|
14
|
+
// Corpus-as-build-artifact (8.20.0): index where the credentials and durable
|
|
15
|
+
// disk live, ship a plain-JSON bundle, serve it read-only where the process
|
|
16
|
+
// runs. `staticVectorStore` is canonical in `agentfootprint/memory` (the
|
|
17
|
+
// runtime side needs no filesystem door) and re-exported here so the whole
|
|
18
|
+
// story is visible from the door that builds the bundle.
|
|
19
|
+
export { exportCorpus, importCorpus } from './exportCorpus.js';
|
|
20
|
+
export { staticVectorStore, CORPUS_BUNDLE_FORMAT, } from '../memory/store/staticVectorStore.js';
|
|
14
21
|
export { DEFAULT_LOADERS, textLoader, markdownLoader, htmlLoader, pdfLoader, mockLoader, MissingPdfSupportError, } from './loaders/index.js';
|
|
15
22
|
export { stripTags } from './loaders/html.js';
|
|
16
|
-
export { byParagraph, byHeading, fixedWithOverlap, wholeDocument, DEFAULT_MAX_CHARS, DEFAULT_OVERLAP_CHARS, } from './splitters/index.js';
|
|
23
|
+
export { byParagraph, byHeading, fixedWithOverlap, wholeDocument, DEFAULT_MAX_CHARS, DEFAULT_OVERLAP_CHARS, DEFAULT_MIN_CHARS, } from './splitters/index.js';
|
|
17
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rag/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAA8B,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAA0B,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,WAAW,EAA2B,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EACL,eAAe,EACf,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,UAAU,EACV,sBAAsB,GAGvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EACL,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rag/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAA8B,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAA0B,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,WAAW,EAA2B,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,2EAA2E;AAC3E,yDAAyD;AACzD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,GAIrB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,eAAe,EACf,UAAU,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,UAAU,EACV,sBAAsB,GAGvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EACL,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GAIlB,MAAM,sBAAsB,CAAC"}
|
|
@@ -19,6 +19,31 @@
|
|
|
19
19
|
* and, failing that, hard-cut; every piece keeps the heading it came from.
|
|
20
20
|
* Text before the first heading (a preamble, a title block) is its own
|
|
21
21
|
* heading-less section rather than being attached to a heading it precedes.
|
|
22
|
+
*
|
|
23
|
+
* ── The floor, and why merging goes FORWARD (8.20.0) ────────────────────────
|
|
24
|
+
* A section whose own body is tiny does not retrieve badly — it retrieves TOO
|
|
25
|
+
* WELL. Similarity is a density measure: a heading plus one preamble sentence
|
|
26
|
+
* concentrates its topic's vocabulary with none of its substance. Measured in
|
|
27
|
+
* a production corpus, a 180-character heading-and-preamble chunk outranked
|
|
28
|
+
* the 1,032-character body of its own section at 0.430 — and the model,
|
|
29
|
+
* handed a passage that PROMISES findings and contains none, fabricated a
|
|
30
|
+
* plausible file path to fill the gap.
|
|
31
|
+
*
|
|
32
|
+
* So a section whose body is under `minChars` is merged into the chunk that
|
|
33
|
+
* FOLLOWS it, under its own heading — the preamble sentence survives, leading
|
|
34
|
+
* the chunk it introduces, and the citation still names the section a reader
|
|
35
|
+
* would look up. Merging it BACKWARD would append it to the previous section's
|
|
36
|
+
* chunk, where it introduces nothing and its heading would be lost; merging
|
|
37
|
+
* forward is the direction the author's own document flows. The last section
|
|
38
|
+
* has no next, so a trailing short section merges backward — the one edge
|
|
39
|
+
* where that is the only honest option. Nothing is ever dropped.
|
|
40
|
+
*
|
|
41
|
+
* Two special cases are unconditional, independent of `minChars`:
|
|
42
|
+
* - a section that is heading-plus-whitespace is NEVER emitted alone. It is
|
|
43
|
+
* a coordinate, not a passage — the same distinction `indexDocuments`
|
|
44
|
+
* enforces one layer up when it refuses a passage-less document.
|
|
45
|
+
* - a document that is NOTHING but headings and whitespace yields no chunks
|
|
46
|
+
* at all: there is no passage anywhere in it to retrieve.
|
|
22
47
|
*/
|
|
23
48
|
import type { Splitter } from '../types.js';
|
|
24
49
|
export interface ByHeadingOptions {
|
|
@@ -32,5 +57,19 @@ export interface ByHeadingOptions {
|
|
|
32
57
|
* `####` for emphasis rather than structure.
|
|
33
58
|
*/
|
|
34
59
|
readonly maxLevel?: number;
|
|
60
|
+
/**
|
|
61
|
+
* The floor under a section's own body, in characters (8.20.0). A section
|
|
62
|
+
* whose body is shorter is merged FORWARD into the next chunk under its own
|
|
63
|
+
* heading — never dropped, never shipped alone. Default
|
|
64
|
+
* `min(250, maxChars / 4)`; see `DEFAULT_MIN_CHARS` for the field
|
|
65
|
+
* measurement behind the number (a 180-char heading-and-preamble chunk that
|
|
66
|
+
* outranked its own section's 1,032-char body and drove a fabricated
|
|
67
|
+
* citation).
|
|
68
|
+
*
|
|
69
|
+
* `0` disables the floor. A heading-plus-whitespace section is still never
|
|
70
|
+
* emitted alone — that refusal is unconditional, because a chunk with no
|
|
71
|
+
* body at all is a coordinate, not a passage.
|
|
72
|
+
*/
|
|
73
|
+
readonly minChars?: number;
|
|
35
74
|
}
|
|
36
75
|
export declare function byHeading(options?: ByHeadingOptions): Splitter;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DEFAULT_MAX_CHARS, DEFAULT_OVERLAP_CHARS } from './constants.js';
|
|
2
|
-
import { applyOverlap, foldRunts, hardCut, packSpans, paragraphSpans, toPieces, } from './shared.js';
|
|
2
|
+
import { applyOverlap, foldRunts, hardCut, mergeShortSpansForward, packSpans, paragraphSpans, resolveMinChars, toPieces, } from './shared.js';
|
|
3
3
|
/** ATX headings only (`# Title`). Setext (`Title\n=====`) is rare in docs corpora. */
|
|
4
4
|
const HEADING = /^(#{1,6})[ \t]+(.+?)[ \t]*$/gm;
|
|
5
5
|
export function byHeading(options = {}) {
|
|
6
6
|
const maxChars = options.maxChars ?? DEFAULT_MAX_CHARS;
|
|
7
7
|
const overlapChars = options.overlapChars ?? DEFAULT_OVERLAP_CHARS;
|
|
8
8
|
const maxLevel = options.maxLevel ?? 6;
|
|
9
|
+
const minChars = resolveMinChars(options.minChars, maxChars);
|
|
9
10
|
return {
|
|
10
11
|
name: 'byHeading',
|
|
11
12
|
split(doc) {
|
|
@@ -17,39 +18,67 @@ export function byHeading(options = {}) {
|
|
|
17
18
|
while ((match = HEADING.exec(text)) !== null) {
|
|
18
19
|
if ((match[1] ?? '').length > maxLevel)
|
|
19
20
|
continue;
|
|
20
|
-
starts.push({
|
|
21
|
+
starts.push({
|
|
22
|
+
offset: match.index,
|
|
23
|
+
heading: match[2],
|
|
24
|
+
headingEnd: match.index + match[0].length,
|
|
25
|
+
});
|
|
21
26
|
}
|
|
22
27
|
// A document with no headings at all is a paragraph document; say so by
|
|
23
28
|
// doing the paragraph thing rather than returning one giant chunk.
|
|
24
29
|
if (starts.length === 0) {
|
|
25
30
|
const packed = packSpans(paragraphSpans(text), maxChars);
|
|
26
31
|
const cut = packed.flatMap((s) => s.end - s.start > maxChars ? hardCut(s, maxChars, overlapChars) : [s]);
|
|
27
|
-
|
|
32
|
+
const floored = mergeShortSpansForward(foldRunts(cut), minChars);
|
|
33
|
+
return toPieces(doc, applyOverlap(floored, overlapChars));
|
|
28
34
|
}
|
|
29
35
|
const sections = [];
|
|
30
|
-
// Preamble before the first heading — its own section, unnamed.
|
|
36
|
+
// Preamble before the first heading — its own section, unnamed. Its
|
|
37
|
+
// whole span IS its body.
|
|
31
38
|
const firstStart = starts[0]?.offset ?? 0;
|
|
32
39
|
if (firstStart > 0)
|
|
33
|
-
sections.push({ start: 0, end: firstStart });
|
|
40
|
+
sections.push({ start: 0, end: firstStart, bodyStart: 0 });
|
|
34
41
|
for (let i = 0; i < starts.length; i++) {
|
|
35
42
|
const start = starts[i]?.offset ?? 0;
|
|
36
43
|
const end = starts[i + 1]?.offset ?? text.length;
|
|
37
44
|
const heading = starts[i]?.heading;
|
|
38
|
-
|
|
45
|
+
const bodyStart = Math.min(end, starts[i]?.headingEnd ?? start);
|
|
46
|
+
sections.push({ start, end, bodyStart, ...(heading !== undefined && { heading }) });
|
|
39
47
|
}
|
|
40
48
|
// Sections that fit stay whole; the rest are packed by paragraph WITHIN
|
|
41
|
-
// the section, so a boundary never merges two headings' content.
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
// the section, so a boundary never merges two headings' content. Kept
|
|
50
|
+
// GROUPED per section here, because the floor pass below must reach the
|
|
51
|
+
// FIRST chunk of a section and only that one.
|
|
52
|
+
const groups = sections.map((section) => {
|
|
44
53
|
if (section.end - section.start <= maxChars) {
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
start: section.start,
|
|
57
|
+
end: section.end,
|
|
58
|
+
...(section.heading !== undefined && { heading: section.heading }),
|
|
59
|
+
},
|
|
60
|
+
];
|
|
47
61
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
// Paragraphs of the BODY, with the heading line glued onto the first
|
|
63
|
+
// one. Splitting the section's own text used to make the heading line
|
|
64
|
+
// its own paragraph unit — and when the first body paragraph was too
|
|
65
|
+
// big to pack with it, the heading shipped as a chunk of its own. That
|
|
66
|
+
// is the exact heading-only failure this release closes; the heading
|
|
67
|
+
// is a label, never a unit.
|
|
68
|
+
const inner = paragraphSpans(text.slice(section.bodyStart, section.end)).map((s) => ({
|
|
69
|
+
start: section.bodyStart + s.start,
|
|
70
|
+
end: section.bodyStart + s.end,
|
|
51
71
|
...(section.heading !== undefined && { heading: section.heading }),
|
|
52
72
|
}));
|
|
73
|
+
const firstInner = inner[0];
|
|
74
|
+
if (firstInner !== undefined && section.start < section.bodyStart) {
|
|
75
|
+
inner[0] = {
|
|
76
|
+
start: section.start,
|
|
77
|
+
end: firstInner.end,
|
|
78
|
+
...(section.heading !== undefined && { heading: section.heading }),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const spans = [];
|
|
53
82
|
for (const packedSpan of packSpans(inner, maxChars)) {
|
|
54
83
|
if (packedSpan.end - packedSpan.start > maxChars) {
|
|
55
84
|
spans.push(...hardCut(packedSpan, maxChars, overlapChars));
|
|
@@ -58,8 +87,97 @@ export function byHeading(options = {}) {
|
|
|
58
87
|
spans.push(packedSpan);
|
|
59
88
|
}
|
|
60
89
|
}
|
|
90
|
+
return spans;
|
|
91
|
+
});
|
|
92
|
+
// ── The floor pass (8.20.0). ─────────────────────────────────────────
|
|
93
|
+
// A short section is by construction a single span (its whole span is
|
|
94
|
+
// under the floor, which is under maxChars), so merging it forward means
|
|
95
|
+
// extending the FIRST span of the next full section back over it — the
|
|
96
|
+
// rest of that section's spans keep their own heading. Consecutive short
|
|
97
|
+
// sections accumulate; an accumulation that clears the floor and has a
|
|
98
|
+
// real body is emitted as its own chunk rather than diluting a full
|
|
99
|
+
// neighbour.
|
|
100
|
+
const out = [];
|
|
101
|
+
let pending;
|
|
102
|
+
for (let i = 0; i < sections.length; i++) {
|
|
103
|
+
// sections and groups are built index-for-index above.
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
105
|
+
const section = sections[i];
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
107
|
+
const group = groups[i];
|
|
108
|
+
const bodyLength = text.slice(section.bodyStart, section.end).trim().length;
|
|
109
|
+
const bare = bodyLength === 0; // heading-plus-whitespace: merged UNCONDITIONALLY
|
|
110
|
+
const short = !bare && bodyLength < minChars;
|
|
111
|
+
if (bare || short) {
|
|
112
|
+
if (pending === undefined) {
|
|
113
|
+
pending = {
|
|
114
|
+
start: section.start,
|
|
115
|
+
bodyChars: bodyLength,
|
|
116
|
+
...(section.heading !== undefined && { heading: section.heading }),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
pending.bodyChars += bodyLength;
|
|
121
|
+
}
|
|
122
|
+
// Adjacent shorts whose BODIES together clear the floor become their
|
|
123
|
+
// own chunk — the same measure shortness is judged by, so a single
|
|
124
|
+
// short section can never self-emit on the strength of its markup.
|
|
125
|
+
if (minChars > 0 && pending.bodyChars >= minChars) {
|
|
126
|
+
out.push({
|
|
127
|
+
start: pending.start,
|
|
128
|
+
end: section.end,
|
|
129
|
+
...(pending.heading !== undefined && { heading: pending.heading }),
|
|
130
|
+
});
|
|
131
|
+
pending = undefined;
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (pending !== undefined) {
|
|
136
|
+
const first = group[0];
|
|
137
|
+
if (first !== undefined) {
|
|
138
|
+
// The merged chunk STARTS at the short section's heading, so the
|
|
139
|
+
// short section's heading is the honest label. A heading-less
|
|
140
|
+
// preamble keeps the chunk heading-less: a chunk is never labelled
|
|
141
|
+
// with a heading its text only reaches later.
|
|
142
|
+
group[0] = {
|
|
143
|
+
start: pending.start,
|
|
144
|
+
end: first.end,
|
|
145
|
+
...(pending.heading !== undefined && { heading: pending.heading }),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
pending = undefined;
|
|
149
|
+
}
|
|
150
|
+
out.push(...group);
|
|
151
|
+
}
|
|
152
|
+
if (pending !== undefined) {
|
|
153
|
+
const lastSectionEnd = sections[sections.length - 1]?.end ?? text.length;
|
|
154
|
+
const previous = out.pop();
|
|
155
|
+
if (previous !== undefined) {
|
|
156
|
+
// Trailing shorts have no next chunk — the one edge that merges
|
|
157
|
+
// BACKWARD, extending the previous chunk under its own heading.
|
|
158
|
+
out.push({
|
|
159
|
+
start: previous.start,
|
|
160
|
+
end: lastSectionEnd,
|
|
161
|
+
...(previous.heading !== undefined && { heading: previous.heading }),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
else if (pending.bodyChars > 0) {
|
|
165
|
+
// The whole document is short sections. No neighbour exists, and
|
|
166
|
+
// "never dropped" wins: one merged chunk.
|
|
167
|
+
out.push({
|
|
168
|
+
start: pending.start,
|
|
169
|
+
end: lastSectionEnd,
|
|
170
|
+
...(pending.heading !== undefined && { heading: pending.heading }),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
// else: nothing but headings and whitespace — coordinates without a
|
|
174
|
+
// passage anywhere. No chunk is emitted; `indexDocuments` makes the
|
|
175
|
+
// same refusal one layer up for a passage-less document.
|
|
61
176
|
}
|
|
62
|
-
|
|
177
|
+
// Within-section tail runts still fold BACKWARD (same heading — the
|
|
178
|
+
// direction that cannot mislabel), now up to the same floor.
|
|
179
|
+
const runtFloor = minChars > 0 ? minChars : undefined;
|
|
180
|
+
return toPieces(doc, applyOverlap(foldRunts(out, runtFloor), overlapChars));
|
|
63
181
|
},
|
|
64
182
|
};
|
|
65
183
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byHeading.js","sourceRoot":"","sources":["../../../../src/rag/splitters/byHeading.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"byHeading.js","sourceRoot":"","sources":["../../../../src/rag/splitters/byHeading.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,SAAS,EACT,OAAO,EACP,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,GAET,MAAM,aAAa,CAAC;AA6BrB,sFAAsF;AACtF,MAAM,OAAO,GAAG,+BAA+B,CAAC;AAQhD,MAAM,UAAU,SAAS,CAAC,UAA4B,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,iBAAiB,CAAC;IACvD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,qBAAqB,CAAC;IACnE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,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AC,CAAC,EAAE,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC;gBACzE,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;gBAC3B,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;oBAC3B,gEAAgE;oBAChE,gEAAgE;oBAChE,GAAG,CAAC,IAAI,CAAC;wBACP,KAAK,EAAE,QAAQ,CAAC,KAAK;wBACrB,GAAG,EAAE,cAAc;wBACnB,GAAG,CAAC,QAAQ,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;qBACrE,CAAC,CAAC;gBACL,CAAC;qBAAM,IAAI,OAAO,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;oBACjC,iEAAiE;oBACjE,0CAA0C;oBAC1C,GAAG,CAAC,IAAI,CAAC;wBACP,KAAK,EAAE,OAAO,CAAC,KAAK;wBACpB,GAAG,EAAE,cAAc;wBACnB,GAAG,CAAC,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;qBACnE,CAAC,CAAC;gBACL,CAAC;gBACD,oEAAoE;gBACpE,oEAAoE;gBACpE,yDAAyD;YAC3D,CAAC;YAED,oEAAoE;YACpE,6DAA6D;YAC7D,MAAM,SAAS,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;YACtD,OAAO,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
*
|
|
14
14
|
* A single paragraph longer than `maxChars` is hard-cut — see the note in
|
|
15
15
|
* `shared.ts` on why packing and cutting are separate decisions.
|
|
16
|
+
*
|
|
17
|
+
* Packing already merges neighbours that FIT — but a short paragraph whose
|
|
18
|
+
* next neighbour is near `maxChars` cannot pack and used to ship alone, where
|
|
19
|
+
* its density outranks real passages (the same failure `byHeading` measured;
|
|
20
|
+
* see `DEFAULT_MIN_CHARS`). Since 8.20.0 a chunk under `minChars` merges
|
|
21
|
+
* FORWARD into the next chunk instead — never dropped, never alone.
|
|
16
22
|
*/
|
|
17
23
|
import type { Splitter } from '../types.js';
|
|
18
24
|
export interface ByParagraphOptions {
|
|
@@ -20,5 +26,13 @@ export interface ByParagraphOptions {
|
|
|
20
26
|
readonly maxChars?: number;
|
|
21
27
|
/** Backward overlap between adjacent chunks. Default 150. */
|
|
22
28
|
readonly overlapChars?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The floor under a chunk, in characters (8.20.0). A packed chunk that
|
|
31
|
+
* remains shorter — a stray short paragraph that could not pack with its
|
|
32
|
+
* full-sized neighbour — merges FORWARD into the next chunk rather than
|
|
33
|
+
* shipping alone. Default `min(250, maxChars / 4)`; `0` disables. See
|
|
34
|
+
* `DEFAULT_MIN_CHARS` for the measured failure behind the number.
|
|
35
|
+
*/
|
|
36
|
+
readonly minChars?: number;
|
|
23
37
|
}
|
|
24
38
|
export declare function byParagraph(options?: ByParagraphOptions): Splitter;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { DEFAULT_MAX_CHARS, DEFAULT_OVERLAP_CHARS } from './constants.js';
|
|
2
|
-
import { applyOverlap, foldRunts, hardCut, packSpans, paragraphSpans, toPieces } from './shared.js';
|
|
2
|
+
import { applyOverlap, foldRunts, hardCut, mergeShortSpansForward, packSpans, paragraphSpans, resolveMinChars, toPieces, } from './shared.js';
|
|
3
3
|
export function byParagraph(options = {}) {
|
|
4
4
|
const maxChars = options.maxChars ?? DEFAULT_MAX_CHARS;
|
|
5
5
|
const overlapChars = options.overlapChars ?? DEFAULT_OVERLAP_CHARS;
|
|
6
|
+
const minChars = resolveMinChars(options.minChars, maxChars);
|
|
6
7
|
return {
|
|
7
8
|
name: 'byParagraph',
|
|
8
9
|
split(doc) {
|
|
9
10
|
const paragraphs = paragraphSpans(doc.text);
|
|
10
11
|
const packed = packSpans(paragraphs, maxChars);
|
|
11
12
|
const cut = packed.flatMap((span) => span.end - span.start > maxChars ? hardCut(span, maxChars, overlapChars) : [span]);
|
|
12
|
-
|
|
13
|
+
const floored = mergeShortSpansForward(foldRunts(cut), minChars);
|
|
14
|
+
return toPieces(doc, applyOverlap(floored, overlapChars));
|
|
13
15
|
},
|
|
14
16
|
};
|
|
15
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byParagraph.js","sourceRoot":"","sources":["../../../../src/rag/splitters/byParagraph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"byParagraph.js","sourceRoot":"","sources":["../../../../src/rag/splitters/byParagraph.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,SAAS,EACT,OAAO,EACP,sBAAsB,EACtB,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,GACT,MAAM,aAAa,CAAC;AAiBrB,MAAM,UAAU,WAAW,CAAC,UAA8B,EAAE;IAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,iBAAiB,CAAC;IACvD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,qBAAqB,CAAC;IACnE,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE7D,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,KAAK,CAAC,GAAmB;YACvB,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5C,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAClC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAClF,CAAC;YACF,MAAM,OAAO,GAAG,sBAAsB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;YACjE,OAAO,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;QAC5D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The numbers every splitter defaults to, in one place so they cannot
|
|
3
3
|
* drift apart between strategies.
|
|
4
4
|
*
|
|
5
5
|
* See `splitters/index.ts` for the measurement they come from: `localEmbedder`
|
|
@@ -17,3 +17,26 @@ export declare const DEFAULT_OVERLAP_CHARS = 150;
|
|
|
17
17
|
* passage.
|
|
18
18
|
*/
|
|
19
19
|
export declare const MIN_CHUNK_CHARS = 50;
|
|
20
|
+
/**
|
|
21
|
+
* The default `minChars` floor for the structural splitters (`byHeading`,
|
|
22
|
+
* `byParagraph`), at the default `maxChars`. A section or paragraph whose own
|
|
23
|
+
* text is under the floor is merged FORWARD into the next chunk rather than
|
|
24
|
+
* shipped alone (8.20.0).
|
|
25
|
+
*
|
|
26
|
+
* Why a floor at all, and why this number: short chunks do not merely retrieve
|
|
27
|
+
* badly — they retrieve TOO WELL. Similarity is a density measure, and a
|
|
28
|
+
* heading plus one preamble sentence concentrates its topic's vocabulary with
|
|
29
|
+
* none of its substance. Measured in a production corpus: a 180-character
|
|
30
|
+
* heading-and-preamble chunk outscored the 1,032-character body of its own
|
|
31
|
+
* section, 0.430 against lower — so the model was handed a passage that
|
|
32
|
+
* PROMISES findings, contains none, and fabricated a plausible file path to
|
|
33
|
+
* fill the gap. 250 characters (~60 tokens) sits comfortably above that
|
|
34
|
+
* measured failure, is a quarter of the default target, and keeps a
|
|
35
|
+
* floor-merged chunk (short section + a full neighbour ≤ ~1,250 chars ≈ 310
|
|
36
|
+
* tokens) far inside the 512-wordpiece-token embedder cliff.
|
|
37
|
+
*
|
|
38
|
+
* The effective default scales with the caller's own target: it is
|
|
39
|
+
* `min(250, maxChars / 4)`, so `byHeading({ maxChars: 400 })` gets a 100-char
|
|
40
|
+
* floor rather than one bigger than half its chunks.
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_MIN_CHARS = 250;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The numbers every splitter defaults to, in one place so they cannot
|
|
3
3
|
* drift apart between strategies.
|
|
4
4
|
*
|
|
5
5
|
* See `splitters/index.ts` for the measurement they come from: `localEmbedder`
|
|
@@ -17,4 +17,27 @@ export const DEFAULT_OVERLAP_CHARS = 150;
|
|
|
17
17
|
* passage.
|
|
18
18
|
*/
|
|
19
19
|
export const MIN_CHUNK_CHARS = 50;
|
|
20
|
+
/**
|
|
21
|
+
* The default `minChars` floor for the structural splitters (`byHeading`,
|
|
22
|
+
* `byParagraph`), at the default `maxChars`. A section or paragraph whose own
|
|
23
|
+
* text is under the floor is merged FORWARD into the next chunk rather than
|
|
24
|
+
* shipped alone (8.20.0).
|
|
25
|
+
*
|
|
26
|
+
* Why a floor at all, and why this number: short chunks do not merely retrieve
|
|
27
|
+
* badly — they retrieve TOO WELL. Similarity is a density measure, and a
|
|
28
|
+
* heading plus one preamble sentence concentrates its topic's vocabulary with
|
|
29
|
+
* none of its substance. Measured in a production corpus: a 180-character
|
|
30
|
+
* heading-and-preamble chunk outscored the 1,032-character body of its own
|
|
31
|
+
* section, 0.430 against lower — so the model was handed a passage that
|
|
32
|
+
* PROMISES findings, contains none, and fabricated a plausible file path to
|
|
33
|
+
* fill the gap. 250 characters (~60 tokens) sits comfortably above that
|
|
34
|
+
* measured failure, is a quarter of the default target, and keeps a
|
|
35
|
+
* floor-merged chunk (short section + a full neighbour ≤ ~1,250 chars ≈ 310
|
|
36
|
+
* tokens) far inside the 512-wordpiece-token embedder cliff.
|
|
37
|
+
*
|
|
38
|
+
* The effective default scales with the caller's own target: it is
|
|
39
|
+
* `min(250, maxChars / 4)`, so `byHeading({ maxChars: 400 })` gets a 100-char
|
|
40
|
+
* floor rather than one bigger than half its chunks.
|
|
41
|
+
*/
|
|
42
|
+
export const DEFAULT_MIN_CHARS = 250;
|
|
20
43
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/rag/splitters/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/rag/splitters/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC"}
|