@devilsdev/rag-pipeline-utils 2.5.0 → 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/CHANGELOG.md +86 -0
- package/README.md +1 -1
- package/dist/index.cjs +1484 -147
- package/dist/index.d.ts +49 -0
- 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/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/connectors/anthropic-connector.d.ts +7 -2
- package/dist/types/connectors/cohere-connector.d.ts +7 -2
- package/dist/types/connectors/local-embedder.d.ts +9 -0
- package/dist/types/connectors/memory-retriever.d.ts +8 -0
- package/dist/types/connectors/ollama-connector.d.ts +7 -2
- package/dist/types/connectors/openai-connector.d.ts +16 -1
- 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/evaluate/semantic-similarity.d.ts +14 -0
- package/dist/types/grounding/check-answer.d.ts +101 -0
- package/dist/types/retrieval/file-vector-store.d.ts +12 -0
- package/dist/types/testing.d.ts +168 -0
- package/package.json +22 -7
- package/src/adapters/ai-sdk.js +215 -0
- 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/cli/commands/ai.js +17 -12
- package/src/cli/commands/plugin-hub.js +18 -13
- package/src/cli/enhanced-cli-commands.js +45 -29
- package/src/cli/handlers/query-handler.js +174 -11
- package/src/cli/services/instrument.js +83 -0
- package/src/cli/services/rag-service.js +51 -12
- package/src/cli/wizard/init-wizard.js +2 -17
- package/src/config/enhanced-ragrc-schema.js +0 -2
- package/src/config/validate-schema.js +4 -1
- package/src/connectors/anthropic-connector.js +22 -2
- package/src/connectors/cohere-connector.js +20 -2
- package/src/connectors/local-embedder.js +20 -0
- package/src/connectors/memory-retriever.js +18 -0
- package/src/connectors/ollama-connector.js +29 -2
- package/src/connectors/openai-connector.js +49 -4
- package/src/core/create-pipeline.js +112 -15
- package/src/core/performance/parallel-processor.js +62 -1
- package/src/core/plugin-registry.js +42 -19
- package/src/core/stage-contracts.js +36 -0
- package/src/core/validate-plugin.js +85 -0
- package/src/debug/execution-tracer.js +14 -4
- package/src/dev/dev-server.js +8 -1
- package/src/dev/hot-reload.js +4 -3
- package/src/enterprise/sso-integration.js +4 -3
- package/src/evaluate/semantic-similarity.js +79 -0
- package/src/grounding/check-answer.js +173 -0
- package/src/index.js +22 -0
- package/src/loader/csv-loader.js +3 -2
- package/src/loader/html-loader.js +3 -1
- package/src/loader/markdown-loader.js +3 -2
- package/src/retrieval/file-vector-store.js +30 -1
- package/src/security/jwt-validator.js +5 -4
- package/src/testing.js +254 -0
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,39 @@ export interface RagPipelineConfig {
|
|
|
14
14
|
llm?: string | LLMPlugin;
|
|
15
15
|
reranker?: string | RerankerPlugin;
|
|
16
16
|
registry?: PluginRegistry;
|
|
17
|
+
/**
|
|
18
|
+
* Cache query embeddings, retrieval results and answers. `true` caches
|
|
19
|
+
* all three in memory; a CacheBackend (MemoryCache, RedisCache, your own)
|
|
20
|
+
* caches all three in it; or configure each layer.
|
|
21
|
+
*/
|
|
22
|
+
cache?: boolean | CacheBackend | CacheOptions;
|
|
17
23
|
[key: string]: any;
|
|
18
24
|
}
|
|
19
25
|
|
|
26
|
+
/** A cache store: get / set / delete, optionally stats. */
|
|
27
|
+
export interface CacheBackend {
|
|
28
|
+
get(key: string): Promise<unknown | undefined>;
|
|
29
|
+
set(key: string, value: unknown, options?: { ttlSeconds?: number }): Promise<void>;
|
|
30
|
+
delete?(key: string): Promise<void>;
|
|
31
|
+
stats?(): Promise<Record<string, number>>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CacheOptions {
|
|
35
|
+
embeddings?: boolean | CacheBackend;
|
|
36
|
+
retrieval?: boolean | CacheBackend;
|
|
37
|
+
generation?: boolean | CacheBackend;
|
|
38
|
+
/** Defaults: embeddings 30 days, retrieval 1 hour, generation 24 hours. */
|
|
39
|
+
ttlSeconds?: { embeddings?: number; retrieval?: number; generation?: number };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type CacheOutcome = "hit" | "miss" | "skip";
|
|
43
|
+
|
|
44
|
+
export interface CacheLayerStats {
|
|
45
|
+
hits: number;
|
|
46
|
+
misses: number;
|
|
47
|
+
skipped: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
20
50
|
export interface PipelineRunOptions {
|
|
21
51
|
query?: string;
|
|
22
52
|
queryVector?: number[];
|
|
@@ -33,11 +63,23 @@ export interface PipelineRunResult {
|
|
|
33
63
|
query?: string;
|
|
34
64
|
results?: any;
|
|
35
65
|
error?: string;
|
|
66
|
+
/** Per-layer cache outcome; present when the pipeline has a cache. */
|
|
67
|
+
cache?: {
|
|
68
|
+
embeddings?: CacheOutcome;
|
|
69
|
+
retrieval?: CacheOutcome;
|
|
70
|
+
generation?: CacheOutcome;
|
|
71
|
+
};
|
|
36
72
|
}
|
|
37
73
|
|
|
38
74
|
export interface Pipeline {
|
|
39
75
|
run(options: PipelineRunOptions): Promise<PipelineRunResult>;
|
|
40
76
|
cleanup(): void;
|
|
77
|
+
/** Hits, misses and skips per cache layer; null without a cache. */
|
|
78
|
+
cacheStats(): {
|
|
79
|
+
embeddings?: CacheLayerStats;
|
|
80
|
+
retrieval?: CacheLayerStats;
|
|
81
|
+
generation?: CacheLayerStats;
|
|
82
|
+
} | null;
|
|
41
83
|
}
|
|
42
84
|
|
|
43
85
|
export interface LoadConfigOptions {
|
|
@@ -486,9 +528,11 @@ export function createDevServer(options?: any): DevServer;
|
|
|
486
528
|
// =============================================================================
|
|
487
529
|
// Declarations generated from JSDoc (scripts/generate-types.js)
|
|
488
530
|
// =============================================================================
|
|
531
|
+
export { validatePlugin } from "./types/core/validate-plugin";
|
|
489
532
|
export { checkNumericConsistency } from "./types/evaluate/scoring";
|
|
490
533
|
export { extractNumbers } from "./types/evaluate/scoring";
|
|
491
534
|
export { computeFaithfulness } from "./types/evaluate/faithfulness";
|
|
535
|
+
export { computeSemanticSimilarity } from "./types/evaluate/semantic-similarity";
|
|
492
536
|
export { computeAnswerRelevance } from "./types/evaluate/relevance";
|
|
493
537
|
export { computeContextPrecision } from "./types/evaluate/context-metrics";
|
|
494
538
|
export { computeContextRecall } from "./types/evaluate/context-metrics";
|
|
@@ -496,6 +540,11 @@ export { computeGroundedness } from "./types/evaluate/groundedness";
|
|
|
496
540
|
export { PipelineEvaluator } from "./types/evaluate/pipeline-evaluator";
|
|
497
541
|
export { ChunkingEngine } from "./types/chunking/chunking-engine";
|
|
498
542
|
export { CitationTracker } from "./types/citation/citation-tracker";
|
|
543
|
+
export { checkAnswer } from "./types/grounding/check-answer";
|
|
544
|
+
export { normalizeSources } from "./types/grounding/check-answer";
|
|
545
|
+
export { createAiSdkAdapter } from "./types/adapters/ai-sdk";
|
|
546
|
+
export { MemoryCache } from "./types/cache/memory-cache";
|
|
547
|
+
export { RedisCache } from "./types/cache/redis-cache";
|
|
499
548
|
export { mapSentenceToSources } from "./types/citation/source-mapper";
|
|
500
549
|
export { buildIDFWeights } from "./types/citation/source-mapper";
|
|
501
550
|
export { detectHallucinations } from "./types/citation/hallucination-detector";
|
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, 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;
|
|
11
|
+
export const { createRagPipeline, createPipeline, loadConfig, loadRagConfig, validateRagrc, normalizeConfig, pluginRegistry, validatePlugin, 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, computeSemanticSimilarity, computeAnswerRelevance, computeContextPrecision, computeContextRecall, computeGroundedness, PipelineEvaluator, ChunkingEngine, CitationTracker, checkAnswer, normalizeSources, createAiSdkAdapter, MemoryCache, RedisCache, 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;
|
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types/testing";
|
package/dist/testing.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type AiSdkFunctions = {
|
|
2
|
+
/**
|
|
3
|
+
* - `embed` from 'ai' (needed for an embedder)
|
|
4
|
+
*/
|
|
5
|
+
embed?: Function;
|
|
6
|
+
/**
|
|
7
|
+
* - `embedMany` from 'ai' (batch embedding)
|
|
8
|
+
*/
|
|
9
|
+
embedMany?: Function;
|
|
10
|
+
/**
|
|
11
|
+
* - `generateText` from 'ai' (needed for an llm)
|
|
12
|
+
*/
|
|
13
|
+
generateText?: Function;
|
|
14
|
+
/**
|
|
15
|
+
* - `streamText` from 'ai' (streaming)
|
|
16
|
+
*/
|
|
17
|
+
streamText?: Function;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Wrap AI SDK models as an embedder and an llm for createRagPipeline().
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* import { embed, embedMany, generateText, streamText } from "ai";
|
|
24
|
+
* import { openai } from "@ai-sdk/openai";
|
|
25
|
+
* import { createAiSdkAdapter, createRagPipeline } from "@devilsdev/rag-pipeline-utils";
|
|
26
|
+
*
|
|
27
|
+
* const { embedder, llm } = createAiSdkAdapter({
|
|
28
|
+
* ai: { embed, embedMany, generateText, streamText },
|
|
29
|
+
* embeddingModel: openai.embedding("text-embedding-3-small"),
|
|
30
|
+
* languageModel: openai("gpt-4o-mini"),
|
|
31
|
+
* });
|
|
32
|
+
* const pipeline = createRagPipeline({ embedder, retriever, llm });
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} options
|
|
35
|
+
* @param {AiSdkFunctions} options.ai - Functions imported from 'ai'
|
|
36
|
+
* @param {Object} [options.embeddingModel] - AI SDK embedding model
|
|
37
|
+
* @param {Object} [options.languageModel] - AI SDK language model
|
|
38
|
+
* @param {Object} [options.settings] - Defaults for every text call, e.g.
|
|
39
|
+
* `{ temperature: 0, maxOutputTokens: 512 }`
|
|
40
|
+
* @param {string} [options.systemPrompt] - Replaces the built-in RAG system
|
|
41
|
+
* prompt
|
|
42
|
+
* @returns {{ embedder: Object|null, llm: Object|null }}
|
|
43
|
+
*/
|
|
44
|
+
export function createAiSdkAdapter(options?: {
|
|
45
|
+
ai: AiSdkFunctions;
|
|
46
|
+
embeddingModel?: any;
|
|
47
|
+
languageModel?: any;
|
|
48
|
+
settings?: any;
|
|
49
|
+
systemPrompt?: string;
|
|
50
|
+
}): {
|
|
51
|
+
embedder: any | null;
|
|
52
|
+
llm: any | null;
|
|
53
|
+
};
|
|
@@ -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
|
+
}
|
|
@@ -28,8 +28,14 @@ export class AnthropicConnector extends BaseConnector {
|
|
|
28
28
|
retryDelay?: number;
|
|
29
29
|
systemPrompt?: string;
|
|
30
30
|
});
|
|
31
|
+
/**
|
|
32
|
+
* Cache identity for createRagPipeline({ cache }).
|
|
33
|
+
* @param {'llm'} role
|
|
34
|
+
* @returns {string|null}
|
|
35
|
+
*/
|
|
36
|
+
getCacheKey(role: "llm"): string | null;
|
|
31
37
|
config: any;
|
|
32
|
-
client: axios.AxiosInstance;
|
|
38
|
+
client: import("axios").AxiosInstance;
|
|
33
39
|
/**
|
|
34
40
|
* @throws {Error} code MISSING_API_KEY when no key is configured
|
|
35
41
|
* @private
|
|
@@ -89,4 +95,3 @@ export class AnthropicConnector extends BaseConnector {
|
|
|
89
95
|
*/
|
|
90
96
|
export const DEFAULT_CONFIG: any;
|
|
91
97
|
import { BaseConnector } from "./base-connector";
|
|
92
|
-
import axios = require("axios");
|
|
@@ -23,8 +23,14 @@ export class CohereConnector extends BaseConnector {
|
|
|
23
23
|
inputType?: string;
|
|
24
24
|
queryInputType?: string;
|
|
25
25
|
});
|
|
26
|
+
/**
|
|
27
|
+
* Cache identity for createRagPipeline({ cache }).
|
|
28
|
+
* @param {'embedder'} role
|
|
29
|
+
* @returns {string|null}
|
|
30
|
+
*/
|
|
31
|
+
getCacheKey(role: "embedder"): string | null;
|
|
26
32
|
config: any;
|
|
27
|
-
client: axios.AxiosInstance;
|
|
33
|
+
client: import("axios").AxiosInstance;
|
|
28
34
|
/**
|
|
29
35
|
* @throws {Error} code MISSING_API_KEY when no key is configured
|
|
30
36
|
* @private
|
|
@@ -86,4 +92,3 @@ export class CohereConnector extends BaseConnector {
|
|
|
86
92
|
*/
|
|
87
93
|
export const DEFAULT_CONFIG: any;
|
|
88
94
|
import { BaseConnector } from "./base-connector";
|
|
89
|
-
import axios = require("axios");
|
|
@@ -29,6 +29,7 @@ export class LocalEmbedder extends BaseConnector {
|
|
|
29
29
|
content?: string;
|
|
30
30
|
text?: string;
|
|
31
31
|
}>): void;
|
|
32
|
+
_fingerprint: string;
|
|
32
33
|
/**
|
|
33
34
|
* Compute a TF-IDF vector for the given text.
|
|
34
35
|
* The vector length equals the vocabulary size. Synchronous; when
|
|
@@ -70,6 +71,14 @@ export class LocalEmbedder extends BaseConnector {
|
|
|
70
71
|
vocabulary: Array<[string, number]>;
|
|
71
72
|
idf: Array<[string, number]>;
|
|
72
73
|
}): void;
|
|
74
|
+
/**
|
|
75
|
+
* Cache identity for createRagPipeline({ cache }): a fingerprint of the
|
|
76
|
+
* trained vocabulary and IDF weights, so retraining invalidates cached
|
|
77
|
+
* query vectors (also across processes sharing a Redis cache).
|
|
78
|
+
* @param {'embedder'} role
|
|
79
|
+
* @returns {string|null}
|
|
80
|
+
*/
|
|
81
|
+
getCacheKey(role: "embedder"): string | null;
|
|
73
82
|
/** @returns {number} Vector length produced by embed() once trained */
|
|
74
83
|
get dimensions(): number;
|
|
75
84
|
/**
|
|
@@ -24,6 +24,14 @@ export class MemoryRetriever extends BaseConnector {
|
|
|
24
24
|
}>;
|
|
25
25
|
/** @type {number|null} Vector dimension, fixed by the first stored vector */
|
|
26
26
|
dimensions: number | null;
|
|
27
|
+
_cacheId: string;
|
|
28
|
+
_revision: number;
|
|
29
|
+
/**
|
|
30
|
+
* Cache identity for createRagPipeline({ cache }).
|
|
31
|
+
* @param {'retriever'} role
|
|
32
|
+
* @returns {string|null}
|
|
33
|
+
*/
|
|
34
|
+
getCacheKey(role: "retriever"): string | null;
|
|
27
35
|
/**
|
|
28
36
|
* Store one or more vector documents. The batch is validated before
|
|
29
37
|
* anything is inserted, so a rejected call leaves the store unchanged.
|
|
@@ -26,8 +26,14 @@ export class OllamaConnector extends BaseConnector {
|
|
|
26
26
|
retryDelay?: number;
|
|
27
27
|
systemPrompt?: string;
|
|
28
28
|
});
|
|
29
|
+
/**
|
|
30
|
+
* Cache identity for createRagPipeline({ cache }).
|
|
31
|
+
* @param {'embedder'|'llm'} role
|
|
32
|
+
* @returns {string|null}
|
|
33
|
+
*/
|
|
34
|
+
getCacheKey(role: "embedder" | "llm"): string | null;
|
|
29
35
|
config: any;
|
|
30
|
-
client: axios.AxiosInstance;
|
|
36
|
+
client: import("axios").AxiosInstance;
|
|
31
37
|
/**
|
|
32
38
|
* POST with the connector's retry policy and cancellation.
|
|
33
39
|
* @private
|
|
@@ -107,4 +113,3 @@ export class OllamaConnector extends BaseConnector {
|
|
|
107
113
|
*/
|
|
108
114
|
export const DEFAULT_CONFIG: any;
|
|
109
115
|
import { BaseConnector } from "./base-connector";
|
|
110
|
-
import axios = require("axios");
|
|
@@ -11,7 +11,14 @@ export class OpenAIConnector extends BaseConnector {
|
|
|
11
11
|
* @param {string} [options.embeddingModel='text-embedding-3-small'] - Embedding model
|
|
12
12
|
* @param {number} [options.temperature=0.7] - Sampling temperature
|
|
13
13
|
* @param {number} [options.maxTokens=4096] - Max tokens in completion
|
|
14
|
-
* @param {string} [options.apiKey] -
|
|
14
|
+
* @param {string} [options.apiKey] - API key. Defaults to OPENAI_API_KEY at
|
|
15
|
+
* construction, except when `baseURL` is set (see below)
|
|
16
|
+
* @param {string} [options.baseURL] - Base URL of an OpenAI-compatible API,
|
|
17
|
+
* e.g. Groq, Together, the Hugging Face router, vLLM, LM Studio or
|
|
18
|
+
* Ollama's `/v1` endpoint. With a custom base URL the key is never read
|
|
19
|
+
* from OPENAI_API_KEY (that would send your OpenAI key to another
|
|
20
|
+
* provider): pass `apiKey` explicitly, or omit it for servers that need
|
|
21
|
+
* none
|
|
15
22
|
* @param {number} [options.maxRetries=3] - Retries for transient failures (the SDK's own retries are disabled)
|
|
16
23
|
* @param {number} [options.retryDelay=1000] - Base backoff delay in ms
|
|
17
24
|
* @param {string} [options.systemPrompt] - System prompt used when RAG context is supplied
|
|
@@ -22,10 +29,18 @@ export class OpenAIConnector extends BaseConnector {
|
|
|
22
29
|
temperature?: number;
|
|
23
30
|
maxTokens?: number;
|
|
24
31
|
apiKey?: string;
|
|
32
|
+
baseURL?: string;
|
|
25
33
|
maxRetries?: number;
|
|
26
34
|
retryDelay?: number;
|
|
27
35
|
systemPrompt?: string;
|
|
28
36
|
});
|
|
37
|
+
/**
|
|
38
|
+
* Cache identity for createRagPipeline({ cache }): the settings that
|
|
39
|
+
* change this connector's output in the given role.
|
|
40
|
+
* @param {'embedder'|'llm'} role
|
|
41
|
+
* @returns {string|null}
|
|
42
|
+
*/
|
|
43
|
+
getCacheKey(role: "embedder" | "llm"): string | null;
|
|
29
44
|
config: any;
|
|
30
45
|
_client: any;
|
|
31
46
|
/**
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function createRagPipeline({ registry, loader, embedder, retriever, llm, reranker, cache, }?: {}): {
|
|
2
|
+
run: ({ query, queryVector, options }?: {
|
|
3
|
+
options?: {};
|
|
4
|
+
}) => Promise<any>;
|
|
5
|
+
cleanup(): void;
|
|
6
|
+
/** Cache hits, misses and skips per layer; null when caching is off. */
|
|
7
|
+
cacheStats(): {};
|
|
8
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export = registry;
|
|
2
|
+
declare const registry: PluginRegistry;
|
|
3
|
+
declare class PluginRegistry {
|
|
4
|
+
constructor(options?: {});
|
|
5
|
+
_plugins: Map<any, any>;
|
|
6
|
+
_validTypes: Set<string>;
|
|
7
|
+
_contracts: Map<any, any>;
|
|
8
|
+
_contractWarningsShown: Set<any>;
|
|
9
|
+
_disableContractWarnings: any;
|
|
10
|
+
_validateContractSchema: any;
|
|
11
|
+
_signatureVerifier: import("../security/plugin-signature-verifier.js").PluginSignatureVerifier;
|
|
12
|
+
_requireSignedPlugins: boolean;
|
|
13
|
+
_contractsLoaded: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Load the contract schema and the stage contracts once.
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
private _ensureContracts;
|
|
19
|
+
_ajv: any;
|
|
20
|
+
_contractSchema: any;
|
|
21
|
+
_contractSchemaValidator: any;
|
|
22
|
+
/**
|
|
23
|
+
* Load contract schema for validation
|
|
24
|
+
*
|
|
25
|
+
* @private
|
|
26
|
+
* @returns {Object|null} Contract schema or null if not found
|
|
27
|
+
*
|
|
28
|
+
* @since 2.2.4
|
|
29
|
+
*/
|
|
30
|
+
private _loadContractSchema;
|
|
31
|
+
/**
|
|
32
|
+
* Validate contract against schema
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
* @param {Object} contract - Contract to validate
|
|
36
|
+
* @param {string} type - Contract type
|
|
37
|
+
* @returns {Object} Validation result { valid: boolean, errors: Array }
|
|
38
|
+
*
|
|
39
|
+
* @since 2.2.4
|
|
40
|
+
*/
|
|
41
|
+
private _validateContractAgainstSchema;
|
|
42
|
+
/**
|
|
43
|
+
* Format schema validation errors for display
|
|
44
|
+
*
|
|
45
|
+
* @private
|
|
46
|
+
* @param {Array} errors - Ajv validation errors
|
|
47
|
+
* @returns {string} Formatted error message
|
|
48
|
+
*
|
|
49
|
+
* @since 2.2.4
|
|
50
|
+
*/
|
|
51
|
+
private _formatSchemaErrors;
|
|
52
|
+
/**
|
|
53
|
+
* Check if a contract exists for the given plugin type
|
|
54
|
+
*
|
|
55
|
+
* @param {string} type - Plugin type (loader, embedder, etc.)
|
|
56
|
+
* @returns {boolean} True if contract exists, false otherwise
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const hasContract = registry.checkContractExists('loader');
|
|
60
|
+
* if (!hasContract) {
|
|
61
|
+
* console.warn('No contract for loader plugins');
|
|
62
|
+
* }
|
|
63
|
+
*
|
|
64
|
+
* @since 2.2.4
|
|
65
|
+
*/
|
|
66
|
+
checkContractExists(type: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Log one-time warning for missing contract
|
|
69
|
+
*
|
|
70
|
+
* Logs a helpful warning message about the benefits of contracts
|
|
71
|
+
* and how to add them. Only logs once per contract type and only
|
|
72
|
+
* in non-production environments.
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
* @param {string} type - Plugin type
|
|
76
|
+
* @param {string} context - Context where warning is generated (e.g., 'load', 'register')
|
|
77
|
+
*
|
|
78
|
+
* @since 2.2.4
|
|
79
|
+
*/
|
|
80
|
+
private _warnMissingContract;
|
|
81
|
+
_loadContracts(): void;
|
|
82
|
+
_validatePluginContract(category: any, impl: any): void;
|
|
83
|
+
_getRequiredMethodsFromContract(contract: any): any[];
|
|
84
|
+
/**
|
|
85
|
+
* Register a plugin.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} category - Plugin type
|
|
88
|
+
* @param {string} name - Plugin name
|
|
89
|
+
* @param {object} impl - Plugin implementation
|
|
90
|
+
* @param {object|null} [manifest] - Signed manifest; when given, its
|
|
91
|
+
* signature is verified before registration
|
|
92
|
+
* @param {object} [options]
|
|
93
|
+
* @param {object} [options.content] - Plugin content checked against the
|
|
94
|
+
* manifest's contentDigest: `{ files, baseDir, contents }`
|
|
95
|
+
* @returns {Promise<PluginRegistry>}
|
|
96
|
+
*/
|
|
97
|
+
register(category: string, name: string, impl: object, manifest?: object | null, options?: {
|
|
98
|
+
content?: object;
|
|
99
|
+
}): Promise<PluginRegistry>;
|
|
100
|
+
/**
|
|
101
|
+
* Verify plugin signature
|
|
102
|
+
* @param {object} manifest - Plugin manifest
|
|
103
|
+
* @param {string} pluginName - Plugin name
|
|
104
|
+
*/
|
|
105
|
+
_verifyPluginSignature(manifest: object, pluginName: string, content?: any): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Whether plugin signature verification is enabled for this registry.
|
|
108
|
+
* @returns {boolean}
|
|
109
|
+
*/
|
|
110
|
+
isSignatureVerificationEnabled(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Whether plugins without a signed manifest are rejected.
|
|
113
|
+
* @returns {boolean}
|
|
114
|
+
*/
|
|
115
|
+
requiresSignedPlugins(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Verify a plugin's signed manifest and code before it is loaded (use this
|
|
118
|
+
* before importing plugin files, since importing executes them).
|
|
119
|
+
*
|
|
120
|
+
* @param {string} pluginName - Plugin name (for audit entries)
|
|
121
|
+
* @param {object} manifest - Signed manifest
|
|
122
|
+
* @param {object} content - `{ files, baseDir, contents }`
|
|
123
|
+
* @returns {Promise<void>} Rejects if verification fails
|
|
124
|
+
*/
|
|
125
|
+
verifyPluginContent(pluginName: string, manifest: object, content: object): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Emit audit entry
|
|
128
|
+
* @param {string} action - Audit action
|
|
129
|
+
* @param {object} details - Audit details
|
|
130
|
+
*/
|
|
131
|
+
_emitAuditEntry(action: string, details: object): void;
|
|
132
|
+
get(category: any, name: any): any;
|
|
133
|
+
resolve(category: any, name: any): any;
|
|
134
|
+
list(category: any): any[];
|
|
135
|
+
clear(): void;
|
|
136
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each pipeline stage must provide, as createRagPipeline and the CLI
|
|
3
|
+
* use it. A plugin needs at least one of `anyOf`; a missing `recommended`
|
|
4
|
+
* method only matters for the command named in its note.
|
|
5
|
+
*
|
|
6
|
+
* Shared by validatePlugin() and the `rag-pipeline init` wizard. The
|
|
7
|
+
* stricter rules pluginRegistry.register() applies (metadata, and the
|
|
8
|
+
* methods in contracts/*.json) are checked by validatePlugin(..., {
|
|
9
|
+
* registry: true }).
|
|
10
|
+
*/
|
|
11
|
+
export const STAGE_CONTRACTS: Readonly<{
|
|
12
|
+
loader: {
|
|
13
|
+
anyOf: string[];
|
|
14
|
+
recommended: {};
|
|
15
|
+
};
|
|
16
|
+
embedder: {
|
|
17
|
+
anyOf: string[];
|
|
18
|
+
recommended: {
|
|
19
|
+
embed: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
retriever: {
|
|
23
|
+
anyOf: string[];
|
|
24
|
+
recommended: {
|
|
25
|
+
store: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
reranker: {
|
|
29
|
+
anyOf: string[];
|
|
30
|
+
recommended: {};
|
|
31
|
+
};
|
|
32
|
+
llm: {
|
|
33
|
+
anyOf: string[];
|
|
34
|
+
recommended: {};
|
|
35
|
+
};
|
|
36
|
+
}>;
|