@devilsdev/rag-pipeline-utils 2.4.5 → 2.6.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/.ragrc.schema.json +83 -192
- package/CHANGELOG.md +431 -0
- package/README.md +418 -117
- package/SECURITY.md +5 -5
- package/dist/experimental.cjs +2 -0
- package/dist/experimental.d.ts +1 -0
- package/dist/experimental.mjs +5 -0
- package/dist/index.cjs +6442 -1355
- package/dist/index.d.ts +129 -2
- package/dist/index.mjs +1 -1
- package/dist/testing.cjs +2 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.mjs +5 -0
- package/dist/types/adapters/ai-sdk.d.ts +53 -0
- package/dist/types/agentic/agentic-pipeline.d.ts +103 -0
- package/dist/types/agentic/iterative-retriever.d.ts +85 -0
- package/dist/types/agentic/query-planner.d.ts +145 -0
- package/dist/types/agentic/self-critique.d.ts +45 -0
- package/dist/types/ai/adaptive-retrieval.d.ts +44 -0
- package/dist/types/ai/federation/federated-learning-coordinator.d.ts +62 -0
- package/dist/types/ai/multimodal-processing.d.ts +32 -0
- package/dist/types/ai/multimodal.d.ts +39 -0
- package/dist/types/ai/retrieval-engine.d.ts +37 -0
- package/dist/types/ai/training/model-training-orchestrator.d.ts +31 -0
- package/dist/types/cache/component-keys.d.ts +7 -0
- package/dist/types/cache/memory-cache.d.ts +54 -0
- package/dist/types/cache/pipeline-cache.d.ts +66 -0
- package/dist/types/cache/redis-cache.d.ts +46 -0
- package/dist/types/chunking/chunking-engine.d.ts +70 -0
- package/dist/types/chunking/strategies/fixed-size.d.ts +17 -0
- package/dist/types/chunking/strategies/recursive.d.ts +20 -0
- package/dist/types/chunking/strategies/semantic.d.ts +19 -0
- package/dist/types/chunking/strategies/sentence.d.ts +13 -0
- package/dist/types/chunking/strategies/structure-aware.d.ts +19 -0
- package/dist/types/citation/citation-tracker.d.ts +64 -0
- package/dist/types/citation/hallucination-detector.d.ts +40 -0
- package/dist/types/citation/source-mapper.d.ts +37 -0
- package/dist/types/connectors/anthropic-connector.d.ts +97 -0
- package/dist/types/connectors/base-connector.d.ts +87 -0
- package/dist/types/connectors/cohere-connector.d.ts +94 -0
- package/dist/types/connectors/connector-utils.d.ts +110 -0
- package/dist/types/connectors/local-embedder.d.ts +95 -0
- package/dist/types/connectors/memory-retriever.d.ts +99 -0
- package/dist/types/connectors/ollama-connector.d.ts +115 -0
- package/dist/types/connectors/openai-connector.d.ts +129 -0
- package/dist/types/connectors/rag-prompt.d.ts +40 -0
- package/dist/types/core/create-pipeline.d.ts +8 -0
- package/dist/types/core/plugin-registry.d.ts +136 -0
- package/dist/types/core/stage-contracts.d.ts +36 -0
- package/dist/types/core/validate-plugin.d.ts +45 -0
- package/dist/types/cost/cost-calculator.d.ts +152 -0
- package/dist/types/cost/cost-tracker.d.ts +126 -0
- package/dist/types/cost/token-budget.d.ts +110 -0
- package/dist/types/dag/core/error-context.d.ts +239 -0
- package/dist/types/dag/core/execution-scheduler.d.ts +191 -0
- package/dist/types/dag/core/topology-validation.d.ts +226 -0
- package/dist/types/dag/dag-engine.d.ts +156 -0
- package/dist/types/dag/dag-node.d.ts +37 -0
- package/dist/types/dashboard/dashboard-generator.d.ts +127 -0
- package/dist/types/dashboard/metrics-aggregator.d.ts +218 -0
- package/dist/types/debug/execution-tracer.d.ts +57 -0
- package/dist/types/debug/trace-inspector.d.ts +31 -0
- package/dist/types/ecosystem/plugin-certification.d.ts +169 -0
- package/dist/types/enterprise/data-governance.d.ts +203 -0
- package/dist/types/enterprise/multi-tenancy.d.ts +137 -0
- package/dist/types/enterprise/sso-integration.d.ts +420 -0
- package/dist/types/evaluate/context-metrics.d.ts +55 -0
- package/dist/types/evaluate/faithfulness.d.ts +41 -0
- package/dist/types/evaluate/groundedness.d.ts +60 -0
- package/dist/types/evaluate/pipeline-evaluator.d.ts +88 -0
- package/dist/types/evaluate/relevance.d.ts +21 -0
- package/dist/types/evaluate/scoring.d.ts +123 -0
- package/dist/types/evaluate/semantic-similarity.d.ts +14 -0
- package/dist/types/experimental.d.ts +15 -0
- package/dist/types/graph/entity-extractor.d.ts +84 -0
- package/dist/types/graph/graph-index.d.ts +49 -0
- package/dist/types/graph/graph-retriever.d.ts +81 -0
- package/dist/types/graph/knowledge-graph.d.ts +129 -0
- package/dist/types/grounding/check-answer.d.ts +101 -0
- package/dist/types/guardrails/guardrails-pipeline.d.ts +63 -0
- package/dist/types/guardrails/injection-detector.d.ts +47 -0
- package/dist/types/guardrails/post-generation-guard.d.ts +61 -0
- package/dist/types/guardrails/pre-retrieval-guard.d.ts +64 -0
- package/dist/types/guardrails/retrieval-guard.d.ts +57 -0
- package/dist/types/mcp/mcp-server.d.ts +85 -0
- package/dist/types/mcp/mcp-tool-builder.d.ts +55 -0
- package/dist/types/reranker/cascade-reranker.d.ts +40 -0
- package/dist/types/reranker/embedding-reranker.d.ts +77 -0
- package/dist/types/reranker/scoring-reranker.d.ts +41 -0
- package/dist/types/retrieval/bm25-search.d.ts +43 -0
- package/dist/types/retrieval/file-vector-store.d.ts +99 -0
- package/dist/types/retrieval/hybrid-retriever.d.ts +35 -0
- package/dist/types/retrieval/rank-fusion.d.ts +10 -0
- package/dist/types/security/jwt-config.d.ts +80 -0
- package/dist/types/security/jwt-validator.d.ts +195 -0
- package/dist/types/security/plugin-sandbox.d.ts +158 -0
- package/dist/types/security/plugin-signature-verifier.d.ts +139 -0
- package/dist/types/security/validator.d.ts +5 -0
- package/dist/types/streaming/embedding-stream.d.ts +65 -0
- package/dist/types/streaming/sse-adapter.d.ts +59 -0
- package/dist/types/streaming/stream-router.d.ts +88 -0
- package/dist/types/streaming/streaming-embedder.d.ts +99 -0
- package/dist/types/streaming/websocket-adapter.d.ts +71 -0
- package/dist/types/templates/scaffold.d.ts +55 -0
- package/dist/types/templates/template-registry.d.ts +63 -0
- package/dist/types/testing.d.ts +168 -0
- package/dist/types/utils/embed-query.d.ts +20 -0
- package/dist/types/utils/logger.d.ts +50 -0
- package/dist/types/utils/rate-limiter.d.ts +66 -0
- package/dist/types/utils/retry.d.ts +27 -0
- package/dist/types/utils/run-abort.d.ts +34 -0
- package/dist/types/utils/secure-logging.d.ts +51 -0
- package/dist/types/utils/structured-logger.d.ts +126 -0
- package/package.json +72 -33
- package/src/adapters/ai-sdk.js +215 -0
- package/src/agentic/agentic-pipeline.js +75 -7
- package/src/agentic/iterative-retriever.js +47 -10
- package/src/agentic/query-planner.js +329 -78
- package/src/cache/component-keys.js +38 -0
- package/src/cache/memory-cache.js +87 -0
- package/src/cache/pipeline-cache.js +260 -0
- package/src/cache/redis-cache.js +83 -0
- package/src/citation/citation-tracker.js +6 -4
- package/src/citation/hallucination-detector.js +2 -2
- package/src/citation/source-mapper.js +15 -28
- package/src/cli/commands/ai.js +106 -0
- package/src/cli/commands/plugin-hub/event-handlers.js +6 -0
- package/src/cli/commands/plugin-hub/hub-commands.js +0 -74
- package/src/cli/commands/plugin-hub/local-commands.js +143 -0
- package/src/cli/commands/plugin-hub.js +114 -49
- package/src/cli/diagnostics/config-checker.js +76 -63
- package/src/cli/diagnostics/environment-checker.js +62 -31
- package/src/cli/diagnostics/plugin-checker.js +36 -89
- package/src/cli/doctor-command.js +39 -5
- package/src/cli/enhanced-cli-commands.js +104 -233
- package/src/cli/handlers/ai-handler.js +364 -0
- package/src/cli/handlers/diagnostics-handler.js +78 -31
- package/src/cli/handlers/ingest-handler.js +28 -22
- package/src/cli/handlers/init-handler.js +148 -25
- package/src/cli/handlers/query-handler.js +203 -25
- package/src/cli/handlers/run-handler.js +16 -167
- package/src/cli/handlers/serve-handler.js +60 -0
- package/src/cli/services/bench-stats.js +54 -0
- package/src/cli/services/benchmark.js +161 -0
- package/src/cli/services/feedback.js +155 -0
- package/src/cli/services/instrument.js +83 -0
- package/src/cli/services/rag-service.js +361 -0
- package/src/cli/shared/cli-utils.js +24 -7
- package/src/cli/shared/config-context.js +21 -0
- package/src/cli/wizard/config-builder.js +81 -0
- package/src/cli/wizard/init-wizard.js +602 -0
- package/src/config/component-factory.js +125 -0
- package/src/config/enhanced-ragrc-schema.js +0 -2
- package/src/config/load-config.js +29 -10
- package/src/config/load-plugin-config.js +46 -2
- package/src/config/validate-schema.js +4 -1
- package/src/connectors/anthropic-connector.js +115 -57
- package/src/connectors/base-connector.js +74 -19
- package/src/connectors/cohere-connector.js +108 -34
- package/src/connectors/connector-utils.js +302 -0
- package/src/connectors/local-embedder.js +63 -5
- package/src/connectors/memory-retriever.js +125 -14
- package/src/connectors/ollama-connector.js +112 -51
- package/src/connectors/openai-connector.js +153 -44
- package/src/connectors/rag-prompt.js +88 -0
- package/src/core/create-pipeline.js +307 -61
- package/src/core/performance/parallel-processor.js +62 -1
- package/src/core/plugin-registry.js +125 -26
- package/src/core/stage-contracts.js +36 -0
- package/src/core/validate-plugin.js +85 -0
- package/src/cost/cost-calculator.js +205 -32
- package/src/debug/execution-tracer.js +14 -4
- package/src/dev/dev-server.js +173 -11
- package/src/dev/hot-reload.js +44 -4
- package/src/ecosystem/plugin-checks.js +181 -0
- package/src/ecosystem/plugin-hub.js +50 -125
- package/src/ecosystem/plugin-installer.js +298 -0
- package/src/ecosystem/plugin-probe.js +127 -0
- package/src/ecosystem/plugin-scanner.js +185 -0
- package/src/ecosystem/tar-extract.js +114 -0
- package/src/enterprise/audit-logging.js +158 -29
- package/src/enterprise/sso-integration.js +716 -228
- package/src/evaluate/context-metrics.js +28 -16
- package/src/evaluate/evaluator.js +3 -3
- package/src/evaluate/faithfulness.js +18 -14
- package/src/evaluate/groundedness.js +43 -12
- package/src/evaluate/pipeline-evaluator.js +35 -8
- package/src/evaluate/scoring.js +251 -3
- package/src/evaluate/semantic-similarity.js +79 -0
- package/src/experimental.js +71 -0
- package/src/grounding/check-answer.js +173 -0
- package/src/guardrails/guardrails-pipeline.js +69 -7
- package/src/guardrails/injection-detector.js +283 -0
- package/src/guardrails/post-generation-guard.js +19 -0
- package/src/guardrails/pre-retrieval-guard.js +36 -36
- package/src/guardrails/retrieval-guard.js +58 -8
- package/src/index.js +58 -1
- package/src/loader/csv-loader.js +3 -2
- package/src/loader/document-reader.js +91 -0
- package/src/loader/html-loader.js +3 -1
- package/src/loader/markdown-loader.js +3 -2
- package/src/reranker/cascade-reranker.js +3 -0
- package/src/reranker/embedding-reranker.js +136 -21
- package/src/reranker/llm-reranker.js +79 -12
- package/src/reranker/scoring-reranker.js +3 -0
- package/src/retrieval/bm25-search.js +12 -6
- package/src/retrieval/file-vector-store.js +241 -0
- package/src/retrieval/hybrid-retriever.js +22 -19
- package/src/security/jwt-config.js +13 -2
- package/src/security/jwt-validator.js +139 -34
- package/src/security/plugin-sandbox.js +18 -1
- package/src/security/plugin-signature-verifier.js +245 -70
- package/src/testing.js +254 -0
- package/src/utils/deprecate.js +69 -0
- package/src/utils/embed-query.js +33 -0
- package/src/utils/input-sanitizer.js +19 -4
- package/src/utils/logger.js +34 -4
- package/src/utils/run-abort.js +102 -0
- package/src/ai/federated-learning.js +0 -211
- package/src/ai/federation.js +0 -71
- package/src/ai/index.js +0 -22
- package/src/ai/model-trainer.js +0 -217
- package/src/ai/model-training.js +0 -202
- package/src/ai/multimodal/multi-modal-processor.js +0 -345
- package/src/ai/orchestrator.js +0 -65
- package/src/ai/retrieval/adaptive-retrieval-engine.js +0 -398
- package/src/cli/commands/ai-ml/adaptive-commands.js +0 -178
- package/src/cli/commands/ai-ml/federated-commands.js +0 -207
- package/src/cli/commands/ai-ml/index.js +0 -17
- package/src/cli/commands/ai-ml/multimodal-commands.js +0 -187
- package/src/cli/commands/ai-ml/shared.js +0 -51
- package/src/cli/commands/ai-ml/training-commands.js +0 -228
- package/src/cli/commands/ai-ml.js +0 -386
- package/src/cli/commands/docs.js +0 -228
- package/src/cli/commands/dx.js +0 -538
- package/src/cli/commands/wizard.js +0 -627
- package/src/cli/input-sanitization-middleware.js +0 -356
- package/src/cli/interactive-wizard.js +0 -373
- package/src/cli/templates/development.template.json +0 -64
- package/src/cli/templates/minimal.template.json +0 -33
- package/src/cli/templates/production.template.json +0 -104
- package/src/cli/templates/testing.template.json +0 -45
- package/src/cli/wizard/configuration.js +0 -148
- package/src/cli/wizard/observability.js +0 -79
- package/src/cli/wizard/performance.js +0 -76
- package/src/cli/wizard/plugin-selection.js +0 -297
- package/src/cli/wizard/preview-save.js +0 -172
- package/src/cli/wizard/project-setup.js +0 -66
- package/src/core/pipeline-factory.js +0 -59
- package/src/dag/enhanced-dag-engine.js +0 -894
- package/src/dx/index.js +0 -40
- package/src/dx/integration-templates.js +0 -662
- package/src/dx/performance-profiler.js +0 -968
- package/src/dx/realtime-debugger.js +0 -755
- package/src/dx/visual-pipeline-builder.js +0 -578
- package/src/ingest.js +0 -59
- package/src/pipeline/pipeline.js +0 -18
- package/src/query.js +0 -117
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Answer verification against retrieved source documents.
|
|
3
|
+
* Uses CitationTracker (lazy-loaded) to compute groundedness and detect hallucinations.
|
|
4
|
+
*
|
|
5
|
+
* @extends EventEmitter
|
|
6
|
+
*/
|
|
7
|
+
export class SelfCritiqueChecker extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} [options] - Override default configuration
|
|
10
|
+
* @param {number} [options.approvalThreshold=0.5] - Minimum groundedness score to approve an answer
|
|
11
|
+
*/
|
|
12
|
+
constructor(options?: {
|
|
13
|
+
approvalThreshold?: number;
|
|
14
|
+
});
|
|
15
|
+
config: any;
|
|
16
|
+
/**
|
|
17
|
+
* Check an answer against retrieved documents for groundedness.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} answer - The LLM-generated answer to verify
|
|
20
|
+
* @param {Array<object>} retrievedDocs - Source documents to check against
|
|
21
|
+
* @returns {{
|
|
22
|
+
* approved: boolean,
|
|
23
|
+
* score: number,
|
|
24
|
+
* issues: Array<{sentence: string, classification: string}>,
|
|
25
|
+
* citationResult: object
|
|
26
|
+
* }}
|
|
27
|
+
* @throws {Error} If answer or retrievedDocs are invalid
|
|
28
|
+
* @fires SelfCritiqueChecker#checked
|
|
29
|
+
*/
|
|
30
|
+
check(answer: string, retrievedDocs: Array<object>): {
|
|
31
|
+
approved: boolean;
|
|
32
|
+
score: number;
|
|
33
|
+
issues: Array<{
|
|
34
|
+
sentence: string;
|
|
35
|
+
classification: string;
|
|
36
|
+
}>;
|
|
37
|
+
citationResult: object;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Default configuration for the SelfCritiqueChecker.
|
|
42
|
+
* @type {object}
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_CONFIG: object;
|
|
45
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize or update user profile
|
|
3
|
+
* @param {string} userId - User identifier
|
|
4
|
+
* @param {object} profile - Profile data
|
|
5
|
+
* @returns {Promise<object>} Created/updated profile
|
|
6
|
+
*/
|
|
7
|
+
export function initializeUserProfile(userId: string, profile?: object): Promise<object>;
|
|
8
|
+
/**
|
|
9
|
+
* Record feedback for a query/item pair
|
|
10
|
+
* @param {string} userId - User identifier
|
|
11
|
+
* @param {object} feedback - Feedback object with query, results, ratings, etc.
|
|
12
|
+
* @returns {Promise<void>}
|
|
13
|
+
*/
|
|
14
|
+
export function recordFeedback(userId: string, feedback: object): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Perform adaptive retrieval with deterministic scoring
|
|
17
|
+
* @param {string} userId - User identifier
|
|
18
|
+
* @param {string} query - Search query
|
|
19
|
+
* @param {object} options - Retrieval options
|
|
20
|
+
* @returns {Promise<object>} Object with documents array and adaptationMetadata
|
|
21
|
+
*/
|
|
22
|
+
export function adaptiveRetrieve(userId: string, query: string, options?: object): Promise<object>;
|
|
23
|
+
/**
|
|
24
|
+
* Get user profile
|
|
25
|
+
* @param {string} userId - User identifier
|
|
26
|
+
* @returns {Promise<object|null>} User profile or null if not found
|
|
27
|
+
*/
|
|
28
|
+
export function getUserProfile(userId: string): Promise<object | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Personalize ranking for a set of documents
|
|
31
|
+
* @param {string} userId - User ID
|
|
32
|
+
* @param {array} documents - Array of documents to personalize
|
|
33
|
+
* @returns {array} Documents with personalized scores and ranking factors
|
|
34
|
+
*/
|
|
35
|
+
export function personalizeRanking(userId: string, documents: any[]): any[];
|
|
36
|
+
/**
|
|
37
|
+
* Get statistics about users and feedback
|
|
38
|
+
* @returns {object} Stats object with users and interactions
|
|
39
|
+
*/
|
|
40
|
+
export function getStats(): object;
|
|
41
|
+
/**
|
|
42
|
+
* Clear all stored data
|
|
43
|
+
*/
|
|
44
|
+
export function clear(): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export class FederatedLearningCoordinator extends EventEmitter<[never]> {
|
|
2
|
+
constructor(options?: {});
|
|
3
|
+
config: {
|
|
4
|
+
minParticipants: any;
|
|
5
|
+
maxParticipants: any;
|
|
6
|
+
roundDuration: any;
|
|
7
|
+
convergenceThreshold: any;
|
|
8
|
+
maxRounds: any;
|
|
9
|
+
};
|
|
10
|
+
federations: Map<any, any>;
|
|
11
|
+
participants: Map<any, any>;
|
|
12
|
+
globalModels: Map<any, any>;
|
|
13
|
+
createFederation(tenantId: any, modelConfig: any, federationConfig?: {}): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
14
|
+
registerParticipant(federationId: any, participantInfo: any): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
15
|
+
startFederatedTraining(federationId: any): Promise<{
|
|
16
|
+
federationId: any;
|
|
17
|
+
status: any;
|
|
18
|
+
rounds: any;
|
|
19
|
+
participants: any;
|
|
20
|
+
}>;
|
|
21
|
+
getFederationStatus(federationId: any): Promise<{
|
|
22
|
+
id: any;
|
|
23
|
+
status: any;
|
|
24
|
+
currentRound: any;
|
|
25
|
+
participantCount: any;
|
|
26
|
+
convergenceHistory: any;
|
|
27
|
+
createdAt: any;
|
|
28
|
+
startedAt: any;
|
|
29
|
+
completedAt: any;
|
|
30
|
+
}>;
|
|
31
|
+
getParticipantStatus(participantId: any): Promise<any>;
|
|
32
|
+
updateParticipantModel(participantId: any, modelUpdate: any): Promise<{
|
|
33
|
+
participantId: any;
|
|
34
|
+
updateAccepted: boolean;
|
|
35
|
+
newPerformance: any;
|
|
36
|
+
}>;
|
|
37
|
+
aggregateModels(federationId: any, participantUpdates: any): Promise<{
|
|
38
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
39
|
+
federationId: any;
|
|
40
|
+
round: any;
|
|
41
|
+
participantCount: any;
|
|
42
|
+
aggregationMethod: string;
|
|
43
|
+
weights: number[];
|
|
44
|
+
performance: {
|
|
45
|
+
accuracy: number;
|
|
46
|
+
loss: number;
|
|
47
|
+
convergence: number;
|
|
48
|
+
};
|
|
49
|
+
createdAt: number;
|
|
50
|
+
}>;
|
|
51
|
+
_executeTrainingRound(federation: any, roundNumber: any): Promise<{
|
|
52
|
+
round: any;
|
|
53
|
+
accuracy: number;
|
|
54
|
+
loss: number;
|
|
55
|
+
convergence: number;
|
|
56
|
+
participantCount: any;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}>;
|
|
59
|
+
getGlobalModel(federationId: any): Promise<any>;
|
|
60
|
+
removeParticipant(participantId: any): Promise<boolean>;
|
|
61
|
+
}
|
|
62
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process multimodal content and store with embedding
|
|
3
|
+
* @param {string} tenantId - Tenant identifier
|
|
4
|
+
* @param {object} content - Content object with type and data
|
|
5
|
+
* @returns {Promise<object>} Processed content record with ID, modalities, metadata
|
|
6
|
+
*/
|
|
7
|
+
export function processContent(tenantId: string, content: object): Promise<object>;
|
|
8
|
+
/**
|
|
9
|
+
* Generate description for content by ID
|
|
10
|
+
* @param {string} contentId - Content ID
|
|
11
|
+
* @returns {Promise<object>} Object with modality-specific descriptions and unified description
|
|
12
|
+
*/
|
|
13
|
+
export function describeContent(contentId: string): Promise<object>;
|
|
14
|
+
/**
|
|
15
|
+
* Search multimodal content using query object
|
|
16
|
+
* @param {string} tenantId - Tenant identifier
|
|
17
|
+
* @param {object} queryObj - Query object
|
|
18
|
+
* @param {object} options - Search options
|
|
19
|
+
* @returns {Promise<object>} Object with results array and metadata
|
|
20
|
+
*/
|
|
21
|
+
export function search(tenantId: string, queryObj: object, options?: object): Promise<object>;
|
|
22
|
+
/**
|
|
23
|
+
* Find similar content to given ID
|
|
24
|
+
* @param {string} contentId - Source content ID
|
|
25
|
+
* @param {object} options - Options with threshold
|
|
26
|
+
* @returns {Promise<Array>} Array of similar items with id and score
|
|
27
|
+
*/
|
|
28
|
+
export function findSimilar(contentId: string, options?: object): Promise<any[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Clear all stored content (for testing)
|
|
31
|
+
*/
|
|
32
|
+
export function clear(): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MultiModalProcessor class
|
|
3
|
+
* Processes and integrates multiple content modalities
|
|
4
|
+
*/
|
|
5
|
+
export class MultiModalProcessor {
|
|
6
|
+
supportedTypes: Set<string>;
|
|
7
|
+
processors: Map<any, any>;
|
|
8
|
+
embeddings: Map<any, any>;
|
|
9
|
+
/**
|
|
10
|
+
* Process multimodal content
|
|
11
|
+
* @param {string} tenantId - Tenant identifier
|
|
12
|
+
* @param {Array} content - Array of content objects with type and data
|
|
13
|
+
* @param {object} options - Processing options
|
|
14
|
+
* @returns {Promise<object>} Processing results
|
|
15
|
+
*/
|
|
16
|
+
processContent(tenantId: string, content: any[], options?: object): Promise<object>;
|
|
17
|
+
/**
|
|
18
|
+
* Generate embeddings for multimodal content
|
|
19
|
+
* @param {string} tenantId - Tenant identifier
|
|
20
|
+
* @param {object} content - Content to embed
|
|
21
|
+
* @returns {Promise<Array>} Generated embeddings
|
|
22
|
+
*/
|
|
23
|
+
generateEmbeddings(tenantId: string, content: object): Promise<any[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Align embeddings across modalities
|
|
26
|
+
* @param {string} tenantId - Tenant identifier
|
|
27
|
+
* @param {Array} embeddings - Multi-modal embeddings
|
|
28
|
+
* @returns {Promise<Array>} Aligned embeddings
|
|
29
|
+
*/
|
|
30
|
+
alignEmbeddings(tenantId: string, embeddings: any[]): Promise<any[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Perform cross-modal search
|
|
33
|
+
* @param {string} tenantId - Tenant identifier
|
|
34
|
+
* @param {object} query - Query object with modality
|
|
35
|
+
* @param {object} options - Search options
|
|
36
|
+
* @returns {Promise<Array>} Search results
|
|
37
|
+
*/
|
|
38
|
+
crossModalSearch(tenantId: string, query: object, options?: object): Promise<any[]>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdaptiveRetrievalEngine class
|
|
3
|
+
* Manages intelligent document retrieval with performance optimization
|
|
4
|
+
*/
|
|
5
|
+
export class AdaptiveRetrievalEngine {
|
|
6
|
+
algorithms: Map<any, any>;
|
|
7
|
+
performanceMetrics: Map<any, any>;
|
|
8
|
+
adaptationThreshold: number;
|
|
9
|
+
/**
|
|
10
|
+
* Process retrieval query with adaptive algorithms
|
|
11
|
+
* @param {string} tenantId - Tenant identifier
|
|
12
|
+
* @param {string} query - Search query
|
|
13
|
+
* @param {object} options - Retrieval options
|
|
14
|
+
* @returns {Promise<object>} Retrieval results
|
|
15
|
+
*/
|
|
16
|
+
retrieveDocuments(tenantId: string, query: string, options?: object): Promise<object>;
|
|
17
|
+
/**
|
|
18
|
+
* Optimize retrieval algorithm based on performance data
|
|
19
|
+
* @param {string} tenantId - Tenant identifier
|
|
20
|
+
* @param {object} performanceData - Performance metrics
|
|
21
|
+
* @returns {Promise<object>} Optimization results
|
|
22
|
+
*/
|
|
23
|
+
optimizeRetrieval(tenantId: string, performanceData: object): Promise<object>;
|
|
24
|
+
/**
|
|
25
|
+
* Get current algorithm configuration
|
|
26
|
+
* @param {string} tenantId - Tenant identifier
|
|
27
|
+
* @returns {Promise<object>} Current algorithm configuration
|
|
28
|
+
*/
|
|
29
|
+
getAlgorithmConfig(tenantId: string): Promise<object>;
|
|
30
|
+
/**
|
|
31
|
+
* Update retrieval strategy
|
|
32
|
+
* @param {string} tenantId - Tenant identifier
|
|
33
|
+
* @param {string} strategy - New retrieval strategy
|
|
34
|
+
* @returns {Promise<boolean>} Success status
|
|
35
|
+
*/
|
|
36
|
+
updateStrategy(tenantId: string, strategy: string): Promise<boolean>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class ModelTrainingOrchestrator extends EventEmitter<[never]> {
|
|
2
|
+
constructor(options?: {});
|
|
3
|
+
config: {
|
|
4
|
+
batchSize: any;
|
|
5
|
+
learningRate: any;
|
|
6
|
+
epochs: any;
|
|
7
|
+
};
|
|
8
|
+
trainingJobs: Map<any, any>;
|
|
9
|
+
deployments: Map<any, any>;
|
|
10
|
+
optimizations: Map<any, any>;
|
|
11
|
+
createTrainingJob(tenantId: any, config?: {}): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
12
|
+
startTraining(jobId: any, data?: any, config?: {}): Promise<{
|
|
13
|
+
jobId: any;
|
|
14
|
+
status: string;
|
|
15
|
+
}>;
|
|
16
|
+
getTrainingStatus(jobId: any): any;
|
|
17
|
+
stopTraining(jobId: any): Promise<boolean>;
|
|
18
|
+
deployModel(jobId: any, deploymentConfig?: {}): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
19
|
+
getDeploymentStatus(deploymentId: any): Promise<any>;
|
|
20
|
+
optimizeHyperparameters(tenantId: any, optimizationConfig: any): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
21
|
+
getOptimizationResults(optimizationId: any): Promise<{
|
|
22
|
+
id: any;
|
|
23
|
+
status: any;
|
|
24
|
+
bestConfiguration: any;
|
|
25
|
+
bestScore: any;
|
|
26
|
+
trials: any;
|
|
27
|
+
startedAt: any;
|
|
28
|
+
completedAt: any;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process cache with least-recently-used eviction and per-entry time to
|
|
3
|
+
* live. Implements the CacheBackend contract:
|
|
4
|
+
*
|
|
5
|
+
* get(key) -> Promise<value | undefined>
|
|
6
|
+
* set(key, value, { ttlSeconds }) -> Promise<void>
|
|
7
|
+
* delete(key) -> Promise<void>
|
|
8
|
+
* stats() -> Promise<{ hits, misses, size }>
|
|
9
|
+
*
|
|
10
|
+
* Values are stored as JSON copies, so later changes to a returned value do
|
|
11
|
+
* not change the cache (the same behaviour as RedisCache).
|
|
12
|
+
*/
|
|
13
|
+
export class MemoryCache {
|
|
14
|
+
/**
|
|
15
|
+
* @param {Object} [options]
|
|
16
|
+
* @param {number} [options.maxEntries=1000] - Entries kept before the least
|
|
17
|
+
* recently used is evicted
|
|
18
|
+
* @param {number} [options.ttlSeconds] - Default time to live; none means
|
|
19
|
+
* entries never expire on their own
|
|
20
|
+
*/
|
|
21
|
+
constructor({ maxEntries, ttlSeconds }?: {
|
|
22
|
+
maxEntries?: number;
|
|
23
|
+
ttlSeconds?: number;
|
|
24
|
+
});
|
|
25
|
+
maxEntries: number;
|
|
26
|
+
ttlSeconds: number;
|
|
27
|
+
_entries: Map<any, any>;
|
|
28
|
+
_hits: number;
|
|
29
|
+
_misses: number;
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} key
|
|
32
|
+
* @returns {Promise<unknown|undefined>}
|
|
33
|
+
*/
|
|
34
|
+
get(key: string): Promise<unknown | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* @param {string} key
|
|
37
|
+
* @param {unknown} value - JSON-serialisable value
|
|
38
|
+
* @param {{ ttlSeconds?: number }} [options]
|
|
39
|
+
* @returns {Promise<void>}
|
|
40
|
+
*/
|
|
41
|
+
set(key: string, value: unknown, { ttlSeconds }?: {
|
|
42
|
+
ttlSeconds?: number;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/** @param {string} key */
|
|
45
|
+
delete(key: string): Promise<void>;
|
|
46
|
+
/** Remove every entry. */
|
|
47
|
+
clear(): Promise<void>;
|
|
48
|
+
/** @returns {Promise<{ hits: number, misses: number, size: number }>} */
|
|
49
|
+
stats(): Promise<{
|
|
50
|
+
hits: number;
|
|
51
|
+
misses: number;
|
|
52
|
+
size: number;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalise the `cache` option of createRagPipeline.
|
|
3
|
+
*
|
|
4
|
+
* - `true`: all three layers in one in-memory cache
|
|
5
|
+
* - a CacheBackend: all three layers in it
|
|
6
|
+
* - `{ embeddings, retrieval, generation, ttlSeconds }`: per layer, each
|
|
7
|
+
* `true` (in-memory), `false`/absent (off) or a CacheBackend;
|
|
8
|
+
* `ttlSeconds: { embeddings, retrieval, generation }` overrides the
|
|
9
|
+
* defaults (30 days, 1 hour, 24 hours)
|
|
10
|
+
*
|
|
11
|
+
* @returns {Object|null} Layer config, or null when caching is off
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeCacheOption(option: any): any | null;
|
|
14
|
+
/**
|
|
15
|
+
* Per-pipeline cache. Every method returns undefined and does nothing for a
|
|
16
|
+
* layer that is off or whose component has no cache key.
|
|
17
|
+
*/
|
|
18
|
+
export class PipelineCache {
|
|
19
|
+
/**
|
|
20
|
+
* @param {Object} layers - normalizeCacheOption() output
|
|
21
|
+
* @param {{ embedder?: Object, retriever?: Object, llm?: Object }} components
|
|
22
|
+
*/
|
|
23
|
+
constructor(layers: any, components: {
|
|
24
|
+
embedder?: any;
|
|
25
|
+
retriever?: any;
|
|
26
|
+
llm?: any;
|
|
27
|
+
});
|
|
28
|
+
layers: any;
|
|
29
|
+
components: {
|
|
30
|
+
embedder?: any;
|
|
31
|
+
retriever?: any;
|
|
32
|
+
llm?: any;
|
|
33
|
+
};
|
|
34
|
+
/** @private */
|
|
35
|
+
private _key;
|
|
36
|
+
/** @private */
|
|
37
|
+
private _get;
|
|
38
|
+
/** @private */
|
|
39
|
+
private _set;
|
|
40
|
+
embeddingKey(query: any): string;
|
|
41
|
+
retrievalKey({ query, queryVector, topK }: {
|
|
42
|
+
query: any;
|
|
43
|
+
queryVector: any;
|
|
44
|
+
topK: any;
|
|
45
|
+
}): string;
|
|
46
|
+
/**
|
|
47
|
+
* @returns {string|null} The key, or null to skip (temperature above 0,
|
|
48
|
+
* or no llm cache key)
|
|
49
|
+
*/
|
|
50
|
+
generationKey({ query, docs, options }: {
|
|
51
|
+
query: any;
|
|
52
|
+
docs: any;
|
|
53
|
+
options: any;
|
|
54
|
+
}): string | null;
|
|
55
|
+
get(layer: any, key: any, status: any): Promise<any>;
|
|
56
|
+
set(layer: any, key: any, value: any): Promise<void>;
|
|
57
|
+
/** Hits, misses and skips per layer since the pipeline was created. */
|
|
58
|
+
stats(): {};
|
|
59
|
+
}
|
|
60
|
+
/** A component's identity for a role, or null when it has none. */
|
|
61
|
+
export function componentKey(component: any, role: any): any;
|
|
62
|
+
export namespace DEFAULT_TTL_SECONDS {
|
|
63
|
+
let embeddings: number;
|
|
64
|
+
let retrieval: number;
|
|
65
|
+
let generation: number;
|
|
66
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CacheBackend on Redis. Pass a connected client from `redis` (node-redis 4
|
|
3
|
+
* and later) or `ioredis`; neither is a dependency of this package.
|
|
4
|
+
*
|
|
5
|
+
* Values are stored as JSON under `prefix + key`, with a millisecond expiry
|
|
6
|
+
* when a time to live applies.
|
|
7
|
+
*/
|
|
8
|
+
export class RedisCache {
|
|
9
|
+
/**
|
|
10
|
+
* @param {Object} options
|
|
11
|
+
* @param {Object} options.client - Connected node-redis or ioredis client
|
|
12
|
+
* @param {string} [options.prefix='rag:'] - Key prefix
|
|
13
|
+
* @param {number} [options.ttlSeconds] - Default time to live
|
|
14
|
+
*/
|
|
15
|
+
constructor({ client, prefix, ttlSeconds }?: {
|
|
16
|
+
client: any;
|
|
17
|
+
prefix?: string;
|
|
18
|
+
ttlSeconds?: number;
|
|
19
|
+
});
|
|
20
|
+
client: any;
|
|
21
|
+
prefix: string;
|
|
22
|
+
ttlSeconds: number;
|
|
23
|
+
_nodeRedis: boolean;
|
|
24
|
+
_hits: number;
|
|
25
|
+
_misses: number;
|
|
26
|
+
/**
|
|
27
|
+
* @param {string} key
|
|
28
|
+
* @returns {Promise<unknown|undefined>}
|
|
29
|
+
*/
|
|
30
|
+
get(key: string): Promise<unknown | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} key
|
|
33
|
+
* @param {unknown} value - JSON-serialisable value
|
|
34
|
+
* @param {{ ttlSeconds?: number }} [options]
|
|
35
|
+
*/
|
|
36
|
+
set(key: string, value: unknown, { ttlSeconds }?: {
|
|
37
|
+
ttlSeconds?: number;
|
|
38
|
+
}): Promise<void>;
|
|
39
|
+
/** @param {string} key */
|
|
40
|
+
delete(key: string): Promise<void>;
|
|
41
|
+
/** Hits and misses seen by this instance (size is not tracked). */
|
|
42
|
+
stats(): Promise<{
|
|
43
|
+
hits: number;
|
|
44
|
+
misses: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChunkingEngine orchestrates text chunking using pluggable strategies.
|
|
3
|
+
* Extends EventEmitter to emit 'chunk' events after each chunking operation.
|
|
4
|
+
*
|
|
5
|
+
* @extends EventEmitter
|
|
6
|
+
*/
|
|
7
|
+
export class ChunkingEngine extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* Create a ChunkingEngine instance.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} [options={}] - Configuration options merged with DEFAULT_CONFIG.
|
|
12
|
+
* @param {string} [options.strategy='recursive'] - Default strategy name.
|
|
13
|
+
* @param {number} [options.chunkSize=512] - Default chunk size.
|
|
14
|
+
* @param {number} [options.chunkOverlap=50] - Default chunk overlap.
|
|
15
|
+
* @param {number} [options.minChunkSize=50] - Default minimum chunk size.
|
|
16
|
+
* @param {string[]} [options.separators] - Default separators for recursive strategy.
|
|
17
|
+
* @param {number} [options.similarityThreshold=0.3] - Default similarity threshold for semantic strategy.
|
|
18
|
+
*/
|
|
19
|
+
constructor(options?: {
|
|
20
|
+
strategy?: string;
|
|
21
|
+
chunkSize?: number;
|
|
22
|
+
chunkOverlap?: number;
|
|
23
|
+
minChunkSize?: number;
|
|
24
|
+
separators?: string[];
|
|
25
|
+
similarityThreshold?: number;
|
|
26
|
+
});
|
|
27
|
+
_config: any;
|
|
28
|
+
_strategies: Map<any, any>;
|
|
29
|
+
/**
|
|
30
|
+
* Chunk text using the configured or specified strategy.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} text - The input text to chunk. Must be a non-empty string.
|
|
33
|
+
* @param {object} [options={}] - Per-call options that override the engine config.
|
|
34
|
+
* @param {string} [options.strategy] - Strategy name to use for this call.
|
|
35
|
+
* @returns {string[]} Array of text chunks.
|
|
36
|
+
* @throws {Error} If text is not a non-empty string.
|
|
37
|
+
* @throws {Error} If the specified strategy is not registered.
|
|
38
|
+
* @fires ChunkingEngine#chunk
|
|
39
|
+
*/
|
|
40
|
+
chunk(text: string, options?: {
|
|
41
|
+
strategy?: string;
|
|
42
|
+
}): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Register a custom chunking strategy.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} name - Strategy name (used to select it via options.strategy).
|
|
47
|
+
* @param {function} fn - Strategy function with signature (text, options) => string[].
|
|
48
|
+
* @throws {Error} If name is not a non-empty string.
|
|
49
|
+
* @throws {Error} If fn is not a function.
|
|
50
|
+
*/
|
|
51
|
+
registerStrategy(name: string, fn: Function): void;
|
|
52
|
+
/**
|
|
53
|
+
* List all registered strategy names.
|
|
54
|
+
*
|
|
55
|
+
* @returns {string[]} Array of strategy names.
|
|
56
|
+
*/
|
|
57
|
+
listStrategies(): string[];
|
|
58
|
+
/**
|
|
59
|
+
* Get the current engine configuration.
|
|
60
|
+
*
|
|
61
|
+
* @returns {object} A copy of the current configuration.
|
|
62
|
+
*/
|
|
63
|
+
getConfig(): object;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Default configuration for the chunking engine.
|
|
67
|
+
* @type {object}
|
|
68
|
+
*/
|
|
69
|
+
export const DEFAULT_CONFIG: object;
|
|
70
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-size chunking strategy.
|
|
3
|
+
* Splits text by character count with configurable overlap.
|
|
4
|
+
* Attempts to break at word boundaries by looking back up to 20 characters.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} text - The input text to chunk.
|
|
7
|
+
* @param {object} [options={}] - Chunking options.
|
|
8
|
+
* @param {number} [options.chunkSize=512] - Target chunk size in characters.
|
|
9
|
+
* @param {number} [options.chunkOverlap=50] - Number of overlapping characters between chunks.
|
|
10
|
+
* @param {number} [options.minChunkSize=50] - Minimum chunk size; smaller chunks are filtered out.
|
|
11
|
+
* @returns {string[]} Array of text chunks.
|
|
12
|
+
*/
|
|
13
|
+
export function fixedSizeChunk(text: string, options?: {
|
|
14
|
+
chunkSize?: number;
|
|
15
|
+
chunkOverlap?: number;
|
|
16
|
+
minChunkSize?: number;
|
|
17
|
+
}): string[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive text chunking strategy.
|
|
3
|
+
* Splits text using a hierarchy of separators, merging consecutive pieces
|
|
4
|
+
* into chunks up to chunkSize. Pieces exceeding chunkSize are recursively
|
|
5
|
+
* split with the next separator in the hierarchy.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} text - The input text to chunk.
|
|
8
|
+
* @param {object} [options={}] - Chunking options.
|
|
9
|
+
* @param {number} [options.chunkSize=512] - Maximum chunk size in characters.
|
|
10
|
+
* @param {number} [options.chunkOverlap=50] - Number of overlapping characters between chunks.
|
|
11
|
+
* @param {string[]} [options.separators] - Separator hierarchy for splitting.
|
|
12
|
+
* @param {number} [options.minChunkSize=50] - Minimum chunk size; smaller chunks are filtered out.
|
|
13
|
+
* @returns {string[]} Array of text chunks.
|
|
14
|
+
*/
|
|
15
|
+
export function recursiveChunk(text: string, options?: {
|
|
16
|
+
chunkSize?: number;
|
|
17
|
+
chunkOverlap?: number;
|
|
18
|
+
separators?: string[];
|
|
19
|
+
minChunkSize?: number;
|
|
20
|
+
}): string[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic chunking strategy using topic-boundary detection.
|
|
3
|
+
* Splits text into sentences, computes Jaccard token overlap between
|
|
4
|
+
* consecutive sentence pairs, and inserts chunk boundaries where
|
|
5
|
+
* similarity drops below the threshold. Oversized segments fall back
|
|
6
|
+
* to recursive splitting.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text - The input text to chunk.
|
|
9
|
+
* @param {object} [options={}] - Chunking options.
|
|
10
|
+
* @param {number} [options.chunkSize=512] - Maximum chunk size in characters.
|
|
11
|
+
* @param {number} [options.similarityThreshold=0.3] - Minimum similarity to keep sentences in the same chunk.
|
|
12
|
+
* @param {number} [options.minChunkSize=50] - Minimum chunk size; smaller chunks are filtered out.
|
|
13
|
+
* @returns {string[]} Array of text chunks.
|
|
14
|
+
*/
|
|
15
|
+
export function semanticChunk(text: string, options?: {
|
|
16
|
+
chunkSize?: number;
|
|
17
|
+
similarityThreshold?: number;
|
|
18
|
+
minChunkSize?: number;
|
|
19
|
+
}): string[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentence-based chunking strategy.
|
|
3
|
+
* Extracted from MarkdownLoader._chunkText for backward compatibility.
|
|
4
|
+
* Splits text on sentence boundaries and merges into chunks up to maxLen.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} text - The input text to chunk.
|
|
7
|
+
* @param {object} [options={}] - Chunking options.
|
|
8
|
+
* @param {number} [options.maxLen=500] - Maximum character length per chunk.
|
|
9
|
+
* @returns {string[]} Array of text chunks.
|
|
10
|
+
*/
|
|
11
|
+
export function sentenceChunk(text: string, options?: {
|
|
12
|
+
maxLen?: number;
|
|
13
|
+
}): string[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structure-aware chunking strategy.
|
|
3
|
+
* Detects document format (Markdown, HTML, or plain) and respects
|
|
4
|
+
* structural boundaries. For Markdown, splits on headers and preserves
|
|
5
|
+
* code blocks. For HTML, splits on heading/section tags. Oversized
|
|
6
|
+
* sections are further split via the recursive strategy.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} text - The input text to chunk.
|
|
9
|
+
* @param {object} [options={}] - Chunking options.
|
|
10
|
+
* @param {number} [options.chunkSize=512] - Maximum chunk size in characters.
|
|
11
|
+
* @param {number} [options.chunkOverlap=50] - Number of overlapping characters between chunks.
|
|
12
|
+
* @param {string} [options.format] - Document format: 'markdown', 'html', 'plain', or auto-detect.
|
|
13
|
+
* @returns {string[]} Array of text chunks.
|
|
14
|
+
*/
|
|
15
|
+
export function structureAwareChunk(text: string, options?: {
|
|
16
|
+
chunkSize?: number;
|
|
17
|
+
chunkOverlap?: number;
|
|
18
|
+
format?: string;
|
|
19
|
+
}): string[];
|