@devilsdev/rag-pipeline-utils 2.4.5 → 2.5.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 +345 -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 +4992 -1242
- package/dist/index.d.ts +80 -2
- package/dist/index.mjs +1 -1
- 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/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 +92 -0
- package/dist/types/connectors/base-connector.d.ts +87 -0
- package/dist/types/connectors/cohere-connector.d.ts +89 -0
- package/dist/types/connectors/connector-utils.d.ts +110 -0
- package/dist/types/connectors/local-embedder.d.ts +86 -0
- package/dist/types/connectors/memory-retriever.d.ts +91 -0
- package/dist/types/connectors/ollama-connector.d.ts +110 -0
- package/dist/types/connectors/openai-connector.d.ts +114 -0
- package/dist/types/connectors/rag-prompt.d.ts +40 -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/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/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 +87 -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/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 +53 -29
- 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/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 +101 -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 +96 -36
- 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 +72 -217
- 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 +41 -26
- 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/rag-service.js +322 -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 +617 -0
- package/src/config/component-factory.js +125 -0
- package/src/config/load-config.js +29 -10
- package/src/config/load-plugin-config.js +46 -2
- package/src/connectors/anthropic-connector.js +93 -55
- package/src/connectors/base-connector.js +74 -19
- package/src/connectors/cohere-connector.js +88 -32
- package/src/connectors/connector-utils.js +302 -0
- package/src/connectors/local-embedder.js +43 -5
- package/src/connectors/memory-retriever.js +108 -15
- package/src/connectors/ollama-connector.js +83 -49
- package/src/connectors/openai-connector.js +108 -44
- package/src/connectors/rag-prompt.js +88 -0
- package/src/core/create-pipeline.js +209 -60
- package/src/core/plugin-registry.js +87 -11
- package/src/cost/cost-calculator.js +205 -32
- package/src/dev/dev-server.js +166 -11
- package/src/dev/hot-reload.js +40 -1
- 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 +715 -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/experimental.js +71 -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 +36 -1
- package/src/loader/document-reader.js +91 -0
- 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 +212 -0
- package/src/retrieval/hybrid-retriever.js +22 -19
- package/src/security/jwt-config.js +13 -2
- package/src/security/jwt-validator.js +134 -30
- package/src/security/plugin-sandbox.js +18 -1
- package/src/security/plugin-signature-verifier.js +245 -70
- 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
package/dist/index.d.ts
CHANGED
|
@@ -258,6 +258,7 @@ export class JWTValidator {
|
|
|
258
258
|
verify(token: string, options?: any): any;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
+
/** @deprecated Experimental (simulated or incomplete). Import PluginSandbox from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
261
262
|
export class PluginSandbox {
|
|
262
263
|
constructor(options?: {
|
|
263
264
|
memoryLimit?: number;
|
|
@@ -283,6 +284,7 @@ export function validateInput(input: string, options?: any): { valid: boolean; e
|
|
|
283
284
|
// AI/ML
|
|
284
285
|
// =============================================================================
|
|
285
286
|
|
|
287
|
+
/** @deprecated Experimental (simulated or incomplete). Import MultiModalProcessor from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
286
288
|
export class MultiModalProcessor {
|
|
287
289
|
constructor(options?: any);
|
|
288
290
|
processContent(tenantId: string, content: any): Promise<any>;
|
|
@@ -290,12 +292,14 @@ export class MultiModalProcessor {
|
|
|
290
292
|
crossModalSearch(tenantId: string, query: any): Promise<any>;
|
|
291
293
|
}
|
|
292
294
|
|
|
295
|
+
/** @deprecated Experimental (simulated or incomplete). Import AdaptiveRetrievalEngine from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
293
296
|
export class AdaptiveRetrievalEngine {
|
|
294
297
|
constructor(options?: any);
|
|
295
298
|
retrieveDocuments(tenantId: string, query: string, options?: any): Promise<any>;
|
|
296
299
|
optimizeRetrieval(tenantId: string, performanceData: any): Promise<any>;
|
|
297
300
|
}
|
|
298
301
|
|
|
302
|
+
/** @deprecated Experimental (simulated or incomplete). Import FederatedLearningCoordinator from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
299
303
|
export class FederatedLearningCoordinator {
|
|
300
304
|
constructor(options?: any);
|
|
301
305
|
createSession(config: any): Promise<any>;
|
|
@@ -303,6 +307,7 @@ export class FederatedLearningCoordinator {
|
|
|
303
307
|
aggregate(sessionId: string): Promise<any>;
|
|
304
308
|
}
|
|
305
309
|
|
|
310
|
+
/** @deprecated Experimental (simulated or incomplete). Import ModelTrainingOrchestrator from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
306
311
|
export class ModelTrainingOrchestrator {
|
|
307
312
|
constructor(options?: any);
|
|
308
313
|
createTrainingJob(tenantId: string, config: any): Promise<any>;
|
|
@@ -370,14 +375,19 @@ export class AuditLogger {
|
|
|
370
375
|
logDataModification(event: any): Promise<void>;
|
|
371
376
|
}
|
|
372
377
|
|
|
378
|
+
/** @deprecated Experimental (simulated or incomplete). Import DataGovernance from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
373
379
|
export class DataGovernance {
|
|
374
380
|
constructor(options?: any);
|
|
375
381
|
classifyData(data: any): any;
|
|
376
382
|
enforceRetention(policy: any): Promise<void>;
|
|
377
383
|
}
|
|
378
384
|
|
|
379
|
-
|
|
385
|
+
/** @deprecated Experimental (simulated or incomplete). Import DataGovernanceManager from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
386
|
+
export declare const DataGovernanceManager: typeof DataGovernance;
|
|
387
|
+
/** @deprecated Experimental (simulated or incomplete). Import DataGovernanceManager from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
388
|
+
export type DataGovernanceManager = DataGovernance;
|
|
380
389
|
|
|
390
|
+
/** @deprecated Experimental (simulated or incomplete). Import TenantManager from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
381
391
|
export class TenantManager {
|
|
382
392
|
constructor(options?: any);
|
|
383
393
|
createTenant(config: any): Promise<any>;
|
|
@@ -385,33 +395,39 @@ export class TenantManager {
|
|
|
385
395
|
deleteTenant(tenantId: string): Promise<void>;
|
|
386
396
|
}
|
|
387
397
|
|
|
398
|
+
/** @deprecated Experimental (simulated or incomplete). Import ResourceMonitor from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
388
399
|
export class ResourceMonitor {
|
|
389
400
|
constructor(options?: any);
|
|
390
401
|
getUsage(tenantId: string): any;
|
|
391
402
|
checkQuota(tenantId: string): boolean;
|
|
392
403
|
}
|
|
393
404
|
|
|
405
|
+
/** @deprecated Experimental (simulated or incomplete). Import SSOManager from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
394
406
|
export class SSOManager {
|
|
395
407
|
constructor(options?: any);
|
|
396
408
|
authenticate(provider: string, credentials: any): Promise<any>;
|
|
397
409
|
getSession(sessionId: string): any;
|
|
398
410
|
}
|
|
399
411
|
|
|
412
|
+
/** @deprecated Experimental (simulated or incomplete). Import SAMLProvider from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
400
413
|
export class SAMLProvider {
|
|
401
414
|
constructor(options?: any);
|
|
402
415
|
authenticate(request: any): Promise<any>;
|
|
403
416
|
}
|
|
404
417
|
|
|
418
|
+
/** @deprecated Experimental (simulated or incomplete). Import OAuth2Provider from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
405
419
|
export class OAuth2Provider {
|
|
406
420
|
constructor(options?: any);
|
|
407
421
|
authenticate(request: any): Promise<any>;
|
|
408
422
|
}
|
|
409
423
|
|
|
424
|
+
/** @deprecated Experimental (simulated or incomplete). Import ActiveDirectoryProvider from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
410
425
|
export class ActiveDirectoryProvider {
|
|
411
426
|
constructor(options?: any);
|
|
412
427
|
authenticate(request: any): Promise<any>;
|
|
413
428
|
}
|
|
414
429
|
|
|
430
|
+
/** @deprecated Experimental (simulated or incomplete). Import OIDCProvider from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
415
431
|
export class OIDCProvider {
|
|
416
432
|
constructor(options?: any);
|
|
417
433
|
authenticate(request: any): Promise<any>;
|
|
@@ -434,6 +450,7 @@ export class PluginAnalytics {
|
|
|
434
450
|
getStats(pluginName: string): any;
|
|
435
451
|
}
|
|
436
452
|
|
|
453
|
+
/** @deprecated Experimental (simulated or incomplete). Import PluginCertification from "@devilsdev/rag-pipeline-utils/experimental"; it will be removed from the main entry in the next major release. */
|
|
437
454
|
export class PluginCertification {
|
|
438
455
|
constructor(options?: any);
|
|
439
456
|
certify(pluginName: string): Promise<any>;
|
|
@@ -464,4 +481,65 @@ export class DevServer {
|
|
|
464
481
|
stop(): Promise<void>;
|
|
465
482
|
}
|
|
466
483
|
|
|
467
|
-
export function createDevServer(options?: any): DevServer;
|
|
484
|
+
export function createDevServer(options?: any): DevServer;
|
|
485
|
+
|
|
486
|
+
// =============================================================================
|
|
487
|
+
// Declarations generated from JSDoc (scripts/generate-types.js)
|
|
488
|
+
// =============================================================================
|
|
489
|
+
export { checkNumericConsistency } from "./types/evaluate/scoring";
|
|
490
|
+
export { extractNumbers } from "./types/evaluate/scoring";
|
|
491
|
+
export { computeFaithfulness } from "./types/evaluate/faithfulness";
|
|
492
|
+
export { computeAnswerRelevance } from "./types/evaluate/relevance";
|
|
493
|
+
export { computeContextPrecision } from "./types/evaluate/context-metrics";
|
|
494
|
+
export { computeContextRecall } from "./types/evaluate/context-metrics";
|
|
495
|
+
export { computeGroundedness } from "./types/evaluate/groundedness";
|
|
496
|
+
export { PipelineEvaluator } from "./types/evaluate/pipeline-evaluator";
|
|
497
|
+
export { ChunkingEngine } from "./types/chunking/chunking-engine";
|
|
498
|
+
export { CitationTracker } from "./types/citation/citation-tracker";
|
|
499
|
+
export { mapSentenceToSources } from "./types/citation/source-mapper";
|
|
500
|
+
export { buildIDFWeights } from "./types/citation/source-mapper";
|
|
501
|
+
export { detectHallucinations } from "./types/citation/hallucination-detector";
|
|
502
|
+
export { BM25Search } from "./types/retrieval/bm25-search";
|
|
503
|
+
export { reciprocalRankFusion } from "./types/retrieval/rank-fusion";
|
|
504
|
+
export { HybridRetriever } from "./types/retrieval/hybrid-retriever";
|
|
505
|
+
export { FileVectorStore } from "./types/retrieval/file-vector-store";
|
|
506
|
+
export { PreRetrievalGuard } from "./types/guardrails/pre-retrieval-guard";
|
|
507
|
+
export { detectInjection } from "./types/guardrails/injection-detector";
|
|
508
|
+
export { RetrievalGuard } from "./types/guardrails/retrieval-guard";
|
|
509
|
+
export { PostGenerationGuard } from "./types/guardrails/post-generation-guard";
|
|
510
|
+
export { GuardrailsPipeline } from "./types/guardrails/guardrails-pipeline";
|
|
511
|
+
export { QueryPlanner } from "./types/agentic/query-planner";
|
|
512
|
+
export { IterativeRetriever } from "./types/agentic/iterative-retriever";
|
|
513
|
+
export { SelfCritiqueChecker } from "./types/agentic/self-critique";
|
|
514
|
+
export { AgenticPipeline } from "./types/agentic/agentic-pipeline";
|
|
515
|
+
export { CostCalculator } from "./types/cost/cost-calculator";
|
|
516
|
+
export { PRICING_METADATA } from "./types/cost/cost-calculator";
|
|
517
|
+
export { CostTracker } from "./types/cost/cost-tracker";
|
|
518
|
+
export { TokenBudget } from "./types/cost/token-budget";
|
|
519
|
+
export { ExecutionTracer } from "./types/debug/execution-tracer";
|
|
520
|
+
export { TraceInspector } from "./types/debug/trace-inspector";
|
|
521
|
+
export { MCPServer } from "./types/mcp/mcp-server";
|
|
522
|
+
export { MCPToolBuilder } from "./types/mcp/mcp-tool-builder";
|
|
523
|
+
export { ProjectScaffolder } from "./types/templates/scaffold";
|
|
524
|
+
export { TemplateRegistry } from "./types/templates/template-registry";
|
|
525
|
+
export { SSEAdapter } from "./types/streaming/sse-adapter";
|
|
526
|
+
export { WebSocketAdapter } from "./types/streaming/websocket-adapter";
|
|
527
|
+
export { StreamRouter } from "./types/streaming/stream-router";
|
|
528
|
+
export { BaseConnector } from "./types/connectors/base-connector";
|
|
529
|
+
export { OllamaConnector } from "./types/connectors/ollama-connector";
|
|
530
|
+
export { LocalEmbedder } from "./types/connectors/local-embedder";
|
|
531
|
+
export { MemoryRetriever } from "./types/connectors/memory-retriever";
|
|
532
|
+
export { OpenAIConnector } from "./types/connectors/openai-connector";
|
|
533
|
+
export { AnthropicConnector } from "./types/connectors/anthropic-connector";
|
|
534
|
+
export { CohereConnector } from "./types/connectors/cohere-connector";
|
|
535
|
+
export { StreamingEmbedder } from "./types/streaming/streaming-embedder";
|
|
536
|
+
export { createEmbeddingStream } from "./types/streaming/embedding-stream";
|
|
537
|
+
export { ScoringReranker } from "./types/reranker/scoring-reranker";
|
|
538
|
+
export { EmbeddingReranker } from "./types/reranker/embedding-reranker";
|
|
539
|
+
export { CascadeReranker } from "./types/reranker/cascade-reranker";
|
|
540
|
+
export { KnowledgeGraph } from "./types/graph/knowledge-graph";
|
|
541
|
+
export { EntityExtractor } from "./types/graph/entity-extractor";
|
|
542
|
+
export { GraphRetriever } from "./types/graph/graph-retriever";
|
|
543
|
+
export { GraphIndex } from "./types/graph/graph-index";
|
|
544
|
+
export { DashboardGenerator } from "./types/dashboard/dashboard-generator";
|
|
545
|
+
export { MetricsAggregator } from "./types/dashboard/metrics-aggregator";
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,6 @@ const require = createRequire(import.meta.url);
|
|
|
8
8
|
|
|
9
9
|
const mod = require('./index.cjs');
|
|
10
10
|
|
|
11
|
-
export const { createRagPipeline, createPipeline, loadConfig, loadRagConfig, validateRagrc, normalizeConfig, pluginRegistry, logger, errorFormatter, createError, wrapError, ERROR_CODES, BatchProcessor, RateLimiter, retry, withRetry, ConnectionPoolManager, JWTValidator, PluginSandbox, PluginSignatureVerifier, validateInput, MultiModalProcessor, AdaptiveRetrievalEngine, FederatedLearningCoordinator, ModelTrainingOrchestrator, DAGEngine, DAG, evaluateRagDataset, scoreAnswer, computeBLEU, computeROUGE, computeFaithfulness, computeAnswerRelevance, computeContextPrecision, computeContextRecall, computeGroundedness, PipelineEvaluator, ChunkingEngine, CitationTracker, mapSentenceToSources, buildIDFWeights, detectHallucinations, BM25Search, reciprocalRankFusion, HybridRetriever, PreRetrievalGuard, RetrievalGuard, PostGenerationGuard, GuardrailsPipeline, QueryPlanner, IterativeRetriever, SelfCritiqueChecker, AgenticPipeline, CostCalculator, CostTracker, TokenBudget, ExecutionTracer, TraceInspector, MCPServer, MCPToolBuilder, ProjectScaffolder, TemplateRegistry, SSEAdapter, WebSocketAdapter, StreamRouter, BaseConnector, OllamaConnector, LocalEmbedder, MemoryRetriever, OpenAIConnector, AnthropicConnector, CohereConnector, StreamingEmbedder, createEmbeddingStream, ScoringReranker, EmbeddingReranker, CascadeReranker, KnowledgeGraph, EntityExtractor, GraphRetriever, GraphIndex, DashboardGenerator, MetricsAggregator, ParallelProcessor, eventLogger, metrics, AuditLogger, DataGovernance, DataGovernanceManager, TenantManager, ResourceMonitor, SSOManager, SAMLProvider, OAuth2Provider, ActiveDirectoryProvider, OIDCProvider, PluginHub, PluginAnalytics, PluginCertification, PluginAnalyticsDashboard, HotReloadManager, createHotReloadManager, DevServer, createDevServer } = mod;
|
|
11
|
+
export const { createRagPipeline, createPipeline, loadConfig, loadRagConfig, validateRagrc, normalizeConfig, pluginRegistry, logger, errorFormatter, createError, wrapError, ERROR_CODES, BatchProcessor, RateLimiter, retry, withRetry, ConnectionPoolManager, JWTValidator, PluginSandbox, PluginSignatureVerifier, validateInput, MultiModalProcessor, AdaptiveRetrievalEngine, FederatedLearningCoordinator, ModelTrainingOrchestrator, DAGEngine, DAG, evaluateRagDataset, scoreAnswer, computeBLEU, computeROUGE, checkNumericConsistency, extractNumbers, computeFaithfulness, computeAnswerRelevance, computeContextPrecision, computeContextRecall, computeGroundedness, PipelineEvaluator, ChunkingEngine, CitationTracker, mapSentenceToSources, buildIDFWeights, detectHallucinations, BM25Search, reciprocalRankFusion, HybridRetriever, FileVectorStore, PreRetrievalGuard, detectInjection, RetrievalGuard, PostGenerationGuard, GuardrailsPipeline, QueryPlanner, IterativeRetriever, SelfCritiqueChecker, AgenticPipeline, CostCalculator, PRICING_METADATA, CostTracker, TokenBudget, ExecutionTracer, TraceInspector, MCPServer, MCPToolBuilder, ProjectScaffolder, TemplateRegistry, SSEAdapter, WebSocketAdapter, StreamRouter, BaseConnector, OllamaConnector, LocalEmbedder, MemoryRetriever, OpenAIConnector, AnthropicConnector, CohereConnector, StreamingEmbedder, createEmbeddingStream, ScoringReranker, EmbeddingReranker, CascadeReranker, KnowledgeGraph, EntityExtractor, GraphRetriever, GraphIndex, DashboardGenerator, MetricsAggregator, ParallelProcessor, eventLogger, metrics, AuditLogger, DataGovernance, DataGovernanceManager, TenantManager, ResourceMonitor, SSOManager, SAMLProvider, OAuth2Provider, ActiveDirectoryProvider, OIDCProvider, PluginHub, PluginAnalytics, PluginCertification, PluginAnalyticsDashboard, HotReloadManager, createHotReloadManager, DevServer, createDevServer } = mod;
|
|
12
12
|
|
|
13
13
|
export default mod;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DAG-based agentic RAG orchestrator with two-phase execution:
|
|
3
|
+
* Phase 1 - Plan: decompose query into sub-queries
|
|
4
|
+
* Phase 2 - Execute: build DAG of retrieve -> merge -> (critique ->) generate
|
|
5
|
+
*
|
|
6
|
+
* @extends EventEmitter
|
|
7
|
+
*/
|
|
8
|
+
export class AgenticPipeline extends EventEmitter<[never]> {
|
|
9
|
+
/**
|
|
10
|
+
* @param {object} [options] - Override default configuration
|
|
11
|
+
* @param {number} [options.maxConcurrency=3] - Max concurrent DAG node execution
|
|
12
|
+
* @param {number} [options.timeout=60000] - Global timeout in ms
|
|
13
|
+
* @param {boolean} [options.enablePlanning=true] - Whether to decompose queries
|
|
14
|
+
* @param {boolean} [options.enableLlmPlanning=false] - Ask the llm for the
|
|
15
|
+
* sub-queries (strictly validated, heuristic fallback); costs one extra
|
|
16
|
+
* llm.generate() call per run
|
|
17
|
+
* @param {boolean} [options.enableCritique=true] - Whether to self-critique answers
|
|
18
|
+
* @param {boolean} [options.enableIterativeRetrieval=false] - Whether to use iterative retrieval
|
|
19
|
+
* @param {number} [options.maxIterations=3] - Max iterations for iterative retrieval
|
|
20
|
+
* @param {number} [options.critiqueThreshold=0.5] - Groundedness threshold for approval
|
|
21
|
+
* @param {object} [options.plannerOptions] - Options forwarded to QueryPlanner
|
|
22
|
+
* @param {object} [options.iterativeOptions] - Options forwarded to IterativeRetriever
|
|
23
|
+
*/
|
|
24
|
+
constructor(options?: {
|
|
25
|
+
maxConcurrency?: number;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
enablePlanning?: boolean;
|
|
28
|
+
enableLlmPlanning?: boolean;
|
|
29
|
+
enableCritique?: boolean;
|
|
30
|
+
enableIterativeRetrieval?: boolean;
|
|
31
|
+
maxIterations?: number;
|
|
32
|
+
critiqueThreshold?: number;
|
|
33
|
+
plannerOptions?: object;
|
|
34
|
+
iterativeOptions?: object;
|
|
35
|
+
});
|
|
36
|
+
config: any;
|
|
37
|
+
planner: QueryPlanner;
|
|
38
|
+
critiqueChecker: SelfCritiqueChecker;
|
|
39
|
+
iterativeRetriever: IterativeRetriever;
|
|
40
|
+
/**
|
|
41
|
+
* Run the full agentic pipeline: plan -> retrieve -> merge -> (critique ->) generate.
|
|
42
|
+
*
|
|
43
|
+
* @param {object} params
|
|
44
|
+
* @param {string} params.query - The user query
|
|
45
|
+
* @param {object} params.retriever - Retriever instance with .retrieve() method
|
|
46
|
+
* @param {object} params.llm - LLM instance with .generate() method
|
|
47
|
+
* @param {Array<number>} [params.queryVector] - Optional pre-computed query vector
|
|
48
|
+
* @param {object} [params.embedder] - Optional embedder; when given, each
|
|
49
|
+
* sub-query is embedded on its own instead of reusing queryVector
|
|
50
|
+
* @param {object} [params.options={}] - Extra options passed to llm.generate()
|
|
51
|
+
* @param {AbortSignal} [params.options.signal] - Cancels the run. The run
|
|
52
|
+
* has its own AbortController (also aborted after `timeout`); its signal
|
|
53
|
+
* is passed to retriever.retrieve({ ..., signal }), embedder.embedQuery /
|
|
54
|
+
* embed(text, { signal }) and llm.generate(query, docs, { ...options,
|
|
55
|
+
* signal }), and no later stage starts once it aborts. The returned
|
|
56
|
+
* promise then rejects with Error('Execution timeout') or
|
|
57
|
+
* Error('Execution aborted').
|
|
58
|
+
* @returns {Promise<{
|
|
59
|
+
* success: boolean,
|
|
60
|
+
* query: string,
|
|
61
|
+
* answer: string,
|
|
62
|
+
* results: Array<object>,
|
|
63
|
+
* critique: object|null,
|
|
64
|
+
* subQueries: Array<object>,
|
|
65
|
+
* metadata: object
|
|
66
|
+
* }>}
|
|
67
|
+
* @throws {Error} If retriever or llm is missing
|
|
68
|
+
*/
|
|
69
|
+
run({ query, retriever, llm, queryVector, embedder, options }: {
|
|
70
|
+
query: string;
|
|
71
|
+
retriever: object;
|
|
72
|
+
llm: object;
|
|
73
|
+
queryVector?: Array<number>;
|
|
74
|
+
embedder?: object;
|
|
75
|
+
options?: {
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
};
|
|
78
|
+
}): Promise<{
|
|
79
|
+
success: boolean;
|
|
80
|
+
query: string;
|
|
81
|
+
answer: string;
|
|
82
|
+
results: Array<object>;
|
|
83
|
+
critique: object | null;
|
|
84
|
+
subQueries: Array<object>;
|
|
85
|
+
metadata: object;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* @param {object} params - Validated run() parameters
|
|
89
|
+
* @param {object} runAbort - Per-run cancellation (see utils/run-abort)
|
|
90
|
+
* @returns {Promise<object>}
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
private _execute;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Default configuration for the AgenticPipeline.
|
|
97
|
+
* @type {object}
|
|
98
|
+
*/
|
|
99
|
+
export const DEFAULT_CONFIG: object;
|
|
100
|
+
import { EventEmitter } from "events";
|
|
101
|
+
import { QueryPlanner } from "./query-planner";
|
|
102
|
+
import { SelfCritiqueChecker } from "./self-critique";
|
|
103
|
+
import { IterativeRetriever } from "./iterative-retriever";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterative retriever that loops: retrieve -> check coverage -> refine -> re-retrieve.
|
|
3
|
+
* Continues until coverage threshold is met or maxIterations is reached.
|
|
4
|
+
*
|
|
5
|
+
* @extends EventEmitter
|
|
6
|
+
*/
|
|
7
|
+
export class IterativeRetriever extends EventEmitter<[never]> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} [options] - Override default configuration
|
|
10
|
+
* @param {number} [options.maxIterations=3] - Maximum retrieval iterations
|
|
11
|
+
* @param {number} [options.coverageThreshold=0.6] - Jaccard similarity threshold for convergence
|
|
12
|
+
* @param {object} [options.retryOptions] - Options passed to retry() on each retrieval call
|
|
13
|
+
*/
|
|
14
|
+
constructor(options?: {
|
|
15
|
+
maxIterations?: number;
|
|
16
|
+
coverageThreshold?: number;
|
|
17
|
+
retryOptions?: object;
|
|
18
|
+
});
|
|
19
|
+
config: any;
|
|
20
|
+
/**
|
|
21
|
+
* Merge new results into accumulated results, deduplicating by id.
|
|
22
|
+
* When duplicates exist, keep the one with the higher score.
|
|
23
|
+
*
|
|
24
|
+
* @param {Array<object>} accumulated - Existing accumulated results
|
|
25
|
+
* @param {Array<object>} newResults - Newly retrieved results
|
|
26
|
+
* @returns {Array<object>}
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
private _mergeResults;
|
|
30
|
+
/**
|
|
31
|
+
* Compute query coverage against accumulated result contents using Jaccard similarity.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} query - Original query
|
|
34
|
+
* @param {Array<object>} results - Accumulated results
|
|
35
|
+
* @returns {number} Coverage score between 0 and 1
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
private _computeCoverage;
|
|
39
|
+
/**
|
|
40
|
+
* Heuristic query refinement: find query tokens missing from results
|
|
41
|
+
* and append them to the original query.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} originalQuery - The original user query
|
|
44
|
+
* @param {Array<object>} results - Accumulated results
|
|
45
|
+
* @returns {string} Refined query
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
private _heuristicRefine;
|
|
49
|
+
/**
|
|
50
|
+
* Perform iterative retrieval with coverage checking and query refinement.
|
|
51
|
+
*
|
|
52
|
+
* @param {object} params
|
|
53
|
+
* @param {string} params.query - The search query
|
|
54
|
+
* @param {object} params.retriever - Retriever instance with .retrieve() method
|
|
55
|
+
* @param {object} [params.llm] - Optional LLM for query refinement
|
|
56
|
+
* @param {Array<number>} [params.queryVector] - Optional pre-computed query vector
|
|
57
|
+
* @param {object} [params.embedder] - Optional embedder; when given, each
|
|
58
|
+
* refined query is re-embedded instead of reusing queryVector
|
|
59
|
+
* @param {AbortSignal} [params.signal] - Cancels the loop: passed to
|
|
60
|
+
* retriever.retrieve({ ..., signal }), the embedder and llm.generate(...,
|
|
61
|
+
* { signal }); no further iteration, retry or refinement starts once it
|
|
62
|
+
* has aborted, and the call rejects with the signal's reason
|
|
63
|
+
* @returns {Promise<{results: Array<object>, iterations: number, converged: boolean, coverage: number}>}
|
|
64
|
+
* @throws {Error} If query or retriever is missing
|
|
65
|
+
*/
|
|
66
|
+
retrieve({ query, retriever, llm, queryVector, embedder, signal }: {
|
|
67
|
+
query: string;
|
|
68
|
+
retriever: object;
|
|
69
|
+
llm?: object;
|
|
70
|
+
queryVector?: Array<number>;
|
|
71
|
+
embedder?: object;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
results: Array<object>;
|
|
75
|
+
iterations: number;
|
|
76
|
+
converged: boolean;
|
|
77
|
+
coverage: number;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Default configuration for the IterativeRetriever.
|
|
82
|
+
* @type {object}
|
|
83
|
+
*/
|
|
84
|
+
export const DEFAULT_CONFIG: object;
|
|
85
|
+
import { EventEmitter } from "events";
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query decomposition planner. The default heuristic needs no LLM:
|
|
3
|
+
*
|
|
4
|
+
* - splits only at clause/question boundaries: "?" / "." followed by more
|
|
5
|
+
* text, ";", and "and" / "or" / "as well as" (optionally after a comma)
|
|
6
|
+
* when a question word, auxiliary verb or imperative follows;
|
|
7
|
+
* - keeps noun-phrase conjunctions intact ("salt and pepper", "A or B");
|
|
8
|
+
* - expands comparisons ("X vs Y", "compare X and Y", "difference between X
|
|
9
|
+
* and Y") into one sub-query per entity plus the comparison itself.
|
|
10
|
+
*
|
|
11
|
+
* `plan(query, { llm })` can instead ask an LLM for a JSON array of
|
|
12
|
+
* sub-queries (strictly validated, heuristic fallback).
|
|
13
|
+
*
|
|
14
|
+
* @extends EventEmitter
|
|
15
|
+
*/
|
|
16
|
+
export class QueryPlanner extends EventEmitter<[never]> {
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} [options] - Override default configuration
|
|
19
|
+
* @param {number} [options.minComplexityToSplit=2] - Minimum complexity
|
|
20
|
+
* score before splitting at conjunctions; punctuation boundaries and
|
|
21
|
+
* comparisons are always split
|
|
22
|
+
* @param {number} [options.maxSubQueries=5] - Maximum number of sub-queries to produce
|
|
23
|
+
*/
|
|
24
|
+
constructor(options?: {
|
|
25
|
+
minComplexityToSplit?: number;
|
|
26
|
+
maxSubQueries?: number;
|
|
27
|
+
});
|
|
28
|
+
config: any;
|
|
29
|
+
/**
|
|
30
|
+
* Compute the complexity score of a query string.
|
|
31
|
+
*
|
|
32
|
+
* Scoring rules:
|
|
33
|
+
* +1 per question word (who, what, when, where, why, how, which)
|
|
34
|
+
* +1 per conjunction (and, or, also, as well as)
|
|
35
|
+
* +1 if length > 100 characters
|
|
36
|
+
* +1 per semicolon
|
|
37
|
+
* +1 per comma-separated clause (commas - 1 if > 0 commas)
|
|
38
|
+
* +1 per conjunction followed by a question word, auxiliary or
|
|
39
|
+
* imperative ("... and how ...", "... and explain ...")
|
|
40
|
+
*
|
|
41
|
+
* @param {string} query
|
|
42
|
+
* @returns {number}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
private _computeComplexity;
|
|
46
|
+
/**
|
|
47
|
+
* Detect the retrieval strategy for a query fragment.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} text
|
|
50
|
+
* @returns {'factual'|'analytical'|'comparative'|'general'}
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private _detectStrategy;
|
|
54
|
+
/**
|
|
55
|
+
* Split a clause describing a comparison into its entities.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} clause
|
|
58
|
+
* @returns {{ entities: string[], aspect: string|null }|null}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private _parseComparison;
|
|
62
|
+
/**
|
|
63
|
+
* Heuristic decomposition into sub-query strings.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} query - Trimmed query
|
|
66
|
+
* @param {number} complexity
|
|
67
|
+
* @returns {Array<{subQuery: string, strategy: string}>}
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
private _decompose;
|
|
71
|
+
/**
|
|
72
|
+
* Turn sub-query texts into the plan result (dedupe, limit, priorities).
|
|
73
|
+
*
|
|
74
|
+
* @param {Array<{subQuery: string, strategy: string}>} items
|
|
75
|
+
* @param {number} complexity
|
|
76
|
+
* @param {string} originalQuery
|
|
77
|
+
* @param {'heuristic'|'llm'} source
|
|
78
|
+
* @returns {object}
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
private _finalize;
|
|
82
|
+
/**
|
|
83
|
+
* Heuristic plan for a trimmed query.
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
private _heuristicPlan;
|
|
87
|
+
/**
|
|
88
|
+
* Strictly validate an LLM's sub-query proposal: a JSON array (optionally
|
|
89
|
+
* in a ```json fence) of 1..maxSubQueries non-empty, single-line strings of
|
|
90
|
+
* at most 500 characters. Anything else is rejected.
|
|
91
|
+
*
|
|
92
|
+
* @param {*} raw - Value returned by llm.generate()
|
|
93
|
+
* @returns {string[]|null}
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
private _parseLlmSubQueries;
|
|
97
|
+
/**
|
|
98
|
+
* Ask the LLM for sub-queries; fall back to the heuristic plan.
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
private _planWithLlm;
|
|
102
|
+
/**
|
|
103
|
+
* Plan query decomposition.
|
|
104
|
+
*
|
|
105
|
+
* Without `options.llm` this is synchronous and returns the plan. With
|
|
106
|
+
* `options.llm` (an object with `generate()`), it returns a Promise of the
|
|
107
|
+
* plan: the LLM is asked for a JSON array of sub-queries, which is strictly
|
|
108
|
+
* validated (see _parseLlmSubQueries); on any failure the heuristic plan is
|
|
109
|
+
* used. `result.source` says which one was used.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} query - The user query to decompose
|
|
112
|
+
* @param {object} [options]
|
|
113
|
+
* @param {{ generate: Function }} [options.llm] - Optional LLM planner
|
|
114
|
+
* @param {AbortSignal} [options.signal] - Passed to llm.generate()
|
|
115
|
+
* @returns {{
|
|
116
|
+
* subQueries: Array<{subQuery: string, strategy: string, priority: number}>,
|
|
117
|
+
* complexity: number,
|
|
118
|
+
* originalQuery: string,
|
|
119
|
+
* source: 'heuristic'|'llm'
|
|
120
|
+
* }|Promise<object>}
|
|
121
|
+
* @throws {Error} If query is not a non-empty string
|
|
122
|
+
* @fires QueryPlanner#planned
|
|
123
|
+
*/
|
|
124
|
+
plan(query: string, options?: {
|
|
125
|
+
llm?: {
|
|
126
|
+
generate: Function;
|
|
127
|
+
};
|
|
128
|
+
signal?: AbortSignal;
|
|
129
|
+
}): {
|
|
130
|
+
subQueries: Array<{
|
|
131
|
+
subQuery: string;
|
|
132
|
+
strategy: string;
|
|
133
|
+
priority: number;
|
|
134
|
+
}>;
|
|
135
|
+
complexity: number;
|
|
136
|
+
originalQuery: string;
|
|
137
|
+
source: "heuristic" | "llm";
|
|
138
|
+
} | Promise<object>;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Default configuration for the QueryPlanner.
|
|
142
|
+
* @type {object}
|
|
143
|
+
*/
|
|
144
|
+
export const DEFAULT_CONFIG: object;
|
|
145
|
+
import { EventEmitter } from "events";
|
|
@@ -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";
|