@devilsdev/rag-pipeline-utils 2.6.2 → 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.
Files changed (90) hide show
  1. package/BENCHMARKS.md +7 -1
  2. package/CHANGELOG.md +121 -0
  3. package/README.md +35 -24
  4. package/dist/index.cjs +4164 -1825
  5. package/dist/index.d.ts +265 -256
  6. package/dist/index.mjs +1 -1
  7. package/dist/types/cache/memory-cache.d.ts +4 -1
  8. package/dist/types/cache/redis-cache.d.ts +4 -1
  9. package/dist/types/cli/services/instrument.d.ts +14 -0
  10. package/dist/types/cli/services/rag-service.d.ts +140 -0
  11. package/dist/types/cli/shared/config-context.d.ts +9 -0
  12. package/dist/types/config/component-factory.d.ts +57 -0
  13. package/dist/types/config/enhanced-ragrc-schema.d.ts +648 -0
  14. package/dist/types/config/load-config.d.ts +18 -0
  15. package/dist/types/config/normalize-config.d.ts +9 -0
  16. package/dist/types/core/observability/event-logger.d.ts +211 -0
  17. package/dist/types/core/observability/metrics.d.ts +585 -0
  18. package/dist/types/core/performance/parallel-processor.d.ts +92 -0
  19. package/dist/types/core/plugin-registry.d.ts +5 -0
  20. package/dist/types/dag/core/execution-scheduler.d.ts +3 -1
  21. package/dist/types/dag/dag-engine.d.ts +15 -2
  22. package/dist/types/dev/dev-server.d.ts +136 -0
  23. package/dist/types/dev/hot-reload.d.ts +226 -0
  24. package/dist/types/ecosystem/plugin-analytics-dashboard.d.ts +141 -0
  25. package/dist/types/ecosystem/plugin-hub.d.ts +161 -0
  26. package/dist/types/ecosystem/plugin-installer.d.ts +40 -0
  27. package/dist/types/ecosystem/plugin-probe.d.ts +21 -0
  28. package/dist/types/ecosystem/plugin-scanner.d.ts +30 -0
  29. package/dist/types/ecosystem/tar-extract.d.ts +24 -0
  30. package/dist/types/enterprise/audit-logging.d.ts +217 -0
  31. package/dist/types/evaluate/compare.d.ts +140 -0
  32. package/dist/types/evaluate/dataset.d.ts +43 -0
  33. package/dist/types/evaluate/evaluator.d.ts +14 -0
  34. package/dist/types/evaluate/report.d.ts +56 -0
  35. package/dist/types/evaluate/synthetic.d.ts +64 -0
  36. package/dist/types/loader/csv-loader.d.ts +10 -0
  37. package/dist/types/loader/document-reader.d.ts +18 -0
  38. package/dist/types/loader/html-loader.d.ts +21 -0
  39. package/dist/types/loader/markdown-loader.d.ts +21 -0
  40. package/dist/types/retrieval/bm25-search.d.ts +4 -0
  41. package/dist/types/retrieval/file-vector-store.d.ts +4 -1
  42. package/dist/types/retrieval/hybrid-retriever.d.ts +4 -0
  43. package/dist/types/retrieval/pgvector-retriever.d.ts +123 -0
  44. package/dist/types/retrieval/qdrant-retriever.d.ts +106 -0
  45. package/dist/types/security/validator.d.ts +11 -1
  46. package/dist/types/testing.d.ts +2 -0
  47. package/dist/types/utils/batch-processor.d.ts +205 -0
  48. package/dist/types/utils/connection-pool.d.ts +158 -0
  49. package/dist/types/utils/error-formatter.d.ts +312 -0
  50. package/dist/types/utils/logger.d.ts +29 -4
  51. package/dist/types/utils/rate-limiter.d.ts +13 -8
  52. package/dist/types/utils/retry.d.ts +10 -0
  53. package/package.json +12 -2
  54. package/src/cache/memory-cache.js +4 -1
  55. package/src/cache/redis-cache.js +4 -1
  56. package/src/cli/enhanced-cli-commands.js +79 -0
  57. package/src/cli/handlers/ai-handler.js +2 -2
  58. package/src/cli/handlers/eval-handler.js +201 -0
  59. package/src/cli/handlers/generate-handler.js +103 -0
  60. package/src/cli/services/benchmark.js +2 -2
  61. package/src/cli/services/rag-service.js +59 -10
  62. package/src/cli/shared/cli-utils.js +40 -1
  63. package/src/config/component-factory.js +32 -0
  64. package/src/connectors/local-embedder.js +20 -13
  65. package/src/core/observability/event-logger.js +135 -1
  66. package/src/core/observability/metrics.js +223 -5
  67. package/src/core/performance/parallel-processor.js +2 -0
  68. package/src/core/plugin-registry.js +5 -1
  69. package/src/dag/core/execution-scheduler.js +2 -0
  70. package/src/dag/dag-engine.js +13 -0
  71. package/src/dev/dev-server.js +6 -0
  72. package/src/ecosystem/plugin-hub.js +4 -0
  73. package/src/enterprise/audit-logging.js +5 -0
  74. package/src/evaluate/compare.js +395 -0
  75. package/src/evaluate/dataset.js +207 -0
  76. package/src/evaluate/report.js +350 -0
  77. package/src/evaluate/synthetic.js +246 -0
  78. package/src/index.js +17 -0
  79. package/src/retrieval/bm25-search.js +4 -0
  80. package/src/retrieval/file-vector-store.js +4 -1
  81. package/src/retrieval/hybrid-retriever.js +4 -0
  82. package/src/retrieval/pgvector-retriever.js +420 -0
  83. package/src/retrieval/qdrant-retriever.js +361 -0
  84. package/src/security/validator.js +8 -0
  85. package/src/testing.js +2 -0
  86. package/src/utils/batch-processor.js +7 -3
  87. package/src/utils/error-formatter.js +48 -20
  88. package/src/utils/logger.js +31 -1
  89. package/src/utils/rate-limiter.js +9 -4
  90. package/src/utils/retry.js +10 -1
@@ -0,0 +1,211 @@
1
+ /**
2
+ * In-memory log of pipeline events (plugin and stage lifecycle, memory
3
+ * warnings, custom events) tagged with a session id. A session is started
4
+ * on the first event if startSession was not called.
5
+ */
6
+ export class PipelineEventLogger {
7
+ _events: any[];
8
+ _sessionId: string;
9
+ /**
10
+ * Start a new session with a fresh id and start time. Existing events are kept.
11
+ * @returns {string} The new session id
12
+ */
13
+ startSession(): string;
14
+ _sessionStartTime: string;
15
+ /**
16
+ * Current time as an ISO 8601 string.
17
+ * @returns {string}
18
+ */
19
+ nowISO(): string;
20
+ /**
21
+ * Describe a value's size: length for arrays and strings, key count for
22
+ * objects, type only for null and primitives.
23
+ * @param {*} v - Value to describe
24
+ * @returns {{type: string, length?: number, keys?: number}}
25
+ */
26
+ getInputSize(v: any): {
27
+ type: string;
28
+ length?: number;
29
+ keys?: number;
30
+ };
31
+ /**
32
+ * Same as getInputSize.
33
+ * @param {*} v - Value to describe
34
+ * @returns {{type: string, length?: number, keys?: number}}
35
+ */
36
+ getResultSize(v: any): {
37
+ type: string;
38
+ length?: number;
39
+ keys?: number;
40
+ };
41
+ /**
42
+ * Record a debug-level plugin.start event with the input size and process info.
43
+ * @param {Object} event
44
+ * @param {string} event.pluginType - Plugin type, such as embedder or retriever
45
+ * @param {string} event.pluginName - Plugin name
46
+ * @param {*} [event.input] - Plugin input; only its size is recorded
47
+ * @param {Object<string, *>} [event.context={}] - Extra metadata
48
+ * @returns {void}
49
+ */
50
+ logPluginStart({ pluginType, pluginName, input, context }: {
51
+ pluginType: string;
52
+ pluginName: string;
53
+ input?: any;
54
+ context?: {
55
+ [x: string]: any;
56
+ };
57
+ }): void;
58
+ /**
59
+ * Record a debug-level plugin.end event. When the result is an array, or
60
+ * has a vectors array, its length is recorded as resultSize.vectorCount.
61
+ * @param {Object} event
62
+ * @param {string} event.pluginType - Plugin type
63
+ * @param {string} event.pluginName - Plugin name
64
+ * @param {number} [event.duration] - Duration in milliseconds
65
+ * @param {*} [event.result] - Plugin result; only its length is recorded
66
+ * @param {string} [event.status='success'] - Outcome
67
+ * @param {Object<string, *>} [event.context={}] - Extra metadata
68
+ * @returns {void}
69
+ */
70
+ logPluginEnd({ pluginType, pluginName, duration, result, status, context, }: {
71
+ pluginType: string;
72
+ pluginName: string;
73
+ duration?: number;
74
+ result?: any;
75
+ status?: string;
76
+ context?: {
77
+ [x: string]: any;
78
+ };
79
+ }): void;
80
+ /**
81
+ * Record an error-level plugin.error event with the error's name, message and code.
82
+ * @param {Object} event
83
+ * @param {string} event.pluginType - Plugin type
84
+ * @param {string} event.pluginName - Plugin name
85
+ * @param {number} [event.duration] - Duration in milliseconds
86
+ * @param {Error & {code?: string}} [event.error] - The error thrown
87
+ * @param {Object<string, *>} [event.context={}] - Extra metadata
88
+ * @returns {void}
89
+ */
90
+ logPluginError({ pluginType, pluginName, duration, error, context }: {
91
+ pluginType: string;
92
+ pluginName: string;
93
+ duration?: number;
94
+ error?: Error & {
95
+ code?: string;
96
+ };
97
+ context?: {
98
+ [x: string]: any;
99
+ };
100
+ }): void;
101
+ /**
102
+ * Record an info-level stage.start event.
103
+ * @param {string} stage - Stage name
104
+ * @returns {void}
105
+ */
106
+ logStageStart(stage: string): void;
107
+ /**
108
+ * Record a warn-level memory.warning event. usagePercentage is heapUsed
109
+ * (or rss if heapUsed is missing) in MB as a percentage of threshold.
110
+ * @param {Object} event
111
+ * @param {{heapUsed?: number, rss?: number}} event.memoryUsage - Memory figures in bytes, as from process.memoryUsage()
112
+ * @param {number} [event.threshold=512] - Threshold in MB
113
+ * @returns {void}
114
+ */
115
+ logMemoryWarning({ memoryUsage, threshold }: {
116
+ memoryUsage: {
117
+ heapUsed?: number;
118
+ rss?: number;
119
+ };
120
+ threshold?: number;
121
+ }): void;
122
+ /**
123
+ * Recorded events, oldest first, optionally filtered.
124
+ * @param {Object} [filters]
125
+ * @param {string} [filters.eventType]
126
+ * @param {string} [filters.severity]
127
+ * @param {string} [filters.pluginType]
128
+ * @param {string|number|Date} [filters.since] - Only events at or after this time
129
+ * @param {string|number|Date} [filters.until] - Only events at or before this time
130
+ * @param {number} [filters.limit] - Keep only the most recent `limit` events
131
+ * @returns {Object[]}
132
+ */
133
+ getEventHistory({ eventType, severity, pluginType, since, until, limit, }?: {
134
+ eventType?: string;
135
+ severity?: string;
136
+ pluginType?: string;
137
+ since?: string | number | Date;
138
+ until?: string | number | Date;
139
+ limit?: number;
140
+ }): any[];
141
+ /**
142
+ * Serialize the session id and the events matching the filters.
143
+ * @param {Object} [filters] - Same filters as getEventHistory
144
+ * @returns {string} JSON string with sessionId, eventCount and events
145
+ */
146
+ exportEvents(filters?: any): string;
147
+ /**
148
+ * Record an event of any type.
149
+ * @param {string} eventType - Event type
150
+ * @param {string} severity - Severity level
151
+ * @param {Object<string, *>} [metadata={}] - Event metadata
152
+ * @param {string} [message] - Message; defaults to 'Event: ' plus the event type
153
+ * @returns {this}
154
+ */
155
+ logEvent(eventType: string, severity: string, metadata?: {
156
+ [x: string]: any;
157
+ }, message?: string): this;
158
+ /**
159
+ * Remove all recorded events. The session id is kept.
160
+ * @returns {this}
161
+ */
162
+ clearHistory(): this;
163
+ /**
164
+ * Record an info-level stage.end event.
165
+ * @param {string} stage - Stage name
166
+ * @param {number} duration - Duration in milliseconds
167
+ * @param {Object<string, *>} [metadata={}] - Extra metadata merged into the event metadata
168
+ * @returns {this}
169
+ */
170
+ logStageEnd(stage: string, duration: number, metadata?: {
171
+ [x: string]: any;
172
+ }): this;
173
+ /**
174
+ * Current session id. Starts a session if none is active.
175
+ * @returns {string}
176
+ */
177
+ get sessionId(): string;
178
+ /**
179
+ * Session id, total event count, session start time and the distinct event
180
+ * types recorded. Starts a session if none is active.
181
+ * @returns {{sessionId: string, totalEvents: number, startTime: string, eventTypes: string[]}}
182
+ */
183
+ getSessionStats(): {
184
+ sessionId: string;
185
+ totalEvents: number;
186
+ startTime: string;
187
+ eventTypes: string[];
188
+ };
189
+ }
190
+ /**
191
+ * Event type names used by PipelineEventLogger. The logger also emits
192
+ * 'stage.end' and 'memory.warning', which have no entry here.
193
+ * @type {{PLUGIN_START: string, PLUGIN_END: string, PLUGIN_ERROR: string, STAGE_START: string, STAGE_ERROR: string}}
194
+ */
195
+ export const EventTypes: {
196
+ PLUGIN_START: string;
197
+ PLUGIN_END: string;
198
+ PLUGIN_ERROR: string;
199
+ STAGE_START: string;
200
+ STAGE_ERROR: string;
201
+ };
202
+ /**
203
+ * Severity levels used by PipelineEventLogger. Memory warnings use 'warn',
204
+ * which has no entry here.
205
+ * @type {{DEBUG: string, INFO: string, ERROR: string}}
206
+ */
207
+ export const EventSeverity: {
208
+ DEBUG: string;
209
+ INFO: string;
210
+ ERROR: string;
211
+ };