@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.
- package/README.md +94 -480
- package/contracts/loader-contract.json +11 -6
- package/contracts/reranker-contract.json +18 -26
- package/dist/index.cjs +21190 -47
- package/dist/index.d.ts +298 -68
- package/dist/index.mjs +9 -76
- package/package.json +37 -11
- package/src/agentic/agentic-pipeline.js +235 -0
- package/src/agentic/iterative-retriever.js +213 -0
- package/src/agentic/query-planner.js +208 -0
- package/src/agentic/self-critique.js +102 -0
- package/src/ai/adaptive-retrieval.js +0 -3
- package/src/ai/federated-learning.js +0 -3
- package/src/ai/federation.js +1 -6
- package/src/ai/index.js +9 -20
- package/src/ai/model-training.js +0 -3
- package/src/ai/multimodal-processing.js +0 -3
- package/src/ai/multimodal.js +1 -6
- package/src/ai/orchestrator.js +1 -6
- package/src/ai/retrieval-engine.js +1 -6
- package/src/chunking/chunking-engine.js +142 -0
- package/src/chunking/strategies/fixed-size.js +54 -0
- package/src/chunking/strategies/recursive.js +127 -0
- package/src/chunking/strategies/semantic.js +128 -0
- package/src/chunking/strategies/sentence.js +32 -0
- package/src/chunking/strategies/structure-aware.js +138 -0
- package/src/citation/citation-tracker.js +161 -0
- package/src/citation/hallucination-detector.js +74 -0
- package/src/citation/source-mapper.js +95 -0
- package/src/cli/commands/ai-ml/adaptive-commands.js +178 -0
- package/src/cli/commands/ai-ml/federated-commands.js +207 -0
- package/src/cli/commands/ai-ml/index.js +17 -0
- package/src/cli/commands/ai-ml/multimodal-commands.js +187 -0
- package/src/cli/commands/ai-ml/shared.js +51 -0
- package/src/cli/commands/ai-ml/training-commands.js +228 -0
- package/src/cli/commands/ai-ml.js +176 -757
- package/src/cli/commands/plugin-hub/certification-commands.js +221 -0
- package/src/cli/commands/plugin-hub/event-handlers.js +64 -0
- package/src/cli/commands/plugin-hub/hub-commands.js +290 -0
- package/src/cli/commands/plugin-hub/review-commands.js +78 -0
- package/src/cli/commands/plugin-hub.js +106 -782
- package/src/cli/diagnostics/config-checker.js +81 -0
- package/src/cli/diagnostics/dependency-checker.js +69 -0
- package/src/cli/diagnostics/environment-checker.js +45 -0
- package/src/cli/diagnostics/performance-checker.js +51 -0
- package/src/cli/diagnostics/plugin-checker.js +106 -0
- package/src/cli/diagnostics/security-checker.js +61 -0
- package/src/cli/doctor-command.js +70 -369
- package/src/cli/enhanced-cli-commands.js +162 -706
- package/src/cli/handlers/config-handler.js +126 -0
- package/src/cli/handlers/diagnostics-handler.js +113 -0
- package/src/cli/handlers/ingest-handler.js +42 -0
- package/src/cli/handlers/init-handler.js +51 -0
- package/src/cli/handlers/query-handler.js +45 -0
- package/src/cli/handlers/run-handler.js +181 -0
- package/src/cli/interactive-wizard.js +99 -723
- package/src/cli/shared/cli-utils.js +89 -0
- package/src/cli/wizard/configuration.js +148 -0
- package/src/cli/wizard/observability.js +79 -0
- package/src/cli/wizard/performance.js +76 -0
- package/src/cli/wizard/plugin-selection.js +297 -0
- package/src/cli/wizard/preview-save.js +172 -0
- package/src/cli/wizard/project-setup.js +66 -0
- package/src/config/memory-optimization.js +3 -3
- package/src/connectors/anthropic-connector.js +179 -0
- package/src/connectors/base-connector.js +94 -0
- package/src/connectors/cohere-connector.js +143 -0
- package/src/connectors/local-embedder.js +171 -0
- package/src/connectors/memory-retriever.js +150 -0
- package/src/connectors/ollama-connector.js +205 -0
- package/src/connectors/openai-connector.js +173 -0
- package/src/core/create-pipeline.js +21 -1
- package/src/core/observability/tracing.js +2 -1
- package/src/core/pipeline-factory.js +0 -1
- package/src/core/plugin-registry.js +14 -14
- package/src/cost/cost-calculator.js +146 -0
- package/src/cost/cost-tracker.js +260 -0
- package/src/cost/token-budget.js +245 -0
- package/src/dag/core/execution-scheduler.js +2 -1
- package/src/dag/core/topology-validation.js +0 -3
- package/src/dag/dag-engine.js +3 -5
- package/src/dag/dag-node.js +0 -1
- package/src/dag/enhanced-dag-engine.js +171 -99
- package/src/dashboard/dashboard-generator.js +642 -0
- package/src/dashboard/metrics-aggregator.js +409 -0
- package/src/debug/execution-tracer.js +210 -0
- package/src/debug/trace-inspector.js +281 -0
- package/src/dev/dev-server.js +5 -5
- package/src/dev/hot-reload.js +3 -2
- package/src/dx/integration-templates.js +0 -3
- package/src/ecosystem/plugin-analytics-dashboard.js +2 -2
- package/src/ecosystem/plugin-hub.js +2 -2
- package/src/enterprise/audit-logging.js +2 -2
- package/src/enterprise/sso-integration.js +52 -32
- package/src/evaluate/context-metrics.js +127 -0
- package/src/evaluate/evaluator.js +4 -2
- package/src/evaluate/faithfulness.js +117 -0
- package/src/evaluate/groundedness.js +60 -0
- package/src/evaluate/pipeline-evaluator.js +156 -0
- package/src/evaluate/relevance.js +129 -0
- package/src/evaluate/scoring.js +27 -0
- package/src/graph/entity-extractor.js +183 -0
- package/src/graph/graph-index.js +113 -0
- package/src/graph/graph-retriever.js +244 -0
- package/src/graph/knowledge-graph.js +256 -0
- package/src/guardrails/guardrails-pipeline.js +136 -0
- package/src/guardrails/post-generation-guard.js +170 -0
- package/src/guardrails/pre-retrieval-guard.js +161 -0
- package/src/guardrails/retrieval-guard.js +126 -0
- package/src/index.js +255 -9
- package/src/loader/html-loader.js +4 -15
- package/src/loader/markdown-loader.js +4 -15
- package/src/mcp/mcp-server.js +199 -0
- package/src/mcp/mcp-tool-builder.js +121 -0
- package/src/observability/audit-logger.js +0 -2
- package/src/observability/event-logger.js +2 -1
- package/src/observability/security-monitor.js +0 -2
- package/src/observability/telemetry.js +0 -2
- package/src/reranker/cascade-reranker.js +79 -0
- package/src/reranker/embedding-reranker.js +124 -0
- package/src/reranker/llm-reranker.js +6 -3
- package/src/reranker/scoring-reranker.js +123 -0
- package/src/retrieval/bm25-search.js +157 -0
- package/src/retrieval/hybrid-retriever.js +111 -0
- package/src/retrieval/rank-fusion.js +62 -0
- package/src/security/jwt-config.js +4 -3
- package/src/security/jwt-validator.js +2 -1
- package/src/security/plugin-sandbox.js +0 -3
- package/src/security/plugin-signature-verifier.js +4 -6
- package/src/security/validator.js +0 -2
- package/src/streaming/embedding-stream.js +197 -0
- package/src/streaming/sse-adapter.js +168 -0
- package/src/streaming/stream-router.js +210 -0
- package/src/streaming/streaming-embedder.js +231 -0
- package/src/streaming/websocket-adapter.js +171 -0
- package/src/templates/scaffold.js +147 -0
- package/src/templates/template-registry.js +272 -0
- package/src/utils/contract-validator.js +2 -1
- package/src/utils/input-sanitizer.js +80 -99
- package/src/utils/performance-monitor.js +0 -3
- package/src/utils/plugin-scaffolder.js +9 -16
- package/src/utils/rate-limiter.js +0 -1
- package/src/utils/retry-policy.js +0 -3
- package/src/utils/safe-expression-evaluator.js +0 -3
- package/src/utils/secure-logger-config.js +2 -4
- package/src/utils/secure-logging.js +0 -3
- package/src/utils/structured-logger.js +0 -3
- package/src/ai/index-fixed.js +0 -509
- package/src/ai/module-template.js +0 -37
- package/src/ci/workflow-analyzer.js +0 -71
- package/src/cli/plugin-marketplace-commands.js +0 -869
- package/src/dev/README.md +0 -126
- package/src/dev/examples/hot-reload-usage.js +0 -355
- package/src/mocks/openai-embedder.js +0 -119
- package/src/mocks/openai-llm.js +0 -77
- package/src/mocks/pdf-loader.js +0 -21
- package/src/mocks/pinecone-retriever.js +0 -106
- package/src/scripts/script-utilities.js +0 -36
- package/src/utils/ci/diagnostic-reporter.js +0 -57
- 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
|
-
|
|
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
|
-
[](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
|
|
7
|
-
[](https://codecov.io/gh/DevilsDev/rag-pipeline-utils)
|
|
8
|
-
[](https://opensource.org/licenses/GPL-3.0)
|
|
9
|
-
[](https://nodejs.org/)
|
|
5
|
+
[](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
|
|
10
6
|
[](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
|
|
11
|
-
[](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
|
|
8
|
+
[](https://opensource.org/licenses/GPL-3.0)
|
|
9
|
+
[](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
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
**
|
|
41
|
+
**Requirements:** Node.js ≥ 18
|
|
408
42
|
|
|
409
|
-
|
|
43
|
+
## Why
|
|
410
44
|
|
|
411
|
-
|
|
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
|
-
-
|
|
414
|
-
-
|
|
415
|
-
-
|
|
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
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
+
## Features
|
|
451
80
|
|
|
452
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
//
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
481
|
-
|
|
482
|
-
---
|
|
483
|
-
|
|
484
|
-
## Contributing
|
|
113
|
+
## Documentation
|
|
485
114
|
|
|
486
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
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
|
-
|
|
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
|
-
|
|
126
|
+
Vote on features in [GitHub Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions/categories/roadmap).
|
|
502
127
|
|
|
503
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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": "
|
|
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
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
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": ["
|
|
42
|
+
"required": ["chunk"]
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
}
|