@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
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
/** Monotonic counter that only goes up until reset. */
|
|
2
|
+
export class Counter {
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} name - Metric name
|
|
5
|
+
* @param {string} [description=''] - Human-readable description
|
|
6
|
+
* @param {Object<string, string>} [labels={}] - Static labels attached to the metric
|
|
7
|
+
*/
|
|
8
|
+
constructor(name: string, description?: string, labels?: {
|
|
9
|
+
[x: string]: string;
|
|
10
|
+
});
|
|
11
|
+
_type: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
labels: {
|
|
15
|
+
[x: string]: string;
|
|
16
|
+
};
|
|
17
|
+
value: number;
|
|
18
|
+
/**
|
|
19
|
+
* Add to the counter.
|
|
20
|
+
* @param {number} [n=1] - Amount to add
|
|
21
|
+
* @returns {void}
|
|
22
|
+
* @throws {Error} If n is negative
|
|
23
|
+
*/
|
|
24
|
+
inc(n?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Set the value back to 0.
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*/
|
|
29
|
+
reset(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Snapshot of the metric with the current time as timestamp.
|
|
32
|
+
* @returns {{name: string, description: string, type: string, value: number, labels: Object<string, string>, timestamp: string}}
|
|
33
|
+
*/
|
|
34
|
+
toJSON(): {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
type: string;
|
|
38
|
+
value: number;
|
|
39
|
+
labels: {
|
|
40
|
+
[x: string]: string;
|
|
41
|
+
};
|
|
42
|
+
timestamp: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Histogram with cumulative bucket counts. It also keeps every observed value
|
|
47
|
+
* in memory to compute percentiles and standard deviation.
|
|
48
|
+
*/
|
|
49
|
+
export class Histogram {
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} name - Metric name
|
|
52
|
+
* @param {string} [description=''] - Human-readable description
|
|
53
|
+
* @param {Object<string, string>} [labels={}] - Static labels attached to the metric
|
|
54
|
+
* @param {number[]} [buckets] - Bucket upper bounds, sorted ascending on construction. A +Inf bucket is added.
|
|
55
|
+
*/
|
|
56
|
+
constructor(name: string, description?: string, labels?: {
|
|
57
|
+
[x: string]: string;
|
|
58
|
+
}, buckets?: number[]);
|
|
59
|
+
_type: string;
|
|
60
|
+
name: string;
|
|
61
|
+
description: string;
|
|
62
|
+
labels: {
|
|
63
|
+
[x: string]: string;
|
|
64
|
+
};
|
|
65
|
+
buckets: number[];
|
|
66
|
+
bucketCounts: any[];
|
|
67
|
+
sum: number;
|
|
68
|
+
count: number;
|
|
69
|
+
min: number;
|
|
70
|
+
max: number;
|
|
71
|
+
_obs: any[];
|
|
72
|
+
/**
|
|
73
|
+
* Record a value. Non-numbers and NaN are ignored.
|
|
74
|
+
* @param {number} v - Observed value
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
observe(v: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Percentiles of the observed values by the nearest-rank method. Returns 0
|
|
80
|
+
* for each percentile when nothing has been observed.
|
|
81
|
+
* @param {number[]} [percentiles=[50, 95, 99]] - Percentiles to compute, 0-100
|
|
82
|
+
* @returns {Object<number, number>} Value for each requested percentile
|
|
83
|
+
*/
|
|
84
|
+
getPercentiles(percentiles?: number[]): {
|
|
85
|
+
[x: number]: number;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Mean, population standard deviation, min, max, count and sum of the
|
|
89
|
+
* observed values. With no observations, min is Infinity and max is -Infinity.
|
|
90
|
+
* @returns {{mean: number, stdDev: number, min: number, max: number, count: number, sum: number}}
|
|
91
|
+
*/
|
|
92
|
+
getStatistics(): {
|
|
93
|
+
mean: number;
|
|
94
|
+
stdDev: number;
|
|
95
|
+
min: number;
|
|
96
|
+
max: number;
|
|
97
|
+
count: number;
|
|
98
|
+
sum: number;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Clear all bucket counts, statistics and stored observations.
|
|
102
|
+
* @returns {void}
|
|
103
|
+
*/
|
|
104
|
+
reset(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Cumulative count per bucket bound (plus '+Inf') together with getStatistics().
|
|
107
|
+
* @returns {{buckets: Object<string, number>, mean: number, stdDev: number, min: number, max: number, count: number, sum: number}}
|
|
108
|
+
*/
|
|
109
|
+
export(): {
|
|
110
|
+
buckets: {
|
|
111
|
+
[x: string]: number;
|
|
112
|
+
};
|
|
113
|
+
mean: number;
|
|
114
|
+
stdDev: number;
|
|
115
|
+
min: number;
|
|
116
|
+
max: number;
|
|
117
|
+
count: number;
|
|
118
|
+
sum: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Snapshot of the histogram with the current time as timestamp. Does not
|
|
122
|
+
* include min, max or percentiles.
|
|
123
|
+
* @returns {{name: string, description: string, type: string, count: number, sum: number, buckets: number[], bucketCounts: number[], labels: Object<string, string>, timestamp: string}}
|
|
124
|
+
*/
|
|
125
|
+
toJSON(): {
|
|
126
|
+
name: string;
|
|
127
|
+
description: string;
|
|
128
|
+
type: string;
|
|
129
|
+
count: number;
|
|
130
|
+
sum: number;
|
|
131
|
+
buckets: number[];
|
|
132
|
+
bucketCounts: number[];
|
|
133
|
+
labels: {
|
|
134
|
+
[x: string]: string;
|
|
135
|
+
};
|
|
136
|
+
timestamp: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Gauge holding a value that can be set, raised or lowered. */
|
|
140
|
+
export class Gauge {
|
|
141
|
+
/**
|
|
142
|
+
* @param {string} name - Metric name
|
|
143
|
+
* @param {string} [description=''] - Human-readable description
|
|
144
|
+
* @param {Object<string, string>} [labels={}] - Static labels attached to the metric
|
|
145
|
+
*/
|
|
146
|
+
constructor(name: string, description?: string, labels?: {
|
|
147
|
+
[x: string]: string;
|
|
148
|
+
});
|
|
149
|
+
_type: string;
|
|
150
|
+
name: string;
|
|
151
|
+
description: string;
|
|
152
|
+
labels: {
|
|
153
|
+
[x: string]: string;
|
|
154
|
+
};
|
|
155
|
+
value: number;
|
|
156
|
+
/**
|
|
157
|
+
* Set the value.
|
|
158
|
+
* @param {number} v - New value
|
|
159
|
+
* @returns {void}
|
|
160
|
+
*/
|
|
161
|
+
set(v: number): void;
|
|
162
|
+
/**
|
|
163
|
+
* Add to the value.
|
|
164
|
+
* @param {number} [n=1] - Amount to add
|
|
165
|
+
* @returns {void}
|
|
166
|
+
*/
|
|
167
|
+
inc(n?: number): void;
|
|
168
|
+
/**
|
|
169
|
+
* Subtract from the value.
|
|
170
|
+
* @param {number} [n=1] - Amount to subtract
|
|
171
|
+
* @returns {void}
|
|
172
|
+
*/
|
|
173
|
+
dec(n?: number): void;
|
|
174
|
+
/**
|
|
175
|
+
* Set the value back to 0.
|
|
176
|
+
* @returns {void}
|
|
177
|
+
*/
|
|
178
|
+
reset(): void;
|
|
179
|
+
/**
|
|
180
|
+
* Snapshot of the metric with the current time as timestamp.
|
|
181
|
+
* @returns {{name: string, description: string, type: string, value: number, labels: Object<string, string>, timestamp: string}}
|
|
182
|
+
*/
|
|
183
|
+
toJSON(): {
|
|
184
|
+
name: string;
|
|
185
|
+
description: string;
|
|
186
|
+
type: string;
|
|
187
|
+
value: number;
|
|
188
|
+
labels: {
|
|
189
|
+
[x: string]: string;
|
|
190
|
+
};
|
|
191
|
+
timestamp: string;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* In-memory totals for pipeline operations: embedding, retrieval and LLM
|
|
196
|
+
* calls, errors, operation counts, concurrency, backpressure and heap usage.
|
|
197
|
+
*/
|
|
198
|
+
export class PipelineMetrics {
|
|
199
|
+
counters: {
|
|
200
|
+
operationsTotal: Counter;
|
|
201
|
+
operationsSuccessful: Counter;
|
|
202
|
+
operationsFailed: Counter;
|
|
203
|
+
operationsActive: Counter;
|
|
204
|
+
};
|
|
205
|
+
errorsByType: {
|
|
206
|
+
plugin: number;
|
|
207
|
+
stage: number;
|
|
208
|
+
};
|
|
209
|
+
errorsByPlugin: {};
|
|
210
|
+
backpressureSamples: any[];
|
|
211
|
+
backpressureApplied: number;
|
|
212
|
+
backpressureReleased: number;
|
|
213
|
+
memory: {
|
|
214
|
+
heapUsed: number;
|
|
215
|
+
heapTotal: number;
|
|
216
|
+
usagePercentage: number;
|
|
217
|
+
};
|
|
218
|
+
embedding: {
|
|
219
|
+
operations: number;
|
|
220
|
+
totalDuration: number;
|
|
221
|
+
totalTokens: number;
|
|
222
|
+
totalBatches: number;
|
|
223
|
+
durations: any[];
|
|
224
|
+
};
|
|
225
|
+
retrieval: {
|
|
226
|
+
operations: number;
|
|
227
|
+
totalDuration: number;
|
|
228
|
+
totalResults: number;
|
|
229
|
+
durations: any[];
|
|
230
|
+
};
|
|
231
|
+
llm: {
|
|
232
|
+
operations: number;
|
|
233
|
+
totalDuration: number;
|
|
234
|
+
totalInputTokens: number;
|
|
235
|
+
totalOutputTokens: number;
|
|
236
|
+
streamingOps: number;
|
|
237
|
+
durations: any[];
|
|
238
|
+
inputTokens: any[];
|
|
239
|
+
outputTokens: any[];
|
|
240
|
+
};
|
|
241
|
+
concurrency: {
|
|
242
|
+
maxConcurrency: number;
|
|
243
|
+
concurrencyValues: any[];
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Record one embedding call.
|
|
247
|
+
* @param {string} provider - Provider name (unused)
|
|
248
|
+
* @param {number} duration - Duration in milliseconds
|
|
249
|
+
* @param {number} tokens - Tokens embedded
|
|
250
|
+
* @param {number} batches - Batches sent
|
|
251
|
+
* @returns {void}
|
|
252
|
+
*/
|
|
253
|
+
recordEmbedding(provider: string, duration: number, tokens: number, batches: number): void;
|
|
254
|
+
/**
|
|
255
|
+
* Record one retrieval call.
|
|
256
|
+
* @param {string} provider - Provider name (unused)
|
|
257
|
+
* @param {number} duration - Duration in milliseconds
|
|
258
|
+
* @param {number} results - Number of results returned
|
|
259
|
+
* @returns {void}
|
|
260
|
+
*/
|
|
261
|
+
recordRetrieval(provider: string, duration: number, results: number): void;
|
|
262
|
+
/**
|
|
263
|
+
* Record one LLM call.
|
|
264
|
+
* @param {string} provider - Provider name (unused)
|
|
265
|
+
* @param {number} duration - Duration in milliseconds
|
|
266
|
+
* @param {number} inputTokens - Prompt tokens
|
|
267
|
+
* @param {number} outputTokens - Completion tokens
|
|
268
|
+
* @param {boolean} [streaming] - Whether the call streamed its output
|
|
269
|
+
* @returns {void}
|
|
270
|
+
*/
|
|
271
|
+
recordLLM(provider: string, duration: number, inputTokens: number, outputTokens: number, streaming?: boolean): void;
|
|
272
|
+
/**
|
|
273
|
+
* Store heapUsed and heapTotal from process.memoryUsage() and the used
|
|
274
|
+
* percentage, rounded.
|
|
275
|
+
* @returns {void}
|
|
276
|
+
*/
|
|
277
|
+
recordMemoryUsage(): void;
|
|
278
|
+
/**
|
|
279
|
+
* Count an error by type and by component. Only the types 'plugin' and
|
|
280
|
+
* 'stage' are counted by type; other types are counted only by component.
|
|
281
|
+
* @param {string} type - Error type, 'plugin' or 'stage'
|
|
282
|
+
* @param {string} [component] - Plugin or component name
|
|
283
|
+
* @param {string} [provider] - Provider name (unused)
|
|
284
|
+
* @param {Error} [error] - The error (unused)
|
|
285
|
+
* @returns {void}
|
|
286
|
+
*/
|
|
287
|
+
recordError(type: string, component?: string, provider?: string, error?: Error): void;
|
|
288
|
+
/**
|
|
289
|
+
* Count an operation as started and active.
|
|
290
|
+
* @param {string} [type] - Operation type (unused)
|
|
291
|
+
* @param {string} [component] - Component name (unused)
|
|
292
|
+
* @param {string} [provider] - Provider name (unused)
|
|
293
|
+
* @returns {void}
|
|
294
|
+
*/
|
|
295
|
+
recordOperationStart(type?: string, component?: string, provider?: string): void;
|
|
296
|
+
/**
|
|
297
|
+
* Mark an active operation as finished. A status of 'error' or 'failed'
|
|
298
|
+
* counts as failed; any other status counts as successful.
|
|
299
|
+
* @param {string} [type] - Operation type (unused)
|
|
300
|
+
* @param {string} [component] - Component name (unused)
|
|
301
|
+
* @param {string} [provider] - Provider name (unused)
|
|
302
|
+
* @param {number} [duration] - Duration in milliseconds (unused)
|
|
303
|
+
* @param {string} [status] - Outcome of the operation
|
|
304
|
+
* @returns {void}
|
|
305
|
+
*/
|
|
306
|
+
recordOperationEnd(type?: string, component?: string, provider?: string, duration?: number, status?: string): void;
|
|
307
|
+
/**
|
|
308
|
+
* Record a concurrency sample. Keeps the highest max seen and every average.
|
|
309
|
+
* @param {number} maxConcurrency - Peak concurrency in the sample
|
|
310
|
+
* @param {number} avgConcurrency - Average concurrency in the sample
|
|
311
|
+
* @returns {void}
|
|
312
|
+
*/
|
|
313
|
+
recordConcurrency(maxConcurrency: number, avgConcurrency: number): void;
|
|
314
|
+
/**
|
|
315
|
+
* Count a backpressure event and keep the buffer size as a sample.
|
|
316
|
+
* @param {string} action - 'applied' or 'released'; other values are not counted
|
|
317
|
+
* @param {number} [bufferSize] - Buffer size at the time of the event
|
|
318
|
+
* @param {number} [threshold] - Backpressure threshold (unused)
|
|
319
|
+
* @returns {void}
|
|
320
|
+
*/
|
|
321
|
+
recordBackpressure(action: string, bufferSize?: number, threshold?: number): void;
|
|
322
|
+
/**
|
|
323
|
+
* Totals and averages for every recorded category. Averages are 0 when
|
|
324
|
+
* nothing was recorded.
|
|
325
|
+
* @returns Summary grouped by embedding, retrieval, llm, memory, errors, operations, concurrency and backpressure
|
|
326
|
+
*/
|
|
327
|
+
getSummary(): {
|
|
328
|
+
embedding: {
|
|
329
|
+
totalOperations: number;
|
|
330
|
+
totalDuration: number;
|
|
331
|
+
totalTokens: number;
|
|
332
|
+
totalBatches: number;
|
|
333
|
+
avgDuration: {
|
|
334
|
+
mean: number;
|
|
335
|
+
};
|
|
336
|
+
};
|
|
337
|
+
retrieval: {
|
|
338
|
+
totalOperations: number;
|
|
339
|
+
totalResults: number;
|
|
340
|
+
avgDuration: {
|
|
341
|
+
mean: number;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
llm: {
|
|
345
|
+
totalOperations: number;
|
|
346
|
+
streamingOperations: number;
|
|
347
|
+
avgDuration: {
|
|
348
|
+
mean: number;
|
|
349
|
+
};
|
|
350
|
+
avgInputTokens: {
|
|
351
|
+
mean: number;
|
|
352
|
+
};
|
|
353
|
+
avgOutputTokens: {
|
|
354
|
+
mean: number;
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
memory: {
|
|
358
|
+
heapUsed: number;
|
|
359
|
+
heapTotal: number;
|
|
360
|
+
usagePercentage: number;
|
|
361
|
+
};
|
|
362
|
+
errors: {
|
|
363
|
+
total: number;
|
|
364
|
+
byType: {
|
|
365
|
+
plugin: number;
|
|
366
|
+
stage: number;
|
|
367
|
+
};
|
|
368
|
+
byPlugin: {};
|
|
369
|
+
};
|
|
370
|
+
operations: {
|
|
371
|
+
total: number;
|
|
372
|
+
successful: number;
|
|
373
|
+
failed: number;
|
|
374
|
+
};
|
|
375
|
+
concurrency: {
|
|
376
|
+
maxConcurrency: number;
|
|
377
|
+
avgConcurrency: {
|
|
378
|
+
mean: number;
|
|
379
|
+
};
|
|
380
|
+
};
|
|
381
|
+
backpressure: {
|
|
382
|
+
totalEvents: number;
|
|
383
|
+
appliedEvents: number;
|
|
384
|
+
releasedEvents: number;
|
|
385
|
+
avgBufferSize: {
|
|
386
|
+
mean: number;
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* getSummary() plus the raw recorded values, with a timestamp.
|
|
392
|
+
* @returns Object with timestamp, summary and rawMetrics
|
|
393
|
+
*/
|
|
394
|
+
exportMetrics(): {
|
|
395
|
+
timestamp: string;
|
|
396
|
+
summary: {
|
|
397
|
+
embedding: {
|
|
398
|
+
totalOperations: number;
|
|
399
|
+
totalDuration: number;
|
|
400
|
+
totalTokens: number;
|
|
401
|
+
totalBatches: number;
|
|
402
|
+
avgDuration: {
|
|
403
|
+
mean: number;
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
retrieval: {
|
|
407
|
+
totalOperations: number;
|
|
408
|
+
totalResults: number;
|
|
409
|
+
avgDuration: {
|
|
410
|
+
mean: number;
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
llm: {
|
|
414
|
+
totalOperations: number;
|
|
415
|
+
streamingOperations: number;
|
|
416
|
+
avgDuration: {
|
|
417
|
+
mean: number;
|
|
418
|
+
};
|
|
419
|
+
avgInputTokens: {
|
|
420
|
+
mean: number;
|
|
421
|
+
};
|
|
422
|
+
avgOutputTokens: {
|
|
423
|
+
mean: number;
|
|
424
|
+
};
|
|
425
|
+
};
|
|
426
|
+
memory: {
|
|
427
|
+
heapUsed: number;
|
|
428
|
+
heapTotal: number;
|
|
429
|
+
usagePercentage: number;
|
|
430
|
+
};
|
|
431
|
+
errors: {
|
|
432
|
+
total: number;
|
|
433
|
+
byType: {
|
|
434
|
+
plugin: number;
|
|
435
|
+
stage: number;
|
|
436
|
+
};
|
|
437
|
+
byPlugin: {};
|
|
438
|
+
};
|
|
439
|
+
operations: {
|
|
440
|
+
total: number;
|
|
441
|
+
successful: number;
|
|
442
|
+
failed: number;
|
|
443
|
+
};
|
|
444
|
+
concurrency: {
|
|
445
|
+
maxConcurrency: number;
|
|
446
|
+
avgConcurrency: {
|
|
447
|
+
mean: number;
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
backpressure: {
|
|
451
|
+
totalEvents: number;
|
|
452
|
+
appliedEvents: number;
|
|
453
|
+
releasedEvents: number;
|
|
454
|
+
avgBufferSize: {
|
|
455
|
+
mean: number;
|
|
456
|
+
};
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
rawMetrics: {
|
|
460
|
+
counters: {
|
|
461
|
+
operationsTotal: Counter;
|
|
462
|
+
operationsSuccessful: Counter;
|
|
463
|
+
operationsFailed: Counter;
|
|
464
|
+
operationsActive: Counter;
|
|
465
|
+
};
|
|
466
|
+
embedding: {
|
|
467
|
+
operations: number;
|
|
468
|
+
totalDuration: number;
|
|
469
|
+
totalTokens: number;
|
|
470
|
+
totalBatches: number;
|
|
471
|
+
durations: any[];
|
|
472
|
+
};
|
|
473
|
+
retrieval: {
|
|
474
|
+
operations: number;
|
|
475
|
+
totalDuration: number;
|
|
476
|
+
totalResults: number;
|
|
477
|
+
durations: any[];
|
|
478
|
+
};
|
|
479
|
+
llm: {
|
|
480
|
+
operations: number;
|
|
481
|
+
totalDuration: number;
|
|
482
|
+
totalInputTokens: number;
|
|
483
|
+
totalOutputTokens: number;
|
|
484
|
+
streamingOps: number;
|
|
485
|
+
durations: any[];
|
|
486
|
+
inputTokens: any[];
|
|
487
|
+
outputTokens: any[];
|
|
488
|
+
};
|
|
489
|
+
memory: {
|
|
490
|
+
heapUsed: number;
|
|
491
|
+
heapTotal: number;
|
|
492
|
+
usagePercentage: number;
|
|
493
|
+
};
|
|
494
|
+
errors: {
|
|
495
|
+
byType: {
|
|
496
|
+
plugin: number;
|
|
497
|
+
stage: number;
|
|
498
|
+
};
|
|
499
|
+
byPlugin: {};
|
|
500
|
+
};
|
|
501
|
+
concurrency: {
|
|
502
|
+
maxConcurrency: number;
|
|
503
|
+
concurrencyValues: any[];
|
|
504
|
+
};
|
|
505
|
+
backpressure: {
|
|
506
|
+
samples: any[];
|
|
507
|
+
applied: number;
|
|
508
|
+
released: number;
|
|
509
|
+
};
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Reset every counter, total and sample to its initial value.
|
|
514
|
+
* @returns {void}
|
|
515
|
+
*/
|
|
516
|
+
clearMetrics(): void;
|
|
517
|
+
}
|
|
518
|
+
/** Registry of Counter, Histogram and Gauge instances keyed by name. */
|
|
519
|
+
export class MetricsRegistry {
|
|
520
|
+
_metrics: Map<any, any>;
|
|
521
|
+
/**
|
|
522
|
+
* Add a metric under its name.
|
|
523
|
+
* @param {Counter|Histogram|Gauge} metric - Metric to register
|
|
524
|
+
* @returns {void}
|
|
525
|
+
* @throws {Error} If a metric with the same name is already registered
|
|
526
|
+
*/
|
|
527
|
+
register(metric: Counter | Histogram | Gauge): void;
|
|
528
|
+
/**
|
|
529
|
+
* Look up a metric by name.
|
|
530
|
+
* @param {string} name - Metric name
|
|
531
|
+
* @returns {Counter|Histogram|Gauge|undefined} The metric, or undefined if not registered
|
|
532
|
+
*/
|
|
533
|
+
getMetric(name: string): Counter | Histogram | Gauge | undefined;
|
|
534
|
+
/**
|
|
535
|
+
* All registered metrics in registration order.
|
|
536
|
+
* @returns {Array<Counter|Histogram|Gauge>}
|
|
537
|
+
*/
|
|
538
|
+
getAllMetrics(): Array<Counter | Histogram | Gauge>;
|
|
539
|
+
/**
|
|
540
|
+
* Remove every registered metric.
|
|
541
|
+
* @returns {void}
|
|
542
|
+
*/
|
|
543
|
+
clear(): void;
|
|
544
|
+
/**
|
|
545
|
+
* Return the metric registered under name, or create and register a Counter.
|
|
546
|
+
* An existing metric is returned as is, even if it is not a Counter.
|
|
547
|
+
* @param {string} name - Metric name
|
|
548
|
+
* @param {string} [description] - Description for a new counter
|
|
549
|
+
* @param {Object<string, string>} [labels={}] - Labels for a new counter
|
|
550
|
+
* @returns {Counter}
|
|
551
|
+
*/
|
|
552
|
+
getOrCreateCounter(name: string, description?: string, labels?: {
|
|
553
|
+
[x: string]: string;
|
|
554
|
+
}): Counter;
|
|
555
|
+
/**
|
|
556
|
+
* Return the metric registered under name, or create and register a
|
|
557
|
+
* Histogram. An existing metric is returned as is, even if it is not a Histogram.
|
|
558
|
+
* @param {string} name - Metric name
|
|
559
|
+
* @param {string} [description] - Description for a new histogram
|
|
560
|
+
* @param {Object<string, string>} [labels={}] - Labels for a new histogram
|
|
561
|
+
* @param {number[]} [buckets] - Bucket bounds for a new histogram
|
|
562
|
+
* @returns {Histogram}
|
|
563
|
+
*/
|
|
564
|
+
getOrCreateHistogram(name: string, description?: string, labels?: {
|
|
565
|
+
[x: string]: string;
|
|
566
|
+
}, buckets?: number[]): Histogram;
|
|
567
|
+
/**
|
|
568
|
+
* Return the metric registered under name, or create and register a Gauge.
|
|
569
|
+
* An existing metric is returned as is, even if it is not a Gauge.
|
|
570
|
+
* @param {string} name - Metric name
|
|
571
|
+
* @param {string} [description] - Description for a new gauge
|
|
572
|
+
* @param {Object<string, string>} [labels={}] - Labels for a new gauge
|
|
573
|
+
* @returns {Gauge}
|
|
574
|
+
*/
|
|
575
|
+
getOrCreateGauge(name: string, description?: string, labels?: {
|
|
576
|
+
[x: string]: string;
|
|
577
|
+
}): Gauge;
|
|
578
|
+
/**
|
|
579
|
+
* Serialize all metrics (their toJSON output) with a timestamp.
|
|
580
|
+
* @returns {string} JSON string with timestamp and metrics fields
|
|
581
|
+
*/
|
|
582
|
+
exportMetrics(): string;
|
|
583
|
+
}
|
|
584
|
+
/** Shared PipelineMetrics instance. */
|
|
585
|
+
export const pipelineMetrics: PipelineMetrics;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel processor for embedding operations with configurable concurrency
|
|
3
|
+
*/
|
|
4
|
+
export class ParallelEmbedder {
|
|
5
|
+
/**
|
|
6
|
+
* @param {object} embedder - Embedder with embed() and/or embedBatch()
|
|
7
|
+
* @param {object} [_options]
|
|
8
|
+
* @param {number} [_options.batchSize=10] - Texts per batch
|
|
9
|
+
* @param {number} [_options.maxConcurrency=3] - Batches in flight at once
|
|
10
|
+
* @param {number} [_options.retryAttempts=2] - Retries per failed batch
|
|
11
|
+
* @param {number} [_options.retryDelay=1000] - Base retry delay in ms
|
|
12
|
+
* @param {'auto'|'batch'|'single'} [_options.mode='auto'] - How a batch is
|
|
13
|
+
* embedded: 'batch' calls embed(texts) and expects one vector per text,
|
|
14
|
+
* 'single' calls embed(text) for each text. 'auto' uses embedBatch(texts)
|
|
15
|
+
* when the embedder has it, 'single' for the built-in connectors (which
|
|
16
|
+
* embed one string at a time) and 'batch' otherwise.
|
|
17
|
+
*/
|
|
18
|
+
constructor(embedder: object, _options?: {
|
|
19
|
+
batchSize?: number;
|
|
20
|
+
maxConcurrency?: number;
|
|
21
|
+
retryAttempts?: number;
|
|
22
|
+
retryDelay?: number;
|
|
23
|
+
mode?: "auto" | "batch" | "single";
|
|
24
|
+
});
|
|
25
|
+
embedder: any;
|
|
26
|
+
batchSize: number;
|
|
27
|
+
maxConcurrency: number;
|
|
28
|
+
retryAttempts: number;
|
|
29
|
+
retryDelay: number;
|
|
30
|
+
mode: "auto" | "batch" | "single";
|
|
31
|
+
/**
|
|
32
|
+
* Embed one batch according to the mode.
|
|
33
|
+
* @param {string[]} batch
|
|
34
|
+
* @returns {Promise<number[][]>}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private _embed;
|
|
38
|
+
/**
|
|
39
|
+
* Process chunks in parallel batches with concurrency control
|
|
40
|
+
* @param {string[]} chunks - Text chunks to embed
|
|
41
|
+
* @returns {Promise<number[][]>} Array of embedding vectors
|
|
42
|
+
*/
|
|
43
|
+
embedBatch(chunks: string[]): Promise<number[][]>;
|
|
44
|
+
/**
|
|
45
|
+
* Process a single batch with retry logic
|
|
46
|
+
* @param {string[]} batch - Batch of chunks to process
|
|
47
|
+
* @param {number} batchIndex - Index of the batch for logging
|
|
48
|
+
* @returns {Promise<number[][]>} Embedding vectors for the batch
|
|
49
|
+
*/
|
|
50
|
+
processBatchWithRetry(batch: string[], batchIndex: number): Promise<number[][]>;
|
|
51
|
+
/**
|
|
52
|
+
* Create batches from chunks array
|
|
53
|
+
* @param {string[]} items - Items to batch
|
|
54
|
+
* @param {number} size - Batch size
|
|
55
|
+
* @returns {string[][]} Array of batches
|
|
56
|
+
*/
|
|
57
|
+
createBatches(items: string[], size: number): string[][];
|
|
58
|
+
/**
|
|
59
|
+
* Delay utility for retry logic
|
|
60
|
+
* @param {number} ms - Milliseconds to delay
|
|
61
|
+
* @returns {Promise<void>}
|
|
62
|
+
*/
|
|
63
|
+
delay(ms: number): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Parallel processor for retrieval operations
|
|
67
|
+
*/
|
|
68
|
+
export class ParallelRetriever {
|
|
69
|
+
constructor(retriever: any, _options?: {});
|
|
70
|
+
retriever: any;
|
|
71
|
+
maxConcurrency: any;
|
|
72
|
+
chunkQueries: any;
|
|
73
|
+
/**
|
|
74
|
+
* Process multiple queries in parallel
|
|
75
|
+
* @param {number[][]} queryVectors - Array of query vectors
|
|
76
|
+
* @returns {Promise<any[]>} Retrieved results
|
|
77
|
+
*/
|
|
78
|
+
retrieveBatch(queryVectors: number[][]): Promise<any[]>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Semaphore for controlling concurrent operations
|
|
82
|
+
*/
|
|
83
|
+
export class Semaphore {
|
|
84
|
+
constructor(maxConcurrency: any);
|
|
85
|
+
maxConcurrency: any;
|
|
86
|
+
currentCount: number;
|
|
87
|
+
waitQueue: any[];
|
|
88
|
+
/** Resolves when a slot is free and takes it. */
|
|
89
|
+
acquire(): Promise<any>;
|
|
90
|
+
/** Frees a slot, starting the next waiter if there is one. */
|
|
91
|
+
release(): void;
|
|
92
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export = registry;
|
|
2
|
+
/**
|
|
3
|
+
* The shared plugin registry: maps (type, name) to plugins, checking each
|
|
4
|
+
* against its contract. Signed manifests are required when NODE_ENV is
|
|
5
|
+
* production.
|
|
6
|
+
*/
|
|
2
7
|
declare const registry: PluginRegistry;
|
|
3
8
|
declare class PluginRegistry {
|
|
4
9
|
constructor(options?: {});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export = ExecutionScheduler;
|
|
2
|
+
/** @typedef {import('../dag-node')} DAGNode */
|
|
2
3
|
/**
|
|
3
4
|
* ExecutionScheduler class for managing DAG node execution
|
|
4
5
|
*
|
|
@@ -186,6 +187,7 @@ declare class ExecutionScheduler {
|
|
|
186
187
|
}): boolean;
|
|
187
188
|
}
|
|
188
189
|
declare namespace ExecutionScheduler {
|
|
189
|
-
export { ExecutionScheduler as default };
|
|
190
|
+
export { ExecutionScheduler as default, DAGNode };
|
|
190
191
|
}
|
|
191
192
|
import ErrorContext = require("./error-context.js");
|
|
193
|
+
type DAGNode = import("../dag-node");
|