@devilsdev/rag-pipeline-utils 2.6.1 → 2.7.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/BENCHMARKS.md +7 -1
- package/CHANGELOG.md +135 -0
- package/README.md +37 -24
- package/dist/index.cjs +4164 -1825
- package/dist/index.d.ts +265 -256
- package/dist/index.mjs +1 -1
- package/dist/types/cache/memory-cache.d.ts +4 -1
- package/dist/types/cache/redis-cache.d.ts +4 -1
- package/dist/types/cli/services/instrument.d.ts +14 -0
- package/dist/types/cli/services/rag-service.d.ts +140 -0
- package/dist/types/cli/shared/config-context.d.ts +9 -0
- package/dist/types/config/component-factory.d.ts +57 -0
- package/dist/types/config/enhanced-ragrc-schema.d.ts +648 -0
- package/dist/types/config/load-config.d.ts +18 -0
- package/dist/types/config/normalize-config.d.ts +9 -0
- package/dist/types/core/observability/event-logger.d.ts +211 -0
- package/dist/types/core/observability/metrics.d.ts +585 -0
- package/dist/types/core/performance/parallel-processor.d.ts +92 -0
- package/dist/types/core/plugin-registry.d.ts +5 -0
- package/dist/types/dag/core/execution-scheduler.d.ts +3 -1
- package/dist/types/dag/dag-engine.d.ts +15 -2
- package/dist/types/dev/dev-server.d.ts +136 -0
- package/dist/types/dev/hot-reload.d.ts +226 -0
- package/dist/types/ecosystem/plugin-analytics-dashboard.d.ts +141 -0
- package/dist/types/ecosystem/plugin-hub.d.ts +161 -0
- package/dist/types/ecosystem/plugin-installer.d.ts +40 -0
- package/dist/types/ecosystem/plugin-probe.d.ts +21 -0
- package/dist/types/ecosystem/plugin-scanner.d.ts +30 -0
- package/dist/types/ecosystem/tar-extract.d.ts +24 -0
- package/dist/types/enterprise/audit-logging.d.ts +217 -0
- package/dist/types/evaluate/compare.d.ts +140 -0
- package/dist/types/evaluate/dataset.d.ts +43 -0
- package/dist/types/evaluate/evaluator.d.ts +14 -0
- package/dist/types/evaluate/report.d.ts +56 -0
- package/dist/types/evaluate/synthetic.d.ts +64 -0
- package/dist/types/loader/csv-loader.d.ts +10 -0
- package/dist/types/loader/document-reader.d.ts +18 -0
- package/dist/types/loader/html-loader.d.ts +21 -0
- package/dist/types/loader/markdown-loader.d.ts +21 -0
- package/dist/types/retrieval/bm25-search.d.ts +4 -0
- package/dist/types/retrieval/file-vector-store.d.ts +4 -1
- package/dist/types/retrieval/hybrid-retriever.d.ts +4 -0
- package/dist/types/retrieval/pgvector-retriever.d.ts +123 -0
- package/dist/types/retrieval/qdrant-retriever.d.ts +106 -0
- package/dist/types/security/validator.d.ts +11 -1
- package/dist/types/testing.d.ts +2 -0
- package/dist/types/utils/batch-processor.d.ts +205 -0
- package/dist/types/utils/connection-pool.d.ts +158 -0
- package/dist/types/utils/error-formatter.d.ts +312 -0
- package/dist/types/utils/logger.d.ts +29 -4
- package/dist/types/utils/rate-limiter.d.ts +13 -8
- package/dist/types/utils/retry.d.ts +10 -0
- package/package.json +13 -3
- package/src/cache/memory-cache.js +4 -1
- package/src/cache/redis-cache.js +4 -1
- package/src/cli/enhanced-cli-commands.js +79 -0
- package/src/cli/handlers/ai-handler.js +2 -2
- package/src/cli/handlers/eval-handler.js +201 -0
- package/src/cli/handlers/generate-handler.js +103 -0
- package/src/cli/services/benchmark.js +2 -2
- package/src/cli/services/rag-service.js +59 -10
- package/src/cli/shared/cli-utils.js +40 -1
- package/src/config/component-factory.js +32 -0
- package/src/connectors/local-embedder.js +20 -13
- package/src/core/observability/event-logger.js +135 -1
- package/src/core/observability/metrics.js +223 -5
- package/src/core/performance/parallel-processor.js +2 -0
- package/src/core/plugin-registry.js +5 -1
- package/src/dag/core/execution-scheduler.js +2 -0
- package/src/dag/dag-engine.js +13 -0
- package/src/dev/dev-server.js +6 -0
- package/src/ecosystem/plugin-hub.js +4 -0
- package/src/enterprise/audit-logging.js +5 -0
- package/src/evaluate/compare.js +395 -0
- package/src/evaluate/dataset.js +207 -0
- package/src/evaluate/report.js +350 -0
- package/src/evaluate/synthetic.js +246 -0
- package/src/index.js +17 -0
- package/src/retrieval/bm25-search.js +4 -0
- package/src/retrieval/file-vector-store.js +4 -1
- package/src/retrieval/hybrid-retriever.js +4 -0
- package/src/retrieval/pgvector-retriever.js +420 -0
- package/src/retrieval/qdrant-retriever.js +361 -0
- package/src/security/validator.js +8 -0
- package/src/testing.js +2 -0
- package/src/utils/batch-processor.js +7 -3
- package/src/utils/error-formatter.js +48 -20
- package/src/utils/logger.js +31 -1
- package/src/utils/rate-limiter.js +9 -4
- package/src/utils/retry.js +10 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RAG Pipeline Utils - TypeScript Definitions
|
|
3
|
-
* @module
|
|
3
|
+
* @module rag-pipeline-utils
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// =============================================================================
|
|
7
|
-
//
|
|
7
|
+
// Pipeline
|
|
8
8
|
// =============================================================================
|
|
9
9
|
|
|
10
|
+
/** Options for {@link createRagPipeline}. */
|
|
10
11
|
export interface RagPipelineConfig {
|
|
12
|
+
/** Resolves plugin names given as strings; defaults to the shared {@link pluginRegistry}. */
|
|
13
|
+
registry?: PluginRegistry;
|
|
14
|
+
/** Called with no arguments at the start of every run; its result is ignored. */
|
|
11
15
|
loader?: string | LoaderPlugin;
|
|
16
|
+
/** Embeds the query when `run()` gets a `query` and no `queryVector`. */
|
|
12
17
|
embedder?: string | EmbedderPlugin;
|
|
18
|
+
/** Finds the documents for a query. Without one, every run retrieves nothing. */
|
|
13
19
|
retriever?: string | RetrieverPlugin;
|
|
20
|
+
/** Writes the answer. Without one the pipeline is retrieval-only and `answer` is null. */
|
|
14
21
|
llm?: string | LLMPlugin;
|
|
22
|
+
/** Reorders the retrieved documents before generation. */
|
|
15
23
|
reranker?: string | RerankerPlugin;
|
|
16
|
-
registry?: PluginRegistry;
|
|
17
24
|
/**
|
|
18
25
|
* Cache query embeddings, retrieval results and answers. `true` caches
|
|
19
26
|
* all three in memory; a CacheBackend (MemoryCache, RedisCache, your own)
|
|
20
27
|
* caches all three in it; or configure each layer.
|
|
21
28
|
*/
|
|
22
29
|
cache?: boolean | CacheBackend | CacheOptions;
|
|
30
|
+
/** Other keys are ignored. */
|
|
23
31
|
[key: string]: any;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/** A cache store: get / set / delete, optionally stats. */
|
|
27
35
|
export interface CacheBackend {
|
|
36
|
+
/** Resolves the stored value, or undefined when the key is missing or expired. */
|
|
28
37
|
get(key: string): Promise<unknown | undefined>;
|
|
38
|
+
/** Stores a value, expiring it after `ttlSeconds` when given. */
|
|
29
39
|
set(key: string, value: unknown, options?: { ttlSeconds?: number }): Promise<void>;
|
|
40
|
+
/** Removes a key. */
|
|
30
41
|
delete?(key: string): Promise<void>;
|
|
42
|
+
/** Backend-specific counters, such as size or hits. */
|
|
31
43
|
stats?(): Promise<Record<string, number>>;
|
|
32
44
|
}
|
|
33
45
|
|
|
46
|
+
/** Per-layer cache settings: `true` for memory, a CacheBackend, or false/omitted for none. */
|
|
34
47
|
export interface CacheOptions {
|
|
35
48
|
embeddings?: boolean | CacheBackend;
|
|
36
49
|
retrieval?: boolean | CacheBackend;
|
|
@@ -39,29 +52,62 @@ export interface CacheOptions {
|
|
|
39
52
|
ttlSeconds?: { embeddings?: number; retrieval?: number; generation?: number };
|
|
40
53
|
}
|
|
41
54
|
|
|
55
|
+
/** What a cache layer did for one run: served it, stored it, or was not used. */
|
|
42
56
|
export type CacheOutcome = "hit" | "miss" | "skip";
|
|
43
57
|
|
|
58
|
+
/** Counts for one cache layer since the pipeline was created. */
|
|
44
59
|
export interface CacheLayerStats {
|
|
45
60
|
hits: number;
|
|
46
61
|
misses: number;
|
|
47
62
|
skipped: number;
|
|
48
63
|
}
|
|
49
64
|
|
|
65
|
+
/** The argument of {@link Pipeline.run}. Give a `query`, a `queryVector`, or both. */
|
|
50
66
|
export interface PipelineRunOptions {
|
|
67
|
+
/** The question. Embedded by the embedder unless `queryVector` is given. */
|
|
51
68
|
query?: string;
|
|
69
|
+
/** A precomputed query embedding; skips the embedder. */
|
|
52
70
|
queryVector?: number[];
|
|
71
|
+
/** Per-run options. The whole object is also passed to `llm.generate`. */
|
|
53
72
|
options?: {
|
|
73
|
+
/** Documents to retrieve. Default 3. */
|
|
74
|
+
topK?: number;
|
|
75
|
+
/** Abort the run after this many milliseconds; it resolves `{ success: false, error: "Execution timeout" }`. */
|
|
54
76
|
timeout?: number;
|
|
77
|
+
/** Cancel the run; it resolves `{ success: false, error: "Execution aborted" }`. */
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
/** Resolve to an async iterable of {@link StreamChunk} instead of a result. */
|
|
55
80
|
stream?: boolean;
|
|
56
|
-
|
|
81
|
+
/** Attribute the answer's sentences to the retrieved documents (see CitationTracker). */
|
|
82
|
+
citations?: boolean;
|
|
83
|
+
citationOptions?: Record<string, any>;
|
|
84
|
+
/** Score the run (see PipelineEvaluator). */
|
|
85
|
+
evaluate?: boolean;
|
|
86
|
+
evaluateOptions?: Record<string, any>;
|
|
87
|
+
/** Ground-truth answer, used by evaluation for context recall. */
|
|
88
|
+
referenceAnswer?: string;
|
|
89
|
+
/** Filter or transform the retrieved documents before reranking. */
|
|
90
|
+
filterResults?: (docs: SearchResult[]) => SearchResult[] | Promise<SearchResult[]>;
|
|
57
91
|
[key: string]: any;
|
|
58
92
|
};
|
|
59
93
|
}
|
|
60
94
|
|
|
95
|
+
/**
|
|
96
|
+
* What {@link Pipeline.run} resolves to without streaming. A failed, timed-out
|
|
97
|
+
* or aborted run resolves `{ success: false, error }`; `run` never rejects.
|
|
98
|
+
*/
|
|
61
99
|
export interface PipelineRunResult {
|
|
62
100
|
success: boolean;
|
|
63
101
|
query?: string;
|
|
64
|
-
|
|
102
|
+
/** The retrieved (filtered, reranked) documents. */
|
|
103
|
+
results?: SearchResult[];
|
|
104
|
+
/** The LLM's answer; null when the pipeline has no llm. */
|
|
105
|
+
answer?: string | null;
|
|
106
|
+
/** Present when `options.citations` was set and there is an answer. */
|
|
107
|
+
citations?: any;
|
|
108
|
+
/** Present when `options.evaluate` was set. */
|
|
109
|
+
evaluation?: any;
|
|
110
|
+
/** The error message when `success` is false. */
|
|
65
111
|
error?: string;
|
|
66
112
|
/** Per-layer cache outcome; present when the pipeline has a cache. */
|
|
67
113
|
cache?: {
|
|
@@ -71,8 +117,32 @@ export interface PipelineRunResult {
|
|
|
71
117
|
};
|
|
72
118
|
}
|
|
73
119
|
|
|
120
|
+
/**
|
|
121
|
+
* One chunk of a streamed answer. The last chunk has `done: true` and, when
|
|
122
|
+
* requested, the run's `citations` and `evaluation`. Without an llm the
|
|
123
|
+
* stream is a single done chunk carrying `results`.
|
|
124
|
+
*/
|
|
125
|
+
export interface StreamChunk {
|
|
126
|
+
token: string;
|
|
127
|
+
done: boolean;
|
|
128
|
+
results?: SearchResult[];
|
|
129
|
+
citations?: any;
|
|
130
|
+
evaluation?: any;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** A pipeline returned by {@link createRagPipeline}. */
|
|
74
134
|
export interface Pipeline {
|
|
75
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Answer one query: (embed) → retrieve → (filter) → (rerank) → generate →
|
|
137
|
+
* (citations, evaluation). Resolves a {@link PipelineRunResult}, or with
|
|
138
|
+
* `options.stream` an async iterable of {@link StreamChunk}.
|
|
139
|
+
*/
|
|
140
|
+
run(options: PipelineRunOptions & { options: { stream: true } }): Promise<PipelineRunResult | AsyncIterable<StreamChunk>>;
|
|
141
|
+
/** Answer one query; see the streaming overload above. */
|
|
142
|
+
run(options?: PipelineRunOptions & { options?: { stream?: false } }): Promise<PipelineRunResult>;
|
|
143
|
+
/** Answer one query; with `options.stream` it may resolve a stream. */
|
|
144
|
+
run(options?: PipelineRunOptions): Promise<PipelineRunResult | AsyncIterable<StreamChunk>>;
|
|
145
|
+
/** Does nothing; kept for compatibility. */
|
|
76
146
|
cleanup(): void;
|
|
77
147
|
/** Hits, misses and skips per cache layer; null without a cache. */
|
|
78
148
|
cacheStats(): {
|
|
@@ -82,36 +152,53 @@ export interface Pipeline {
|
|
|
82
152
|
} | null;
|
|
83
153
|
}
|
|
84
154
|
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated loadConfig takes a path, not an options object. This type is
|
|
157
|
+
* unused and will be removed in the next major release.
|
|
158
|
+
*/
|
|
85
159
|
export interface LoadConfigOptions {
|
|
86
160
|
configPath?: string;
|
|
87
161
|
validate?: boolean;
|
|
88
162
|
}
|
|
89
163
|
|
|
90
164
|
// =============================================================================
|
|
91
|
-
//
|
|
165
|
+
// Documents and results
|
|
92
166
|
// =============================================================================
|
|
93
167
|
|
|
168
|
+
/** A document as stored in a retriever. */
|
|
94
169
|
export interface Document {
|
|
95
170
|
id: string;
|
|
96
171
|
content: string;
|
|
97
172
|
metadata?: Record<string, any>;
|
|
173
|
+
/** The document's embedding (the built-in stores call it `vector`). */
|
|
174
|
+
vector?: number[];
|
|
175
|
+
/** @deprecated Use `vector`; the built-in stores do not read `embedding`. */
|
|
98
176
|
embedding?: number[];
|
|
99
177
|
}
|
|
100
178
|
|
|
179
|
+
/** A retrieved document, as the built-in retrievers return it. */
|
|
101
180
|
export interface SearchResult {
|
|
102
181
|
id: string;
|
|
182
|
+
/** Similarity; higher is closer. */
|
|
103
183
|
score: number;
|
|
104
|
-
|
|
184
|
+
content?: string;
|
|
105
185
|
metadata?: Record<string, any>;
|
|
186
|
+
[key: string]: any;
|
|
106
187
|
}
|
|
107
188
|
|
|
189
|
+
/** What the pipeline passes to {@link RetrieverPlugin.retrieve}. */
|
|
108
190
|
export interface RetrieveOptions {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
191
|
+
query?: string;
|
|
192
|
+
queryVector?: number[];
|
|
193
|
+
topK: number;
|
|
194
|
+
signal?: AbortSignal;
|
|
113
195
|
}
|
|
114
196
|
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated The pipeline reads `llm.generate()` as a string; an object
|
|
199
|
+
* like this becomes "[object Object]". Return the answer text instead. This
|
|
200
|
+
* type will be removed in the next major release.
|
|
201
|
+
*/
|
|
115
202
|
export interface LLMResponse {
|
|
116
203
|
text: string;
|
|
117
204
|
usage?: {
|
|
@@ -123,33 +210,134 @@ export interface LLMResponse {
|
|
|
123
210
|
}
|
|
124
211
|
|
|
125
212
|
// =============================================================================
|
|
126
|
-
// Plugin
|
|
213
|
+
// Plugin contracts: what createRagPipeline calls on each component
|
|
127
214
|
// =============================================================================
|
|
128
215
|
|
|
216
|
+
/** A loader. To register it with pluginRegistry it needs `metadata: { name, version, type: "loader" }`. */
|
|
129
217
|
export interface LoaderPlugin {
|
|
130
|
-
load(
|
|
218
|
+
/** The pipeline calls `load()` with no arguments at the start of each run and ignores the result. */
|
|
219
|
+
load(source?: string, options?: any): unknown;
|
|
131
220
|
}
|
|
132
221
|
|
|
222
|
+
/** An embedding returned by an embedder: a vector, a batch whose first vector is used, or `[{ values | vector | embedding }]`. */
|
|
223
|
+
export type EmbeddingOutput =
|
|
224
|
+
| number[]
|
|
225
|
+
| number[][]
|
|
226
|
+
| Array<{ values?: number[]; vector?: number[]; embedding?: number[] }>;
|
|
227
|
+
|
|
228
|
+
/** An embedder. To register it with pluginRegistry it needs `metadata: { name, version, type: "embedder" }`. */
|
|
133
229
|
export interface EmbedderPlugin {
|
|
134
|
-
|
|
230
|
+
/** Embeds one text. Used for the query when `embedQuery` is absent. */
|
|
231
|
+
embed(text: string, options?: { signal?: AbortSignal; [key: string]: any }): EmbeddingOutput | Promise<EmbeddingOutput>;
|
|
232
|
+
/** Embeds a query; preferred over `embed` when present. */
|
|
233
|
+
embedQuery?(text: string, options?: { signal?: AbortSignal; [key: string]: any }): EmbeddingOutput | Promise<EmbeddingOutput>;
|
|
135
234
|
}
|
|
136
235
|
|
|
236
|
+
/** A retriever. To register it with pluginRegistry it needs `store()` and `metadata: { name, version, type: "retriever" }`. */
|
|
137
237
|
export interface RetrieverPlugin {
|
|
138
|
-
|
|
238
|
+
/** Returns up to `topK` documents for the query, closest first. */
|
|
239
|
+
retrieve(options: RetrieveOptions): SearchResult[] | Promise<SearchResult[]>;
|
|
240
|
+
/** Adds documents. Not called by the pipeline; required by pluginRegistry and the CLI. */
|
|
241
|
+
store?(documents: Document[]): unknown;
|
|
139
242
|
}
|
|
140
243
|
|
|
244
|
+
/** An LLM. To register it with pluginRegistry it needs `metadata: { name, version, type: "llm" }`. */
|
|
141
245
|
export interface LLMPlugin {
|
|
142
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Answers the query from the retrieved documents. Must resolve to the
|
|
248
|
+
* answer text: the pipeline converts the result with `String()`.
|
|
249
|
+
* `options` is the run's `options` plus its AbortSignal.
|
|
250
|
+
*/
|
|
251
|
+
generate(query: string, documents: SearchResult[], options?: { signal?: AbortSignal; [key: string]: any }): string | Promise<string>;
|
|
252
|
+
/** Streams the answer; used with `options.stream` when present, otherwise `generate` is yielded as one chunk. */
|
|
253
|
+
generateStream?(query: string, documents: SearchResult[], options?: { signal?: AbortSignal; [key: string]: any }): AsyncIterable<string | { token: string; done?: boolean }>;
|
|
143
254
|
}
|
|
144
255
|
|
|
256
|
+
/** A reranker. To register it with pluginRegistry it needs `metadata: { name, version, type: "reranker" }`. */
|
|
145
257
|
export interface RerankerPlugin {
|
|
146
|
-
|
|
258
|
+
/** Reorders (and may trim) the retrieved documents for the query. */
|
|
259
|
+
rerank(query: string, documents: SearchResult[], options?: { topK?: number; signal?: AbortSignal }): SearchResult[] | Promise<SearchResult[]>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The interface of {@link pluginRegistry}. */
|
|
263
|
+
export interface PluginRegistry {
|
|
264
|
+
/**
|
|
265
|
+
* Registers a plugin after checking it against its type's contract and,
|
|
266
|
+
* when signature verification is enabled, its signed manifest.
|
|
267
|
+
* Types: loader, embedder, retriever, reranker, llm, evaluator.
|
|
268
|
+
*/
|
|
269
|
+
register(type: string, name: string, implementation: any, manifest?: any, options?: { content?: any }): Promise<PluginRegistry>;
|
|
270
|
+
/** Returns a registered plugin; throws when it is not registered. */
|
|
271
|
+
get(type: string, name: string): any;
|
|
272
|
+
/** The names registered for a type. */
|
|
273
|
+
list(type: string): string[];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** The interface of the `logger` export's methods and of `logger.logger`. */
|
|
277
|
+
export interface Logger {
|
|
278
|
+
/** Logs at info level; `meta` may be an object, an Error or a value. */
|
|
279
|
+
info(message: string, meta?: any): void;
|
|
280
|
+
/** Logs at error level. */
|
|
281
|
+
error(message: string, meta?: any): void;
|
|
282
|
+
/** Logs at warn level. */
|
|
283
|
+
warn(message: string, meta?: any): void;
|
|
284
|
+
/** Logs at debug level. */
|
|
285
|
+
debug(message: string, meta?: any): void;
|
|
147
286
|
}
|
|
148
287
|
|
|
288
|
+
/** An error created by {@link createError} or {@link wrapError}. */
|
|
289
|
+
export interface EnhancedError extends Error {
|
|
290
|
+
code: string;
|
|
291
|
+
context: Record<string, any>;
|
|
292
|
+
suggestions: string[];
|
|
293
|
+
documentation?: string;
|
|
294
|
+
originalError?: Error | null;
|
|
295
|
+
timestamp: string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// =============================================================================
|
|
299
|
+
// Pipeline factory and errors
|
|
300
|
+
// =============================================================================
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Creates a RAG pipeline from components: plugin objects, or names
|
|
304
|
+
* registered in the registry. A name that is not registered throws here.
|
|
305
|
+
*/
|
|
306
|
+
export function createRagPipeline(config?: RagPipelineConfig): Pipeline;
|
|
307
|
+
export { createRagPipeline as createPipeline };
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Creates an error whose message and suggestions come from the code's
|
|
311
|
+
* template, with `{placeholders}` filled from `context`.
|
|
312
|
+
* @param code - One of {@link ERROR_CODES}
|
|
313
|
+
* @param context - Values for the message template's placeholders
|
|
314
|
+
* @param originalError - The underlying error, kept as `originalError`
|
|
315
|
+
*/
|
|
316
|
+
export function createError(code: string, context?: Record<string, any>, originalError?: Error | null): EnhancedError;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Wraps an error in an EnhancedError with the given code, keeping the
|
|
320
|
+
* original as `originalError` and its message as `context.originalMessage`.
|
|
321
|
+
* @param error - The error to wrap
|
|
322
|
+
* @param code - One of {@link ERROR_CODES}
|
|
323
|
+
* @param context - Values for the message template's placeholders
|
|
324
|
+
*/
|
|
325
|
+
export function wrapError(error: Error, code: string, context?: Record<string, any>): EnhancedError;
|
|
326
|
+
|
|
327
|
+
/** The error codes {@link createError} accepts; each key equals its value. */
|
|
328
|
+
export const ERROR_CODES: Record<string, string>;
|
|
329
|
+
|
|
330
|
+
/** The DAG class under its older name. */
|
|
331
|
+
export { DAG as DAGEngine } from "./types/dag/dag-engine";
|
|
332
|
+
|
|
333
|
+
/** The same function as loadRagConfig. */
|
|
334
|
+
export { loadRagConfig as loadConfig } from "./types/config/load-config";
|
|
335
|
+
|
|
149
336
|
// =============================================================================
|
|
150
|
-
//
|
|
337
|
+
// Deprecated types (kept so code that imports them still compiles)
|
|
151
338
|
// =============================================================================
|
|
152
339
|
|
|
340
|
+
/** @deprecated Not what DAG.addNode reads; see the DAG class. This type will be removed in the next major release. */
|
|
153
341
|
export interface DAGNode {
|
|
154
342
|
id: string;
|
|
155
343
|
run: (input: any) => Promise<any>;
|
|
@@ -160,6 +348,7 @@ export interface DAGNode {
|
|
|
160
348
|
retryDelay?: number;
|
|
161
349
|
}
|
|
162
350
|
|
|
351
|
+
/** @deprecated See DAG.execute for the options it reads. This type will be removed in the next major release. */
|
|
163
352
|
export interface DAGOptions {
|
|
164
353
|
timeout?: number;
|
|
165
354
|
concurrency?: number;
|
|
@@ -170,24 +359,7 @@ export interface DAGOptions {
|
|
|
170
359
|
maxRetries?: number;
|
|
171
360
|
}
|
|
172
361
|
|
|
173
|
-
|
|
174
|
-
// Utility Types
|
|
175
|
-
// =============================================================================
|
|
176
|
-
|
|
177
|
-
export interface PluginRegistry {
|
|
178
|
-
register(type: string, name: string, implementation: any, contract?: any): void;
|
|
179
|
-
get(type: string, name: string): any;
|
|
180
|
-
has(type: string, name: string): boolean;
|
|
181
|
-
list(type: string): any[];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export interface Logger {
|
|
185
|
-
info(message: string, meta?: any): void;
|
|
186
|
-
error(message: string, meta?: any): void;
|
|
187
|
-
warn(message: string, meta?: any): void;
|
|
188
|
-
debug(message: string, meta?: any): void;
|
|
189
|
-
}
|
|
190
|
-
|
|
362
|
+
/** @deprecated Does not describe the errorFormatter export; see createError and wrapError. This type will be removed in the next major release. */
|
|
191
363
|
export interface ErrorFormatter {
|
|
192
364
|
formatError(error: Error): string;
|
|
193
365
|
createError(code: string, message: string, details?: any): Error;
|
|
@@ -195,10 +367,7 @@ export interface ErrorFormatter {
|
|
|
195
367
|
ERROR_CODES: Record<string, string>;
|
|
196
368
|
}
|
|
197
369
|
|
|
198
|
-
|
|
199
|
-
// Evaluation Types
|
|
200
|
-
// =============================================================================
|
|
201
|
-
|
|
370
|
+
/** @deprecated evaluateRagDataset returns `{ prompt, expected, actual, success, scores: { bleu, rouge } }`. This type will be removed in the next major release. */
|
|
202
371
|
export interface EvalResult {
|
|
203
372
|
question: string;
|
|
204
373
|
expected: string;
|
|
@@ -209,121 +378,7 @@ export interface EvalResult {
|
|
|
209
378
|
}
|
|
210
379
|
|
|
211
380
|
// =============================================================================
|
|
212
|
-
//
|
|
213
|
-
// =============================================================================
|
|
214
|
-
|
|
215
|
-
export function createRagPipeline(config: RagPipelineConfig): Pipeline;
|
|
216
|
-
export { createRagPipeline as createPipeline };
|
|
217
|
-
|
|
218
|
-
// Configuration
|
|
219
|
-
export function loadConfig(options?: LoadConfigOptions): Promise<RagPipelineConfig>;
|
|
220
|
-
export { loadConfig as loadRagConfig };
|
|
221
|
-
export function validateRagrc(config: any): boolean;
|
|
222
|
-
export function normalizeConfig(config: any): RagPipelineConfig;
|
|
223
|
-
|
|
224
|
-
// Plugin system
|
|
225
|
-
export const pluginRegistry: PluginRegistry;
|
|
226
|
-
|
|
227
|
-
// Utilities
|
|
228
|
-
export const logger: Logger;
|
|
229
|
-
export const errorFormatter: ErrorFormatter;
|
|
230
|
-
export function createError(code: string, message: string, details?: any): Error;
|
|
231
|
-
export function wrapError(error: Error, context: string): Error;
|
|
232
|
-
export const ERROR_CODES: Record<string, string>;
|
|
233
|
-
|
|
234
|
-
// =============================================================================
|
|
235
|
-
// Utility Classes
|
|
236
|
-
// =============================================================================
|
|
237
|
-
|
|
238
|
-
export class BatchProcessor {
|
|
239
|
-
constructor(options?: {
|
|
240
|
-
batchSize?: number;
|
|
241
|
-
maxConcurrent?: number;
|
|
242
|
-
retryAttempts?: number;
|
|
243
|
-
onProgress?: (progress: any) => void;
|
|
244
|
-
[key: string]: any;
|
|
245
|
-
});
|
|
246
|
-
process(items: any[], handler: (batch: any[]) => Promise<any[]>): Promise<any[]>;
|
|
247
|
-
cancel(): void;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export class RateLimiter {
|
|
251
|
-
constructor(options?: {
|
|
252
|
-
maxRequests?: number;
|
|
253
|
-
windowMs?: number;
|
|
254
|
-
[key: string]: any;
|
|
255
|
-
});
|
|
256
|
-
tryAcquire(identifier?: string): boolean;
|
|
257
|
-
reset(identifier?: string): void;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function retry<T>(fn: () => Promise<T>, options?: {
|
|
261
|
-
maxAttempts?: number;
|
|
262
|
-
delay?: number;
|
|
263
|
-
backoff?: number;
|
|
264
|
-
retryIf?: (error: Error) => boolean;
|
|
265
|
-
}): Promise<T>;
|
|
266
|
-
|
|
267
|
-
export function withRetry<T>(fn: () => Promise<T>, options?: {
|
|
268
|
-
maxAttempts?: number;
|
|
269
|
-
delay?: number;
|
|
270
|
-
backoff?: number;
|
|
271
|
-
}): Promise<T>;
|
|
272
|
-
|
|
273
|
-
export class ConnectionPoolManager {
|
|
274
|
-
constructor(options?: {
|
|
275
|
-
maxSockets?: number;
|
|
276
|
-
maxFreeSockets?: number;
|
|
277
|
-
timeout?: number;
|
|
278
|
-
[key: string]: any;
|
|
279
|
-
});
|
|
280
|
-
getPool(hostname: string): any;
|
|
281
|
-
getMetrics(): any;
|
|
282
|
-
destroy(): void;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// =============================================================================
|
|
286
|
-
// Security
|
|
287
|
-
// =============================================================================
|
|
288
|
-
|
|
289
|
-
export class JWTValidator {
|
|
290
|
-
constructor(options?: {
|
|
291
|
-
secret?: string;
|
|
292
|
-
algorithms?: string[];
|
|
293
|
-
issuer?: string;
|
|
294
|
-
audience?: string;
|
|
295
|
-
clockTolerance?: number;
|
|
296
|
-
maxAge?: string;
|
|
297
|
-
[key: string]: any;
|
|
298
|
-
});
|
|
299
|
-
sign(payload: any, options?: any): string;
|
|
300
|
-
verify(token: string, options?: any): any;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/** @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. */
|
|
304
|
-
export class PluginSandbox {
|
|
305
|
-
constructor(options?: {
|
|
306
|
-
memoryLimit?: number;
|
|
307
|
-
timeout?: number;
|
|
308
|
-
permissions?: string[];
|
|
309
|
-
[key: string]: any;
|
|
310
|
-
});
|
|
311
|
-
execute(code: string, context?: any): Promise<any>;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
export class PluginSignatureVerifier {
|
|
315
|
-
constructor(options?: {
|
|
316
|
-
trustedKeysPath?: string;
|
|
317
|
-
failClosed?: boolean;
|
|
318
|
-
[key: string]: any;
|
|
319
|
-
});
|
|
320
|
-
verify(pluginPath: string): Promise<boolean>;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export function validateInput(input: string, options?: any): { valid: boolean; errors?: string[] };
|
|
324
|
-
|
|
325
|
-
// =============================================================================
|
|
326
|
-
// AI/ML
|
|
381
|
+
// Experimental (also exported from ./experimental)
|
|
327
382
|
// =============================================================================
|
|
328
383
|
|
|
329
384
|
/** @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. */
|
|
@@ -358,65 +413,6 @@ export class ModelTrainingOrchestrator {
|
|
|
358
413
|
deployModel(jobId: string, deployConfig: any): Promise<any>;
|
|
359
414
|
}
|
|
360
415
|
|
|
361
|
-
// =============================================================================
|
|
362
|
-
// Workflow Engine
|
|
363
|
-
// =============================================================================
|
|
364
|
-
|
|
365
|
-
export class DAGEngine {
|
|
366
|
-
constructor(options?: DAGOptions);
|
|
367
|
-
addNode(id: string, fn: (input: any) => Promise<any>, options?: Partial<DAGNode>): void;
|
|
368
|
-
connect(fromId: string, toId: string): void;
|
|
369
|
-
execute(seed?: any, options?: DAGOptions): Promise<Map<string, any>>;
|
|
370
|
-
validate(): void;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export { DAGEngine as DAG };
|
|
374
|
-
|
|
375
|
-
// =============================================================================
|
|
376
|
-
// Evaluation
|
|
377
|
-
// =============================================================================
|
|
378
|
-
|
|
379
|
-
export function evaluateRagDataset(dataset: Array<{
|
|
380
|
-
question: string;
|
|
381
|
-
expected: string;
|
|
382
|
-
actual: string;
|
|
383
|
-
}>): EvalResult[];
|
|
384
|
-
|
|
385
|
-
export function scoreAnswer(expected: string, actual: string): number;
|
|
386
|
-
export function computeBLEU(reference: string, hypothesis: string): number;
|
|
387
|
-
export function computeROUGE(reference: string, hypothesis: string): number;
|
|
388
|
-
|
|
389
|
-
// =============================================================================
|
|
390
|
-
// Performance & Observability
|
|
391
|
-
// =============================================================================
|
|
392
|
-
|
|
393
|
-
export class ParallelProcessor {
|
|
394
|
-
constructor(options?: any);
|
|
395
|
-
process(items: any[], handler: (item: any) => Promise<any>): Promise<any[]>;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export const eventLogger: {
|
|
399
|
-
log(event: string, data?: any): void;
|
|
400
|
-
info(event: string, data?: any): void;
|
|
401
|
-
error(event: string, data?: any): void;
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
export const metrics: {
|
|
405
|
-
counter(name: string): { inc(): void };
|
|
406
|
-
timer(name: string): { end(): void };
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// =============================================================================
|
|
410
|
-
// Enterprise
|
|
411
|
-
// =============================================================================
|
|
412
|
-
|
|
413
|
-
export class AuditLogger {
|
|
414
|
-
constructor(options?: any);
|
|
415
|
-
logAuthentication(event: any): Promise<void>;
|
|
416
|
-
logDataAccess(event: any): Promise<void>;
|
|
417
|
-
logDataModification(event: any): Promise<void>;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
416
|
/** @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. */
|
|
421
417
|
export class DataGovernance {
|
|
422
418
|
constructor(options?: any);
|
|
@@ -475,21 +471,15 @@ export class OIDCProvider {
|
|
|
475
471
|
authenticate(request: any): Promise<any>;
|
|
476
472
|
}
|
|
477
473
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
export class PluginAnalytics {
|
|
490
|
-
constructor(options?: any);
|
|
491
|
-
trackDownload(pluginName: string): void;
|
|
492
|
-
getStats(pluginName: string): any;
|
|
474
|
+
/** @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. */
|
|
475
|
+
export class PluginSandbox {
|
|
476
|
+
constructor(options?: {
|
|
477
|
+
memoryLimit?: number;
|
|
478
|
+
timeout?: number;
|
|
479
|
+
permissions?: string[];
|
|
480
|
+
[key: string]: any;
|
|
481
|
+
});
|
|
482
|
+
execute(code: string, context?: any): Promise<any>;
|
|
493
483
|
}
|
|
494
484
|
|
|
495
485
|
/** @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. */
|
|
@@ -499,40 +489,43 @@ export class PluginCertification {
|
|
|
499
489
|
verify(pluginName: string): Promise<boolean>;
|
|
500
490
|
}
|
|
501
491
|
|
|
502
|
-
export class PluginAnalyticsDashboard {
|
|
503
|
-
constructor(options?: any);
|
|
504
|
-
generateReport(options?: any): Promise<any>;
|
|
505
|
-
getMetrics(): any;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// =============================================================================
|
|
509
|
-
// Development Tools
|
|
510
|
-
// =============================================================================
|
|
511
|
-
|
|
512
|
-
export class HotReloadManager {
|
|
513
|
-
constructor(options?: any);
|
|
514
|
-
watch(paths: string[]): void;
|
|
515
|
-
stop(): void;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
export function createHotReloadManager(options?: any): HotReloadManager;
|
|
519
|
-
|
|
520
|
-
export class DevServer {
|
|
521
|
-
constructor(options?: any);
|
|
522
|
-
start(port?: number): Promise<void>;
|
|
523
|
-
stop(): Promise<void>;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
export function createDevServer(options?: any): DevServer;
|
|
527
|
-
|
|
528
492
|
// =============================================================================
|
|
529
493
|
// Declarations generated from JSDoc (scripts/generate-types.js)
|
|
530
494
|
// =============================================================================
|
|
495
|
+
export { loadRagConfig } from "./types/config/load-config";
|
|
496
|
+
export { validateRagrc } from "./types/config/enhanced-ragrc-schema";
|
|
497
|
+
export { normalizeConfig } from "./types/config/normalize-config";
|
|
498
|
+
import pluginRegistry = require("./types/core/plugin-registry");
|
|
499
|
+
export { pluginRegistry };
|
|
531
500
|
export { validatePlugin } from "./types/core/validate-plugin";
|
|
501
|
+
import logger = require("./types/utils/logger");
|
|
502
|
+
export { logger };
|
|
503
|
+
import errorFormatter = require("./types/utils/error-formatter");
|
|
504
|
+
export { errorFormatter };
|
|
505
|
+
export { BatchProcessor } from "./types/utils/batch-processor";
|
|
506
|
+
import RateLimiter = require("./types/utils/rate-limiter");
|
|
507
|
+
export { RateLimiter };
|
|
508
|
+
export { retry } from "./types/utils/retry";
|
|
509
|
+
export { withRetry } from "./types/utils/retry";
|
|
510
|
+
export { ConnectionPoolManager } from "./types/utils/connection-pool";
|
|
511
|
+
export { JWTValidator } from "./types/security/jwt-validator";
|
|
512
|
+
export { PluginSignatureVerifier } from "./types/security/plugin-signature-verifier";
|
|
513
|
+
export { validateInput } from "./types/security/validator";
|
|
514
|
+
export { DAG } from "./types/dag/dag-engine";
|
|
515
|
+
export { evaluateRagDataset } from "./types/evaluate/evaluator";
|
|
516
|
+
export { scoreAnswer } from "./types/evaluate/scoring";
|
|
517
|
+
export { computeBLEU } from "./types/evaluate/scoring";
|
|
518
|
+
export { computeROUGE } from "./types/evaluate/scoring";
|
|
532
519
|
export { checkNumericConsistency } from "./types/evaluate/scoring";
|
|
533
520
|
export { extractNumbers } from "./types/evaluate/scoring";
|
|
534
521
|
export { computeFaithfulness } from "./types/evaluate/faithfulness";
|
|
535
522
|
export { computeSemanticSimilarity } from "./types/evaluate/semantic-similarity";
|
|
523
|
+
export { validateDataset } from "./types/evaluate/dataset";
|
|
524
|
+
export { generateSyntheticDataset } from "./types/evaluate/synthetic";
|
|
525
|
+
export { runEvaluation } from "./types/evaluate/compare";
|
|
526
|
+
export { compareConfigurations } from "./types/evaluate/compare";
|
|
527
|
+
export { evaluationVerdict } from "./types/evaluate/report";
|
|
528
|
+
export { renderEvaluationReport } from "./types/evaluate/report";
|
|
536
529
|
export { computeAnswerRelevance } from "./types/evaluate/relevance";
|
|
537
530
|
export { computeContextPrecision } from "./types/evaluate/context-metrics";
|
|
538
531
|
export { computeContextRecall } from "./types/evaluate/context-metrics";
|
|
@@ -578,6 +571,8 @@ export { BaseConnector } from "./types/connectors/base-connector";
|
|
|
578
571
|
export { OllamaConnector } from "./types/connectors/ollama-connector";
|
|
579
572
|
export { LocalEmbedder } from "./types/connectors/local-embedder";
|
|
580
573
|
export { MemoryRetriever } from "./types/connectors/memory-retriever";
|
|
574
|
+
export { PgVectorRetriever } from "./types/retrieval/pgvector-retriever";
|
|
575
|
+
export { QdrantRetriever } from "./types/retrieval/qdrant-retriever";
|
|
581
576
|
export { OpenAIConnector } from "./types/connectors/openai-connector";
|
|
582
577
|
export { AnthropicConnector } from "./types/connectors/anthropic-connector";
|
|
583
578
|
export { CohereConnector } from "./types/connectors/cohere-connector";
|
|
@@ -592,3 +587,17 @@ export { GraphRetriever } from "./types/graph/graph-retriever";
|
|
|
592
587
|
export { GraphIndex } from "./types/graph/graph-index";
|
|
593
588
|
export { DashboardGenerator } from "./types/dashboard/dashboard-generator";
|
|
594
589
|
export { MetricsAggregator } from "./types/dashboard/metrics-aggregator";
|
|
590
|
+
import ParallelProcessor = require("./types/core/performance/parallel-processor");
|
|
591
|
+
export { ParallelProcessor };
|
|
592
|
+
import eventLogger = require("./types/core/observability/event-logger");
|
|
593
|
+
export { eventLogger };
|
|
594
|
+
import metrics = require("./types/core/observability/metrics");
|
|
595
|
+
export { metrics };
|
|
596
|
+
export { AuditLogger } from "./types/enterprise/audit-logging";
|
|
597
|
+
export { PluginHub } from "./types/ecosystem/plugin-hub";
|
|
598
|
+
export { PluginAnalytics } from "./types/ecosystem/plugin-hub";
|
|
599
|
+
export { PluginAnalyticsDashboard } from "./types/ecosystem/plugin-analytics-dashboard";
|
|
600
|
+
export { HotReloadManager } from "./types/dev/hot-reload";
|
|
601
|
+
export { createHotReloadManager } from "./types/dev/hot-reload";
|
|
602
|
+
export { DevServer } from "./types/dev/dev-server";
|
|
603
|
+
export { createDevServer } from "./types/dev/dev-server";
|