@devilsdev/rag-pipeline-utils 2.3.1 → 2.4.1

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 (160) hide show
  1. package/README.md +94 -480
  2. package/contracts/loader-contract.json +11 -6
  3. package/contracts/reranker-contract.json +18 -26
  4. package/dist/index.cjs +21190 -47
  5. package/dist/index.d.ts +298 -68
  6. package/dist/index.mjs +9 -76
  7. package/package.json +37 -11
  8. package/src/agentic/agentic-pipeline.js +235 -0
  9. package/src/agentic/iterative-retriever.js +213 -0
  10. package/src/agentic/query-planner.js +208 -0
  11. package/src/agentic/self-critique.js +102 -0
  12. package/src/ai/adaptive-retrieval.js +0 -3
  13. package/src/ai/federated-learning.js +0 -3
  14. package/src/ai/federation.js +1 -6
  15. package/src/ai/index.js +9 -20
  16. package/src/ai/model-training.js +0 -3
  17. package/src/ai/multimodal-processing.js +0 -3
  18. package/src/ai/multimodal.js +1 -6
  19. package/src/ai/orchestrator.js +1 -6
  20. package/src/ai/retrieval-engine.js +1 -6
  21. package/src/chunking/chunking-engine.js +142 -0
  22. package/src/chunking/strategies/fixed-size.js +54 -0
  23. package/src/chunking/strategies/recursive.js +127 -0
  24. package/src/chunking/strategies/semantic.js +128 -0
  25. package/src/chunking/strategies/sentence.js +32 -0
  26. package/src/chunking/strategies/structure-aware.js +138 -0
  27. package/src/citation/citation-tracker.js +161 -0
  28. package/src/citation/hallucination-detector.js +74 -0
  29. package/src/citation/source-mapper.js +95 -0
  30. package/src/cli/commands/ai-ml/adaptive-commands.js +178 -0
  31. package/src/cli/commands/ai-ml/federated-commands.js +207 -0
  32. package/src/cli/commands/ai-ml/index.js +17 -0
  33. package/src/cli/commands/ai-ml/multimodal-commands.js +187 -0
  34. package/src/cli/commands/ai-ml/shared.js +51 -0
  35. package/src/cli/commands/ai-ml/training-commands.js +228 -0
  36. package/src/cli/commands/ai-ml.js +176 -757
  37. package/src/cli/commands/plugin-hub/certification-commands.js +221 -0
  38. package/src/cli/commands/plugin-hub/event-handlers.js +64 -0
  39. package/src/cli/commands/plugin-hub/hub-commands.js +290 -0
  40. package/src/cli/commands/plugin-hub/review-commands.js +78 -0
  41. package/src/cli/commands/plugin-hub.js +106 -782
  42. package/src/cli/diagnostics/config-checker.js +81 -0
  43. package/src/cli/diagnostics/dependency-checker.js +69 -0
  44. package/src/cli/diagnostics/environment-checker.js +45 -0
  45. package/src/cli/diagnostics/performance-checker.js +51 -0
  46. package/src/cli/diagnostics/plugin-checker.js +106 -0
  47. package/src/cli/diagnostics/security-checker.js +61 -0
  48. package/src/cli/doctor-command.js +70 -369
  49. package/src/cli/enhanced-cli-commands.js +162 -706
  50. package/src/cli/handlers/config-handler.js +126 -0
  51. package/src/cli/handlers/diagnostics-handler.js +113 -0
  52. package/src/cli/handlers/ingest-handler.js +42 -0
  53. package/src/cli/handlers/init-handler.js +51 -0
  54. package/src/cli/handlers/query-handler.js +45 -0
  55. package/src/cli/handlers/run-handler.js +181 -0
  56. package/src/cli/interactive-wizard.js +99 -723
  57. package/src/cli/shared/cli-utils.js +89 -0
  58. package/src/cli/wizard/configuration.js +148 -0
  59. package/src/cli/wizard/observability.js +79 -0
  60. package/src/cli/wizard/performance.js +76 -0
  61. package/src/cli/wizard/plugin-selection.js +297 -0
  62. package/src/cli/wizard/preview-save.js +172 -0
  63. package/src/cli/wizard/project-setup.js +66 -0
  64. package/src/config/memory-optimization.js +3 -3
  65. package/src/connectors/anthropic-connector.js +179 -0
  66. package/src/connectors/base-connector.js +94 -0
  67. package/src/connectors/cohere-connector.js +143 -0
  68. package/src/connectors/local-embedder.js +171 -0
  69. package/src/connectors/memory-retriever.js +150 -0
  70. package/src/connectors/ollama-connector.js +205 -0
  71. package/src/connectors/openai-connector.js +173 -0
  72. package/src/core/create-pipeline.js +21 -1
  73. package/src/core/observability/tracing.js +2 -1
  74. package/src/core/pipeline-factory.js +0 -1
  75. package/src/core/plugin-registry.js +14 -14
  76. package/src/cost/cost-calculator.js +146 -0
  77. package/src/cost/cost-tracker.js +260 -0
  78. package/src/cost/token-budget.js +245 -0
  79. package/src/dag/core/execution-scheduler.js +2 -1
  80. package/src/dag/core/topology-validation.js +0 -3
  81. package/src/dag/dag-engine.js +3 -5
  82. package/src/dag/dag-node.js +0 -1
  83. package/src/dag/enhanced-dag-engine.js +171 -99
  84. package/src/dashboard/dashboard-generator.js +642 -0
  85. package/src/dashboard/metrics-aggregator.js +409 -0
  86. package/src/debug/execution-tracer.js +210 -0
  87. package/src/debug/trace-inspector.js +281 -0
  88. package/src/dev/dev-server.js +5 -5
  89. package/src/dev/hot-reload.js +3 -2
  90. package/src/dx/integration-templates.js +0 -3
  91. package/src/ecosystem/plugin-analytics-dashboard.js +2 -2
  92. package/src/ecosystem/plugin-hub.js +2 -2
  93. package/src/enterprise/audit-logging.js +2 -2
  94. package/src/enterprise/sso-integration.js +52 -32
  95. package/src/evaluate/context-metrics.js +127 -0
  96. package/src/evaluate/evaluator.js +4 -2
  97. package/src/evaluate/faithfulness.js +117 -0
  98. package/src/evaluate/groundedness.js +60 -0
  99. package/src/evaluate/pipeline-evaluator.js +156 -0
  100. package/src/evaluate/relevance.js +129 -0
  101. package/src/evaluate/scoring.js +27 -0
  102. package/src/graph/entity-extractor.js +183 -0
  103. package/src/graph/graph-index.js +113 -0
  104. package/src/graph/graph-retriever.js +244 -0
  105. package/src/graph/knowledge-graph.js +256 -0
  106. package/src/guardrails/guardrails-pipeline.js +136 -0
  107. package/src/guardrails/post-generation-guard.js +170 -0
  108. package/src/guardrails/pre-retrieval-guard.js +161 -0
  109. package/src/guardrails/retrieval-guard.js +126 -0
  110. package/src/index.js +255 -9
  111. package/src/loader/html-loader.js +4 -15
  112. package/src/loader/markdown-loader.js +4 -15
  113. package/src/mcp/mcp-server.js +199 -0
  114. package/src/mcp/mcp-tool-builder.js +121 -0
  115. package/src/observability/audit-logger.js +0 -2
  116. package/src/observability/event-logger.js +2 -1
  117. package/src/observability/security-monitor.js +0 -2
  118. package/src/observability/telemetry.js +0 -2
  119. package/src/reranker/cascade-reranker.js +79 -0
  120. package/src/reranker/embedding-reranker.js +124 -0
  121. package/src/reranker/llm-reranker.js +6 -3
  122. package/src/reranker/scoring-reranker.js +123 -0
  123. package/src/retrieval/bm25-search.js +157 -0
  124. package/src/retrieval/hybrid-retriever.js +111 -0
  125. package/src/retrieval/rank-fusion.js +62 -0
  126. package/src/security/jwt-config.js +4 -3
  127. package/src/security/jwt-validator.js +2 -1
  128. package/src/security/plugin-sandbox.js +0 -3
  129. package/src/security/plugin-signature-verifier.js +4 -6
  130. package/src/security/validator.js +0 -2
  131. package/src/streaming/embedding-stream.js +197 -0
  132. package/src/streaming/sse-adapter.js +168 -0
  133. package/src/streaming/stream-router.js +210 -0
  134. package/src/streaming/streaming-embedder.js +231 -0
  135. package/src/streaming/websocket-adapter.js +171 -0
  136. package/src/templates/scaffold.js +147 -0
  137. package/src/templates/template-registry.js +272 -0
  138. package/src/utils/contract-validator.js +2 -1
  139. package/src/utils/input-sanitizer.js +80 -99
  140. package/src/utils/performance-monitor.js +0 -3
  141. package/src/utils/plugin-scaffolder.js +9 -16
  142. package/src/utils/rate-limiter.js +0 -1
  143. package/src/utils/retry-policy.js +0 -3
  144. package/src/utils/safe-expression-evaluator.js +0 -3
  145. package/src/utils/secure-logger-config.js +2 -4
  146. package/src/utils/secure-logging.js +0 -3
  147. package/src/utils/structured-logger.js +0 -3
  148. package/src/ai/index-fixed.js +0 -509
  149. package/src/ai/module-template.js +0 -37
  150. package/src/ci/workflow-analyzer.js +0 -71
  151. package/src/cli/plugin-marketplace-commands.js +0 -869
  152. package/src/dev/README.md +0 -126
  153. package/src/dev/examples/hot-reload-usage.js +0 -355
  154. package/src/mocks/openai-embedder.js +0 -119
  155. package/src/mocks/openai-llm.js +0 -77
  156. package/src/mocks/pdf-loader.js +0 -21
  157. package/src/mocks/pinecone-retriever.js +0 -106
  158. package/src/scripts/script-utilities.js +0 -36
  159. package/src/utils/ci/diagnostic-reporter.js +0 -57
  160. package/src/utils/examples/error-formatter-usage.js +0 -351
package/README.md CHANGED
@@ -1,527 +1,141 @@
1
1
  # rag-pipeline-utils
2
2
 
3
- **Modular toolkit for building production-ready RAG pipelines in Node.js**
3
+ The complete Node.js toolkit for production-grade RAG — evaluation, citation, agentic reasoning, guardrails, and 7 provider connectors in one package.
4
4
 
5
- [![CI](https://github.com/DevilsDev/rag-pipeline-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/DevilsDev/rag-pipeline-utils/actions)
6
- [![npm version](https://badge.fury.io/js/%40devilsdev%2Frag-pipeline-utils.svg)](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
7
- [![codecov](https://codecov.io/gh/DevilsDev/rag-pipeline-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/DevilsDev/rag-pipeline-utils)
8
- [![License: GPL-3.0](https://img.shields.io/badge/License-GPL%203.0-blue.svg)](https://opensource.org/licenses/GPL-3.0)
9
- [![Node.js Version](https://img.shields.io/node/v/@devilsdev/rag-pipeline-utils.svg)](https://nodejs.org/)
5
+ [![npm version](https://img.shields.io/npm/v/@devilsdev/rag-pipeline-utils.svg)](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
10
6
  [![Downloads](https://img.shields.io/npm/dm/@devilsdev/rag-pipeline-utils.svg)](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
11
- [![GitHub Discussions](https://img.shields.io/github/discussions/DevilsDev/rag-pipeline-utils)](https://github.com/DevilsDev/rag-pipeline-utils/discussions)
7
+ [![Types](https://img.shields.io/npm/types/@devilsdev/rag-pipeline-utils.svg)](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
8
+ [![License](https://img.shields.io/badge/License-GPL%203.0-blue.svg)](https://opensource.org/licenses/GPL-3.0)
9
+ [![Node.js](https://img.shields.io/node/v/@devilsdev/rag-pipeline-utils.svg)](https://nodejs.org/)
12
10
 
13
- ---
14
-
15
- ## Why This Exists
16
-
17
- Building Retrieval-Augmented Generation (RAG) systems is harder than it should be. Most solutions lock you into specific vendors, force opinionated architectures, or sacrifice observability for simplicity.
18
-
19
- **rag-pipeline-utils** takes a different approach: it provides the building blocks—loaders, embedders, retrievers, LLM connectors, and rerankers—that you compose into pipelines that fit your needs. Every component follows clear contracts. Every integration is optional. Every decision is yours.
20
-
21
- We built this toolkit because we believe infrastructure should be:
22
-
23
- - **Modular** – swap any component without rewriting your pipeline
24
- - **Observable** – metrics, tracing, and audit logs built in from day one
25
- - **Secure** – hardened JWT validation with replay protection, multi-layer path traversal defense, and enterprise-grade defaults
26
- - **Open** – no vendor lock-in, no proprietary APIs, just JavaScript
27
-
28
- Whether you're prototyping a document Q&A system or scaling a production knowledge base, this toolkit grows with you.
29
-
30
- ---
31
-
32
- ## Quick Start
33
-
34
- Here's a complete RAG pipeline in 15 lines:
35
-
36
- ```javascript
37
- const { createRagPipeline } = require("@devilsdev/rag-pipeline-utils");
38
-
39
- // Implement your plugins (or use existing ones)
40
- const pipeline = createRagPipeline({
41
- loader: new MyPDFLoader(),
42
- embedder: new MyOpenAIEmbedder({ apiKey: process.env.OPENAI_API_KEY }),
43
- retriever: new MyVectorDBRetriever({ url: "http://localhost:8000" }),
44
- llm: new MyLLMConnector({ model: "gpt-4" }),
45
- });
46
-
47
- // Ingest documents
48
- await pipeline.ingest("./company-docs.pdf");
49
-
50
- // Query with natural language
51
- const answer = await pipeline.query("What is the vacation policy?");
52
- console.log(answer.text);
53
- // Output: "Based on the company handbook, employees receive 20 days of vacation per year..."
54
- ```
55
-
56
- **Requirements:** Node.js >= 18.0.0
57
-
58
- Install with:
11
+ ## Installation
59
12
 
60
13
  ```bash
61
14
  npm install @devilsdev/rag-pipeline-utils
62
15
  ```
63
16
 
64
- ### What's New in v2.3.1 (Released November 8, 2025)
65
-
66
- **Major Security Enhancements:**
67
-
68
- - **Advanced JWT replay protection** with self-signed token reusability
69
- - **Hardened path traversal defense** with iterative URL decoding
70
- - **Consistent validation behavior** eliminating duplicate checks
71
- - **Race condition mitigation** in concurrent token verification
72
-
73
- **All security tests passing:** 113 security-focused tests with 100% coverage on critical paths.
74
-
75
- [See full security details below](#security-and-quality) | [Migration guide](#upgrading-from-v22x)
76
-
77
- ---
78
-
79
- ## How It Works
80
-
81
- **rag-pipeline-utils** orchestrates data through a clear, predictable flow:
82
-
83
- ```mermaid
84
- graph LR
85
- A[Documents] --> B[Loader]
86
- B --> C[Embedder]
87
- C --> D[Vector Store]
88
- D --> E[Retriever]
89
- F[User Query] --> C
90
- F --> E
91
- E --> G[Reranker]
92
- G --> H[LLM]
93
- H --> I[Response]
94
-
95
- style B fill:#e1f5e1
96
- style C fill:#e1f5e1
97
- style E fill:#e1f5e1
98
- style G fill:#fff4e1
99
- style H fill:#e1f5e1
100
- style I fill:#e3f2fd
101
- ```
102
-
103
- 1. **Loader** – Parse documents (PDF, HTML, Markdown, etc.)
104
- 2. **Embedder** – Convert text to vector embeddings
105
- 3. **Vector Store** – Index and persist embeddings
106
- 4. **Retriever** – Find semantically similar content
107
- 5. **Reranker** (optional) – Refine retrieval results
108
- 6. **LLM** – Generate contextual responses
109
-
110
- Every component is replaceable. Every step is observable.
111
-
112
- ---
113
-
114
- ## Features
115
-
116
- ### Modular Plugin Architecture
117
-
118
- Swap any component without rewriting your pipeline. Use OpenAI embeddings with Pinecone storage, or mix Hugging Face models with PostgreSQL—your choice.
119
-
120
- ### Enterprise Observability
121
-
122
- Built-in structured logging, Prometheus metrics, OpenTelemetry tracing, and audit logs for compliance-grade transparency.
123
-
124
- ### DAG Workflow Engine
125
-
126
- Chain complex multi-step operations with retry logic, parallel execution, and graceful error handling. Perfect for batch ingestion or multi-stage transformations.
127
-
128
- ### Type-Safe Contracts
129
-
130
- Complete TypeScript interfaces for all plugin types. Full IDE autocomplete and compile-time validation.
131
-
132
- ### Production-Ready Security
133
-
134
- Hardened security with defense-in-depth: JWT replay protection with race condition mitigation, multi-layer path traversal defense with iterative URL decoding, validated JSON parsing, algorithm whitelisting, automatic secret redaction, and comprehensive audit logging.
135
-
136
- ### Streaming & Batching
137
-
138
- Stream LLM responses in real-time. Batch embed thousands of documents efficiently with parallel processing and backpressure control.
139
-
140
- ### Framework Agnostic
141
-
142
- Works with Express, Fastify, Next.js, or any Node.js runtime. Deploy to AWS Lambda, Vercel, Docker, or bare metal.
143
-
144
- ---
145
-
146
- ## Join the Community
147
-
148
- We're building this together.
149
-
150
- Whether you're implementing a new retriever, writing documentation, reporting bugs, or sharing ideas—every contribution makes this toolkit better for everyone.
151
-
152
- **Getting Started:**
153
-
154
- - [GitHub Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions) – Ask questions, share use cases, propose features
155
- - [Issue Tracker](https://github.com/DevilsDev/rag-pipeline-utils/issues) – Report bugs or request features
156
- - [Contributing Guide](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/docs/CONTRIBUTING.md) – Learn how to submit pull requests
157
- - [Code of Conduct](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/CODE_OF_CONDUCT.md) – Our community standards
158
-
159
- **Good First Issues:** Look for issues tagged `good first issue` to find beginner-friendly contributions.
160
-
161
- **Office Hours:** Join our monthly community calls to discuss roadmap priorities and architectural decisions.
162
-
163
- ---
164
-
165
- ## Security and Quality
166
-
167
- Security isn't optional. This toolkit is built with defense in depth:
168
-
169
- ### Core Security Features
170
-
171
- - **Validated Inputs** – All JSON parsed through schema validation (AJV)
172
- - **Secure Logging** – Automatic redaction of 36 sensitive field patterns (API keys, JWTs, tokens)
173
- - **JWT Best Practices** – Algorithm whitelisting, issuer/audience validation, expiration enforcement
174
- - **Dependency Scanning** – Weekly Dependabot updates, CI blocks on critical vulnerabilities
175
- - **Audit Trail** – Immutable compliance-grade logs for all security-sensitive operations
176
- - **Plugin Sandboxing** – Third-party plugins run with declared permissions and resource limits
177
- - **Supply Chain Security** – All GitHub Actions pinned to commit SHAs, SBOM generation available
178
-
179
- ### Recent Security Enhancements (v2.3.1)
180
-
181
- #### Hardened JWT Validation
182
-
183
- **Advanced Replay Protection:**
184
-
185
- - Self-signed tokens can be verified multiple times (essential for refresh flows and load balancer retries)
186
- - External tokens are tracked and blocked on replay attempts
187
- - Race condition mitigation with optimized check-then-set pattern
188
- - Separate tracking for reusable vs. single-use tokens
189
-
190
- **Consistent Validation Behavior:**
191
-
192
- - `strictValidation` flag now consistently controls issuer/audience validation
193
- - Eliminated duplicate validation logic to prevent configuration confusion
194
- - Clear separation of concerns: jsonwebtoken handles cryptographic validation, custom logic handles business rules
195
-
196
- **Example:**
197
-
198
- ```javascript
199
- const { JWTValidator } = require("@devilsdev/rag-pipeline-utils");
200
-
201
- const validator = new JWTValidator({
202
- secret: process.env.JWT_SECRET,
203
- algorithm: "HS256",
204
- issuer: "my-app",
205
- audience: "api-users",
206
- strictValidation: true, // Enforces iss/aud validation
207
- enableJtiTracking: true, // Prevents replay attacks
208
- });
209
-
210
- // Self-signed tokens can be verified multiple times
211
- const token = validator.sign({ sub: "user-123" });
212
- validator.verify(token); // First verification
213
- validator.verify(token); // Still works (refresh flow)
214
-
215
- // External tokens are blocked on replay
216
- const externalToken = getTokenFromThirdParty();
217
- validator.verify(externalToken); // First use
218
- validator.verify(externalToken); // Throws "Token replay detected"
219
- ```
220
-
221
- #### Path Traversal Defense
222
-
223
- **Multi-Layer Protection:**
224
-
225
- - Iterative URL decoding (up to 5 passes) to catch sophisticated encoding attacks
226
- - Detects double-encoded paths: `%252e%252e%252f` → `%2e%2e%2f` → `../`
227
- - Malformed encoding treated as attack indicator (throws error)
228
- - Critical security violations always throw, regardless of configuration
229
-
230
- **Attack Vectors Blocked:**
231
-
232
- - Standard traversal: `../../../etc/passwd`
233
- - Windows paths: `..\..\windows\system32`
234
- - URL encoded: `%2e%2e%2f`, `%2e%2e%5c`
235
- - Double encoded: `%252e%252e%252f`
236
- - Mixed encoding: combinations of above
237
-
238
- **Example:**
17
+ ## Quick Start
239
18
 
240
19
  ```javascript
241
- const { sanitizePath } = require("@devilsdev/rag-pipeline-utils");
242
-
243
- // Safe paths are normalized
244
- sanitizePath("docs/README.md"); // Returns: "docs/README.md"
245
-
246
- // Dangerous paths throw errors
247
- sanitizePath("../../../etc/passwd"); // Throws
248
- sanitizePath("%2e%2e%2f%2e%2e%2fpasswd"); // Throws
249
- sanitizePath("%252e%252e%252fconfig"); // Throws (double-encoded)
250
- ```
251
-
252
- #### Defense-in-Depth Architecture
253
-
254
- **Critical Security Errors:**
20
+ import {
21
+ createRagPipeline,
22
+ OpenAIConnector,
23
+ MemoryRetriever,
24
+ } from "@devilsdev/rag-pipeline-utils";
255
25
 
256
- - Path traversal violations **always throw**, even if `throwOnInvalid=false`
257
- - Object depth limit violations **always throw** to prevent DoS
258
- - Security-critical operations are prioritized over configuration flexibility
259
-
260
- **Security Monitoring:**
261
-
262
- - All blocked attempts tracked in `stats.blocked` counter
263
- - Audit events emitted for replay detection, algorithm mismatches, and validation failures
264
- - Structured logging with security event correlation
265
-
266
- ### Quality Metrics
267
-
268
- **Zero Production Vulnerabilities:** `npm audit --production` returns clean on every release.
269
-
270
- **Test Coverage:** 113 security-focused tests across 2 dedicated security suites:
271
-
272
- - JWT Validator: 44 tests covering algorithm confusion, replay attacks, and validation edge cases
273
- - Input Sanitizer: 69 tests covering XSS, SQL injection, command injection, and path traversal
274
-
275
- **Supported Node Versions:** 18.x, 20.x, 22.x (tested in CI)
276
-
277
- ---
278
-
279
- ## Installation & Development
280
-
281
- ### Install
282
-
283
- ```bash
284
- npm install @devilsdev/rag-pipeline-utils
285
- ```
286
-
287
- ### Development Setup
288
-
289
- ```bash
290
- # Clone the repository
291
- git clone https://github.com/DevilsDev/rag-pipeline-utils.git
292
- cd rag-pipeline-utils
293
-
294
- # Install dependencies
295
- npm install
296
-
297
- # Run tests
298
- npm test
299
-
300
- # Run linter
301
- npm run lint
302
-
303
- # Build distribution
304
- npm run build
305
-
306
- # Run development tools
307
- npm run dev
308
- ```
309
-
310
- ### Common Commands
311
-
312
- ```bash
313
- npm test # Run test suite
314
- npm run test:watch # Watch mode for TDD
315
- npm run lint # Check code style
316
- npm run lint:fix # Auto-fix linting issues
317
- npm run security:audit # Scan dependencies
318
- npm run docs:api # Generate API documentation
319
- npm run benchmark # Performance benchmarks
320
- ```
321
-
322
- ---
323
-
324
- ## Roadmap
325
-
326
- ### v2.3.1 (Released November 8, 2025) ✅
327
-
328
- - ✅ **Enhanced CLI** – Interactive wizard for pipeline setup, validation commands, and migration tools
329
- - ✅ **Plugin Marketplace** – Curated registry of community-contributed plugins with ratings and verification
330
- - ✅ **Multi-Tenant Support** – Workspace isolation, resource quotas, and tenant-specific configurations
331
- - ✅ **Advanced Security** – JWT replay protection and hardened path traversal defense
332
-
333
- ### v2.4.0 (Q1 2026)
334
-
335
- - **Streaming Embeddings** – Real-time embedding generation with backpressure control
336
- - **GraphRAG Support** – Native knowledge graph integration for entity-relationship retrieval
337
- - **Advanced Reranking** – Cross-encoder models and learned ranking functions
338
- - **Performance Dashboard** – Web UI for monitoring pipeline health and cost metrics
339
-
340
- ### v2.5.0 (Q2 2026)
341
-
342
- - **Federated Learning** – Privacy-preserving model training across distributed datasets
343
- - **Advanced Caching** – Intelligent embedding cache with TTL and invalidation strategies
344
- - **Multi-Modal Processing** – Native image and audio embedding support
345
- - **Cost Optimization** – Automatic provider selection based on cost and performance
346
-
347
- ### Beyond 2026
348
-
349
- - Native Rust bindings for performance-critical paths
350
- - Kubernetes operator for production deployments
351
- - Real-time collaboration features for team-based pipelines
352
- - Edge deployment support for latency-sensitive applications
353
-
354
- **Vote on features:** Share your priorities in [GitHub Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions/categories/roadmap).
355
-
356
- ---
357
-
358
- ## Upgrading from v2.2.x
359
-
360
- The v2.3.1 release includes important security enhancements that are **100% backward compatible** for most use cases. However, there are a few behavioral changes to be aware of:
361
-
362
- ### JWT Validator Changes
363
-
364
- #### No Action Required (Recommended Use Case)
365
-
366
- If you're using the default configuration with `strictValidation: true` (the default), everything works the same:
367
-
368
- ```javascript
369
- const validator = new JWTValidator({
370
- secret: process.env.JWT_SECRET,
371
- algorithm: "HS256",
372
- issuer: "my-app",
373
- audience: "api-users",
374
- // strictValidation defaults to true
26
+ const pipeline = createRagPipeline({
27
+ retriever: new MemoryRetriever(),
28
+ llm: new OpenAIConnector({ apiKey: process.env.OPENAI_API_KEY }),
375
29
  });
376
30
 
377
- // Behavior unchanged - tokens validated correctly
378
- ```
379
-
380
- #### Behavior Change (Advanced Use Case)
381
-
382
- If you explicitly set `strictValidation: false`, the behavior has changed for consistency:
383
-
384
- **Before v2.3.0:**
385
-
386
- ```javascript
387
- const validator = new JWTValidator({
388
- secret: process.env.JWT_SECRET,
389
- strictValidation: false,
390
- issuer: "my-app", // These were still validated
391
- audience: "api-users", // even with strictValidation=false
31
+ const result = await pipeline.run({
32
+ query: "What is the vacation policy?",
33
+ options: { citations: true, evaluate: true },
392
34
  });
393
- ```
394
-
395
- **After v2.3.0:**
396
35
 
397
- ```javascript
398
- const validator = new JWTValidator({
399
- secret: process.env.JWT_SECRET,
400
- strictValidation: false,
401
- issuer: "my-app", // Now properly ignored
402
- audience: "api-users", // when strictValidation=false
403
- });
404
- // issuer/audience validation is now truly disabled
36
+ console.log(result.results); // retrieved documents
37
+ console.log(result.citations.groundednessScore); // 0.85
38
+ console.log(result.evaluation.scores); // { faithfulness, relevance, ... }
405
39
  ```
406
40
 
407
- **Migration:** If you were relying on the old inconsistent behavior, set `strictValidation: true` explicitly.
41
+ **Requirements:** Node.js ≥ 18
408
42
 
409
- #### Enhanced Behavior (Self-Signed Tokens)
43
+ ## Why
410
44
 
411
- Self-signed tokens can now be verified multiple times, which is essential for:
45
+ Most RAG solutions force vendor lock-in, opinionated architectures, or sacrifice observability for simplicity. `rag-pipeline-utils` gives you modular building blocks with clear contracts — every component is swappable, every decision is yours.
412
46
 
413
- - Refresh token flows
414
- - Load balancer retries
415
- - Distributed systems with eventual consistency
47
+ - **Modular** — swap any component without rewriting your pipeline
48
+ - **Evaluated** — faithfulness, relevance, and groundedness metrics on every run
49
+ - **Safe** — 3-layer guardrails: prompt injection detection, ACL filtering, PII detection
50
+ - **Observable** — OpenTelemetry tracing, Prometheus metrics, audit logs
51
+ - **Connected** — OpenAI, Anthropic, Cohere, Ollama, or bring your own
416
52
 
417
- ```javascript
418
- const token = validator.sign({ sub: "user-123" });
53
+ ## Architecture
419
54
 
420
- // Before v2.3.0: Second verification would throw "replay detected"
421
- // After v2.3.0: Works correctly for self-signed tokens
422
- validator.verify(token); // Works
423
- validator.verify(token); // Now works!
424
55
  ```
56
+ Ingestion: Documents → Chunking → Embedder → Vector Store
425
57
 
426
- External tokens (not signed by your validator) are still correctly blocked on replay.
427
-
428
- ### Input Sanitizer Changes
429
-
430
- #### Path Traversal Now Always Throws
431
-
432
- Path traversal attempts now **always throw errors**, even with `throwOnInvalid: false`:
433
-
434
- **Before v2.3.0:**
435
-
436
- ```javascript
437
- const sanitizer = new InputSanitizer({ throwOnInvalid: false });
438
- const result = sanitizePath("../../../etc/passwd");
439
- // Returned: null (silent failure)
58
+ Query: User Query
59
+ ↓
60
+ Guardrails → prompt injection, topic filtering
61
+ ↓
62
+ Query Planner → decomposes complex queries
63
+ ↓
64
+ Hybrid Retriever → vector + BM25 with Reciprocal Rank Fusion
65
+ ↓
66
+ Reranker → BM25 / embedding / cascade
67
+ ↓
68
+ LLM → generates answer from context
69
+ ↓
70
+ Citation Tracker → maps sentences to sources
71
+ ↓
72
+ Evaluator → scores faithfulness & groundedness
73
+ ↓
74
+ Response { answer, citations, evaluation }
440
75
  ```
441
76
 
442
- **After v2.3.0:**
443
-
444
- ```javascript
445
- const sanitizer = new InputSanitizer({ throwOnInvalid: false });
446
- const result = sanitizePath("../../../etc/passwd");
447
- // Throws: "Potential path traversal detected"
448
- ```
77
+ Each stage is optional and pluggable.
449
78
 
450
- **Rationale:** Path traversal is a critical security violation that should never be silently ignored.
79
+ ## Features
451
80
 
452
- **Migration:** Wrap path sanitization in try-catch if you need to handle errors gracefully:
81
+ | Category | Capabilities |
82
+ | -------------- | ------------------------------------------------------------------------ |
83
+ | **Chunking** | 5 strategies: sentence, fixed-size, recursive, semantic, structure-aware |
84
+ | **Retrieval** | Hybrid vector + BM25 with Reciprocal Rank Fusion |
85
+ | **Reranking** | LLM, BM25 scoring, embedding similarity, or cascade |
86
+ | **Evaluation** | Faithfulness, relevance, context precision/recall, groundedness |
87
+ | **Citation** | Source attribution per sentence, hallucination detection |
88
+ | **Agentic** | Query planning, iterative retrieval, self-critique via DAG engine |
89
+ | **Guardrails** | Injection detection, PII filtering, ACL-aware access control |
90
+ | **GraphRAG** | Knowledge graph construction with entity extraction |
91
+ | **Streaming** | SSE and WebSocket adapters with backpressure control |
92
+ | **Cost** | Token tracking, budget enforcement, provider pricing models |
93
+ | **Debugging** | Execution tracing, bottleneck detection, replay |
94
+ | **MCP** | Expose pipelines as Model Context Protocol tools |
95
+ | **Security** | JWT replay protection, plugin sandboxing, audit logs |
96
+ | **Enterprise** | Multi-tenancy, SSO (SAML/OAuth2/AD/OIDC), data governance |
97
+
98
+ **104 public exports** across the full RAG lifecycle. See [full documentation](https://devilsdev.github.io/rag-pipeline-utils/) for complete API reference.
99
+
100
+ ## Provider Connectors
453
101
 
454
102
  ```javascript
455
- try {
456
- const safePath = sanitizePath(userInput);
457
- // Use safePath
458
- } catch (error) {
459
- if (error.message.includes("path traversal")) {
460
- // Handle attack attempt
461
- logger.warn("Path traversal blocked", { input: userInput });
462
- return res.status(400).json({ error: "Invalid path" });
463
- }
464
- throw error;
465
- }
466
- ```
467
-
468
- ### Breaking Changes
469
-
470
- **None.** All changes are security enhancements that improve correctness without breaking existing valid use cases.
471
-
472
- ### Testing Your Upgrade
473
-
474
- Run your test suite after upgrading:
475
-
476
- ```bash
477
- npm test
103
+ import {
104
+ OpenAIConnector, // GPT-4, text-embedding-3
105
+ AnthropicConnector, // Claude 3 Opus, Sonnet, Haiku
106
+ CohereConnector, // Embed + Rerank
107
+ OllamaConnector, // Llama 3, Mistral (local)
108
+ LocalEmbedder, // TF-IDF (offline, no API)
109
+ MemoryRetriever, // In-memory cosine similarity
110
+ } from "@devilsdev/rag-pipeline-utils";
478
111
  ```
479
112
 
480
- If you encounter issues, please [open an issue](https://github.com/DevilsDev/rag-pipeline-utils/issues) with details about your configuration.
481
-
482
- ---
483
-
484
- ## Contributing
113
+ ## Documentation
485
114
 
486
- We welcome contributions of all kinds:
115
+ - **[Full documentation](https://devilsdev.github.io/rag-pipeline-utils/)** — guides, API reference, deployment
116
+ - **[Architecture guide](https://devilsdev.github.io/rag-pipeline-utils/docs/Architecture)** — pipeline internals
117
+ - **[API reference](https://devilsdev.github.io/rag-pipeline-utils/docs/API-Reference)** — all 104 exports
118
+ - **[Examples](https://devilsdev.github.io/rag-pipeline-utils/docs/Examples)** — chatbot, Q&A, code search, support
487
119
 
488
- - **Code** – Fix bugs, add features, improve performance
489
- - **Documentation** – Write guides, improve examples, clarify concepts
490
- - **Testing** – Expand test coverage, add integration tests, report edge cases
491
- - **Design** – Propose API improvements, suggest architectural patterns
492
- - **Community** – Answer questions, review pull requests, mentor new contributors
120
+ ## Roadmap
493
121
 
494
- **Before You Start:**
122
+ **Current (v2.4):** chunking, citation, evaluation, agentic RAG, hybrid retrieval, 3-layer guardrails, GraphRAG, streaming, cost management, MCP integration, 7 provider connectors.
495
123
 
496
- 1. Read the [Contributing Guide](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/docs/CONTRIBUTING.md)
497
- 2. Check existing [Issues](https://github.com/DevilsDev/rag-pipeline-utils/issues) and [Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions)
498
- 3. Open an issue to discuss major changes before coding
499
- 4. Follow our [Code of Conduct](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/CODE_OF_CONDUCT.md)
124
+ **Next (v3.0):** intelligent caching, native Rust bindings, Kubernetes operator, edge deployment (Cloudflare Workers, Deno Deploy).
500
125
 
501
- **Pull Request Checklist:**
126
+ Vote on features in [GitHub Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions/categories/roadmap).
502
127
 
503
- - [ ] Tests pass (`npm test`)
504
- - [ ] Linter passes (`npm run lint`)
505
- - [ ] Documentation updated
506
- - [ ] Changelog entry added
507
- - [ ] Type definitions updated (if applicable)
128
+ ## Community
508
129
 
509
- ---
130
+ - **[GitHub Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions)** — ask questions, share use cases
131
+ - **[Issues](https://github.com/DevilsDev/rag-pipeline-utils/issues)** — report bugs, request features
132
+ - **[Contributing guide](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/docs/CONTRIBUTING.md)** — submit pull requests
133
+ - **[Code of Conduct](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/CODE_OF_CONDUCT.md)**
510
134
 
511
135
  ## License
512
136
 
513
- **GPL-3.0** – See [LICENSE](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/LICENSE) for full terms.
514
-
515
- This is free software: you are free to change and redistribute it under the terms of the GNU General Public License version 3.
137
+ GPL-3.0 — see [LICENSE](LICENSE) for full terms.
516
138
 
517
139
  ---
518
140
 
519
- ## What's Next?
520
-
521
- **Star this repository** if you find it useful—it helps others discover the project.
522
-
523
- **Share your use case** in [Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions/categories/show-and-tell) to inspire the community.
524
-
525
- **Contribute** your first pull request—check out issues tagged [good first issue](https://github.com/DevilsDev/rag-pipeline-utils/labels/good%20first%20issue).
526
-
527
- Happy building.
141
+ **Star the repo** if you find it useful. **Share your use case** in [Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions/categories/show-and-tell).
@@ -14,13 +14,13 @@
14
14
  "properties": {
15
15
  "load": {
16
16
  "type": "function",
17
- "description": "Load documents from source",
17
+ "description": "Load and parse a document from the given file path",
18
18
  "parameters": {
19
19
  "type": "object",
20
20
  "properties": {
21
21
  "source": {
22
22
  "type": "string",
23
- "description": "Source path or identifier"
23
+ "description": "File path to the document to load"
24
24
  }
25
25
  },
26
26
  "required": ["source"]
@@ -30,11 +30,16 @@
30
30
  "items": {
31
31
  "type": "object",
32
32
  "properties": {
33
- "id": { "type": "string" },
34
- "content": { "type": "string" },
35
- "metadata": { "type": "object" }
33
+ "chunk": {
34
+ "type": "function",
35
+ "description": "Split the document into text chunks",
36
+ "returns": {
37
+ "type": "array",
38
+ "items": { "type": "string" }
39
+ }
40
+ }
36
41
  },
37
- "required": ["id", "content"]
42
+ "required": ["chunk"]
38
43
  }
39
44
  }
40
45
  }