@devilsdev/rag-pipeline-utils 2.1.11 → 2.2.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/.ragrc.schema.json +218 -0
- package/README.md +651 -393
- package/bin/cli.js +8 -14
- package/dist/index.d.ts +237 -0
- package/dist/index.mjs +22 -7
- package/package.json +17 -13
- package/src/ai/adaptive-retrieval.js +191 -0
- package/src/ai/federated-learning.js +214 -0
- package/src/ai/federation/federated-learning-coordinator.js +345 -0
- package/src/ai/federation.js +76 -0
- package/src/ai/index-fixed.js +509 -0
- package/src/ai/index.js +33 -0
- package/src/ai/model-trainer.js +217 -0
- package/src/ai/model-training.js +205 -0
- package/src/ai/module-template.js +37 -0
- package/src/ai/multimodal/multi-modal-processor.js +345 -0
- package/src/ai/multimodal-processing.js +268 -0
- package/src/ai/multimodal.js +71 -0
- package/src/ai/orchestrator.js +70 -0
- package/src/ai/retrieval/adaptive-retrieval-engine.js +398 -0
- package/src/ai/retrieval-engine.js +69 -0
- package/src/ai/training/model-training-orchestrator.js +228 -0
- package/src/ci/workflow-analyzer.js +71 -0
- package/src/cli/commands/ai-ml.js +967 -0
- package/src/cli/commands/docs.js +228 -0
- package/src/cli/commands/dx.js +538 -0
- package/src/cli/commands/plugin-hub.js +875 -0
- package/src/cli/doctor-command.js +639 -0
- package/src/cli/enhanced-cli-commands.js +945 -0
- package/src/cli/interactive-wizard.js +997 -0
- package/src/cli/plugin-marketplace-commands.js +869 -0
- package/src/cli.js +17 -0
- package/src/config/enhanced-ragrc-schema.js +632 -0
- package/src/config/load-config.js +54 -0
- package/src/config/load-plugin-config.js +69 -0
- package/src/config/normalize-config.js +105 -0
- package/src/config/schema-validator.js +315 -0
- package/src/config/validate-plugin-schema.js +35 -0
- package/src/config/validate-schema.js +113 -0
- package/src/contracts/plugin-contracts.js +33 -0
- package/src/core/create-pipeline.js +99 -0
- package/src/core/dependency-injection.js +242 -0
- package/src/core/observability/event-logger.js +241 -0
- package/src/core/observability/instrumented-pipeline.js +609 -0
- package/src/core/observability/metrics.js +497 -0
- package/src/core/observability/tracing.js +781 -0
- package/src/core/performance/benchmark.js +516 -0
- package/src/core/performance/parallel-processor.js +240 -0
- package/src/core/performance/streaming-safeguards.js +611 -0
- package/src/core/pipeline-factory.js +60 -0
- package/src/core/plugin-contracts.js +89 -0
- package/src/core/plugin-marketplace/plugin-metadata.js +485 -0
- package/src/core/plugin-marketplace/plugin-publisher.js +574 -0
- package/src/core/plugin-marketplace/plugin-registry-format.js +419 -0
- package/src/core/plugin-marketplace/version-resolver.js +61 -0
- package/src/core/plugin-registry.js +265 -0
- package/src/dag/dag-engine.js +954 -0
- package/src/dag/dag-node.js +76 -0
- package/src/dag/enhanced-dag-engine.js +822 -0
- package/src/dx/index.js +40 -0
- package/src/dx/integration-templates.js +665 -0
- package/src/dx/performance-profiler.js +968 -0
- package/src/dx/realtime-debugger.js +755 -0
- package/src/dx/visual-pipeline-builder.js +578 -0
- package/src/ecosystem/plugin-analytics-dashboard.js +778 -0
- package/src/ecosystem/plugin-certification.js +580 -0
- package/src/ecosystem/plugin-hub.js +821 -0
- package/src/enterprise/audit-logging.js +967 -0
- package/src/enterprise/data-governance.js +408 -0
- package/src/enterprise/multi-tenancy.js +496 -0
- package/src/enterprise/sso-integration.js +903 -0
- package/src/evaluate/evaluator.js +52 -0
- package/src/evaluate/scoring.js +91 -0
- package/src/index.js +67 -0
- package/src/ingest.js +59 -0
- package/src/loader/csv-loader.js +38 -0
- package/src/loader/directory-loader.js +48 -0
- package/src/loader/html-loader.js +62 -0
- package/src/loader/markdown-loader.js +67 -0
- package/src/mocks/openai-embedder.js +119 -0
- package/src/mocks/openai-llm.js +77 -0
- package/src/mocks/pdf-loader.js +21 -0
- package/src/mocks/pinecone-retriever.js +106 -0
- package/src/observability/audit-logger.js +758 -0
- package/src/observability/dashboard-config.json +675 -0
- package/src/observability/event-logger.js +310 -0
- package/src/observability/metrics.js +691 -0
- package/src/observability/security-monitor.js +830 -0
- package/src/observability/slo-monitor.js +319 -0
- package/src/observability/telemetry.js +686 -0
- package/src/pipeline/pipeline.js +18 -0
- package/src/plugins/sample-embedder.js +53 -0
- package/src/plugins/sample-llm.js +30 -0
- package/src/plugins/sample-loader.js +24 -0
- package/src/plugins/sample-retriever.js +84 -0
- package/src/query.js +117 -0
- package/src/reranker/llm-reranker.js +85 -0
- package/src/scripts/script-utilities.js +36 -0
- package/src/security/plugin-sandbox.js +586 -0
- package/src/security/plugin-signature-verifier.js +414 -0
- package/src/security/validator.js +36 -0
- package/src/utils/ci/diagnostic-reporter.js +57 -0
- package/src/utils/logger.js +211 -0
- package/src/utils/performance-monitor.js +561 -0
- package/src/utils/plugin-scaffolder.js +447 -0
- package/src/utils/retry-policy.js +443 -0
- package/src/utils/retry.js +107 -0
- package/src/utils/safe-expression-evaluator.js +579 -0
- package/src/utils/structured-logger.js +361 -0
- package/src/utils/validate-plugin-contract.js +42 -0
package/README.md
CHANGED
|
@@ -8,315 +8,332 @@
|
|
|
8
8
|
|
|
9
9
|
Enterprise-grade toolkit for building Retrieval-Augmented Generation (RAG) pipelines in Node.js with modular plugin architecture, streaming support, and observability.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## 🎉 What's New in v2.2.0
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
npm install @devilsdev/rag-pipeline-utils
|
|
15
|
-
```
|
|
13
|
+
### Major Improvements
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
**✅ Fixed ESM Build (Critical)**
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
- Implemented CJS→ESM interop pattern for proper module compatibility
|
|
18
|
+
- All 15 exports now working correctly in both CommonJS and ES Modules
|
|
19
|
+
- Verified compatibility with Node.js 18.x, 20.x, and 22.x
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
**📦 50% Smaller Install Size**
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
- Reduced from ~30MB to ~15MB by optimizing dependencies
|
|
24
|
+
- Moved CLI-only tools to devDependencies
|
|
25
|
+
- Zero production vulnerabilities (npm audit clean)
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
const pipeline = createRagPipeline({
|
|
28
|
-
loader: new PDFLoader(),
|
|
29
|
-
embedder: new OpenAIEmbedder({
|
|
30
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
31
|
-
model: "text-embedding-ada-002",
|
|
32
|
-
}),
|
|
33
|
-
retriever: new ChromaRetriever({
|
|
34
|
-
url: "http://localhost:8000",
|
|
35
|
-
collection: "documents",
|
|
36
|
-
}),
|
|
37
|
-
llm: new OpenAILLM({
|
|
38
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
39
|
-
model: "gpt-4",
|
|
40
|
-
}),
|
|
41
|
-
});
|
|
27
|
+
**📝 Enhanced TypeScript Support**
|
|
42
28
|
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
- Added 5 complete plugin contract interfaces:
|
|
30
|
+
- `LoaderPlugin` - Document loading interface
|
|
31
|
+
- `EmbedderPlugin` - Text embedding interface
|
|
32
|
+
- `RetrieverPlugin` - Vector search interface
|
|
33
|
+
- `LLMPlugin` - Language model interface
|
|
34
|
+
- `RerankerPlugin` - Result reranking interface
|
|
35
|
+
- Added 4 helper types: `Document`, `SearchResult`, `RetrieveOptions`, `LLMResponse`
|
|
36
|
+
- 236 lines of comprehensive type definitions
|
|
37
|
+
- Full IDE autocomplete and type checking support
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
const result = await pipeline.query("What is the main conclusion?");
|
|
48
|
-
console.log(result.answer);
|
|
49
|
-
```
|
|
39
|
+
**🔧 Real-World Example**
|
|
50
40
|
|
|
51
|
-
|
|
41
|
+
- Complete OpenAI + Pinecone integration example in `examples/openai-pinecone/`
|
|
42
|
+
- Mock mode for testing without API keys
|
|
43
|
+
- Production-ready error handling and cost estimation guidance
|
|
44
|
+
- See [OpenAI + Pinecone Example](#openai--pinecone-example) below
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
// Stream tokens in real-time
|
|
55
|
-
const stream = await pipeline.query("Explain the methodology", {
|
|
56
|
-
stream: true,
|
|
57
|
-
});
|
|
46
|
+
**📚 Documentation Enhancements**
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
- Platform compatibility matrix (Linux, macOS, Windows, Docker)
|
|
49
|
+
- Module system examples (CommonJS + ES Modules)
|
|
50
|
+
- Docker usage examples
|
|
51
|
+
- Troubleshooting guides
|
|
63
52
|
|
|
64
|
-
###
|
|
53
|
+
### Migration from v2.1.x
|
|
65
54
|
|
|
66
|
-
|
|
67
|
-
// Process multiple documents concurrently
|
|
68
|
-
const results = await pipeline.ingestBatch(
|
|
69
|
-
["./docs/paper1.pdf", "./docs/paper2.pdf", "./docs/paper3.pdf"],
|
|
70
|
-
{
|
|
71
|
-
parallel: true,
|
|
72
|
-
maxConcurrency: 5,
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
```
|
|
55
|
+
**No breaking changes!** v2.2.0 is fully backward compatible. Simply update:
|
|
76
56
|
|
|
77
|
-
|
|
57
|
+
```bash
|
|
58
|
+
npm install @devilsdev/rag-pipeline-utils@latest
|
|
59
|
+
```
|
|
78
60
|
|
|
79
|
-
|
|
61
|
+
All existing code will continue to work without modifications.
|
|
80
62
|
|
|
81
|
-
|
|
63
|
+
---
|
|
82
64
|
|
|
83
|
-
|
|
65
|
+
## Installation
|
|
84
66
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- `config.llm` - Language model plugin
|
|
89
|
-
- `config.reranker` (optional) - Result reranking plugin
|
|
67
|
+
```bash
|
|
68
|
+
npm install @devilsdev/rag-pipeline-utils
|
|
69
|
+
```
|
|
90
70
|
|
|
91
|
-
**
|
|
71
|
+
**Requirements:** Node.js >= 18.0.0
|
|
92
72
|
|
|
93
|
-
|
|
73
|
+
## Compatibility
|
|
94
74
|
|
|
95
|
-
|
|
75
|
+
### Platform Support
|
|
96
76
|
|
|
97
|
-
|
|
77
|
+
| Platform | Status | Notes |
|
|
78
|
+
| ----------- | ------------------ | ------------------------------------------------------------- |
|
|
79
|
+
| **Linux** | ✅ Fully Supported | Tested on Ubuntu 20.04+, Debian 11+, RHEL 8+ |
|
|
80
|
+
| **macOS** | ✅ Fully Supported | Tested on macOS 12+ (Intel & Apple Silicon) |
|
|
81
|
+
| **Windows** | ✅ Fully Supported | Tested on Windows 10/11, WSL2 recommended for best experience |
|
|
82
|
+
| **Docker** | ✅ Fully Supported | Alpine & Debian-based images available |
|
|
98
83
|
|
|
99
|
-
|
|
100
|
-
await pipeline.ingest("./document.pdf", {
|
|
101
|
-
chunkSize: 1000,
|
|
102
|
-
chunkOverlap: 200,
|
|
103
|
-
metadata: { source: "research", year: 2024 },
|
|
104
|
-
});
|
|
105
|
-
```
|
|
84
|
+
### Module Systems
|
|
106
85
|
|
|
107
|
-
|
|
86
|
+
This package supports both CommonJS and ES Modules:
|
|
108
87
|
|
|
109
|
-
|
|
88
|
+
**CommonJS (require)**
|
|
110
89
|
|
|
111
90
|
```javascript
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
const {
|
|
92
|
+
createRagPipeline,
|
|
93
|
+
DAGEngine,
|
|
94
|
+
} = require("@devilsdev/rag-pipeline-utils");
|
|
95
|
+
|
|
96
|
+
const pipeline = createRagPipeline({
|
|
97
|
+
/* config */
|
|
116
98
|
});
|
|
99
|
+
const dag = new DAGEngine();
|
|
117
100
|
```
|
|
118
101
|
|
|
119
|
-
**
|
|
102
|
+
**ES Modules (import)**
|
|
120
103
|
|
|
121
104
|
```javascript
|
|
122
|
-
{
|
|
123
|
-
answer: string,
|
|
124
|
-
sources: Array<{
|
|
125
|
-
content: string,
|
|
126
|
-
metadata: object,
|
|
127
|
-
score: number
|
|
128
|
-
}>,
|
|
129
|
-
metrics: {
|
|
130
|
-
retrievalTime: number,
|
|
131
|
-
generationTime: number,
|
|
132
|
-
totalTime: number
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
#### `pipeline.ingestBatch(files, options)`
|
|
138
|
-
|
|
139
|
-
Batch ingest multiple documents.
|
|
105
|
+
import { createRagPipeline, DAGEngine } from "@devilsdev/rag-pipeline-utils";
|
|
140
106
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
parallel: true,
|
|
144
|
-
maxConcurrency: 3,
|
|
107
|
+
const pipeline = createRagPipeline({
|
|
108
|
+
/* config */
|
|
145
109
|
});
|
|
110
|
+
const dag = new DAGEngine();
|
|
146
111
|
```
|
|
147
112
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
### Plugin Contracts
|
|
113
|
+
### TypeScript Support
|
|
151
114
|
|
|
152
|
-
|
|
115
|
+
**New in v2.2.0:** Complete plugin contract interfaces with 236 lines of type definitions:
|
|
153
116
|
|
|
154
|
-
|
|
117
|
+
```typescript
|
|
118
|
+
import {
|
|
119
|
+
createRagPipeline,
|
|
120
|
+
DAGEngine,
|
|
121
|
+
RagPipelineConfig,
|
|
122
|
+
// Plugin contract interfaces (NEW in v2.2.0)
|
|
123
|
+
LoaderPlugin,
|
|
124
|
+
EmbedderPlugin,
|
|
125
|
+
RetrieverPlugin,
|
|
126
|
+
LLMPlugin,
|
|
127
|
+
RerankerPlugin,
|
|
128
|
+
// Helper types (NEW in v2.2.0)
|
|
129
|
+
Document,
|
|
130
|
+
SearchResult,
|
|
131
|
+
RetrieveOptions,
|
|
132
|
+
LLMResponse,
|
|
133
|
+
} from "@devilsdev/rag-pipeline-utils";
|
|
155
134
|
|
|
156
|
-
|
|
157
|
-
class
|
|
158
|
-
async load(
|
|
159
|
-
//
|
|
160
|
-
return [
|
|
135
|
+
// Type-safe plugin implementation
|
|
136
|
+
class MyLoader implements LoaderPlugin {
|
|
137
|
+
async load(source: string, options?: any): Promise<Document[]> {
|
|
138
|
+
// Your implementation with full type checking
|
|
139
|
+
return [
|
|
140
|
+
{
|
|
141
|
+
id: "doc-1",
|
|
142
|
+
content: "Document content",
|
|
143
|
+
metadata: { source },
|
|
144
|
+
},
|
|
145
|
+
];
|
|
161
146
|
}
|
|
162
147
|
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
#### Embedder Plugin
|
|
166
148
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return [[0.1, 0.2, ...], [0.3, 0.4, ...]];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async embedQuery(query) {
|
|
175
|
-
// Return single vector
|
|
176
|
-
return [0.5, 0.6, ...];
|
|
177
|
-
}
|
|
149
|
+
const config: RagPipelineConfig = {
|
|
150
|
+
loader: new MyLoader(),
|
|
151
|
+
embedder: "my-embedder",
|
|
152
|
+
};
|
|
178
153
|
|
|
179
|
-
|
|
180
|
-
return 1536; // Vector dimensions
|
|
181
|
-
}
|
|
182
|
-
}
|
|
154
|
+
const pipeline = createRagPipeline(config);
|
|
183
155
|
```
|
|
184
156
|
|
|
185
|
-
|
|
157
|
+
### Package Size & Dependencies
|
|
186
158
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
159
|
+
- **Package size**: 244KB (gzipped), 1.1MB (unpacked)
|
|
160
|
+
- **Runtime dependencies**: Only 11 production dependencies
|
|
161
|
+
- **Total install size**: ~15MB (including dependencies) - **50% smaller than v2.1.x**
|
|
162
|
+
- **Tree-shakeable**: ES module exports support tree-shaking
|
|
163
|
+
- **Zero vulnerabilities**: npm audit clean (production dependencies)
|
|
192
164
|
|
|
193
|
-
|
|
194
|
-
const { topK = 5, threshold = 0.7 } = options;
|
|
195
|
-
// Return similar documents
|
|
196
|
-
return [{ content: string, metadata: object, score: number }];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
```
|
|
165
|
+
### Docker Usage
|
|
200
166
|
|
|
201
|
-
|
|
167
|
+
**Basic Docker setup:**
|
|
202
168
|
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
async generate(prompt, options = {}) {
|
|
206
|
-
// Return generated text
|
|
207
|
-
return { text: string, usage: object };
|
|
208
|
-
}
|
|
169
|
+
```dockerfile
|
|
170
|
+
FROM node:18-alpine
|
|
209
171
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return generate();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
172
|
+
WORKDIR /app
|
|
173
|
+
COPY package*.json ./
|
|
174
|
+
RUN npm ci --production
|
|
175
|
+
COPY . .
|
|
176
|
+
|
|
177
|
+
CMD ["node", "index.js"]
|
|
219
178
|
```
|
|
220
179
|
|
|
221
|
-
|
|
180
|
+
**Docker Compose example:**
|
|
222
181
|
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
182
|
+
```yaml
|
|
183
|
+
version: "3.8"
|
|
184
|
+
services:
|
|
185
|
+
rag-pipeline:
|
|
186
|
+
image: node:18-alpine
|
|
187
|
+
working_dir: /app
|
|
188
|
+
volumes:
|
|
189
|
+
- ./:/app
|
|
190
|
+
environment:
|
|
191
|
+
- NODE_ENV=production
|
|
192
|
+
command: npm start
|
|
233
193
|
```
|
|
234
194
|
|
|
235
|
-
##
|
|
236
|
-
|
|
237
|
-
### Environment Variables
|
|
195
|
+
## Quick Start
|
|
238
196
|
|
|
239
|
-
|
|
240
|
-
# OpenAI
|
|
241
|
-
OPENAI_API_KEY=sk-...
|
|
242
|
-
OPENAI_MODEL=gpt-4
|
|
197
|
+
### Basic Pipeline Setup
|
|
243
198
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
PINECONE_ENVIRONMENT=us-east-1
|
|
199
|
+
```javascript
|
|
200
|
+
const { createRagPipeline } = require("@devilsdev/rag-pipeline-utils");
|
|
247
201
|
|
|
248
|
-
|
|
249
|
-
|
|
202
|
+
// Create pipeline with your plugin implementations
|
|
203
|
+
const pipeline = createRagPipeline({
|
|
204
|
+
loader: yourLoaderPlugin,
|
|
205
|
+
embedder: yourEmbedderPlugin,
|
|
206
|
+
retriever: yourRetrieverPlugin,
|
|
207
|
+
llm: yourLLMPlugin,
|
|
208
|
+
});
|
|
250
209
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
210
|
+
// Use the pipeline
|
|
211
|
+
await pipeline.ingest("./document.pdf");
|
|
212
|
+
const result = await pipeline.query("What is this document about?");
|
|
213
|
+
console.log(result);
|
|
254
214
|
```
|
|
255
215
|
|
|
256
|
-
### Configuration File
|
|
216
|
+
### Using Configuration File
|
|
257
217
|
|
|
258
218
|
Create `.ragrc.json`:
|
|
259
219
|
|
|
260
220
|
```json
|
|
261
221
|
{
|
|
262
222
|
"loader": {
|
|
263
|
-
"pdf": "
|
|
264
|
-
"markdown": "@devilsdev/markdown-loader"
|
|
223
|
+
"pdf": "your-pdf-loader-plugin"
|
|
265
224
|
},
|
|
266
225
|
"embedder": {
|
|
267
|
-
"
|
|
226
|
+
"default": "your-embedder-plugin"
|
|
268
227
|
},
|
|
269
228
|
"retriever": {
|
|
270
|
-
"
|
|
229
|
+
"default": "your-vector-db-plugin"
|
|
271
230
|
},
|
|
272
231
|
"llm": {
|
|
273
|
-
"
|
|
274
|
-
},
|
|
275
|
-
"pipeline": {
|
|
276
|
-
"loader": "pdf",
|
|
277
|
-
"embedder": "openai",
|
|
278
|
-
"retriever": "chroma",
|
|
279
|
-
"llm": "openai"
|
|
280
|
-
},
|
|
281
|
-
"performance": {
|
|
282
|
-
"maxConcurrency": 5,
|
|
283
|
-
"enableStreaming": true
|
|
232
|
+
"default": "your-llm-plugin"
|
|
284
233
|
}
|
|
285
234
|
}
|
|
286
235
|
```
|
|
287
236
|
|
|
288
|
-
Load configuration:
|
|
237
|
+
Load and use configuration:
|
|
289
238
|
|
|
290
239
|
```javascript
|
|
291
|
-
const {
|
|
240
|
+
const {
|
|
241
|
+
loadConfig,
|
|
242
|
+
createRagPipeline,
|
|
243
|
+
} = require("@devilsdev/rag-pipeline-utils");
|
|
244
|
+
|
|
292
245
|
const config = await loadConfig(".ragrc.json");
|
|
246
|
+
const pipeline = createRagPipeline(config);
|
|
293
247
|
```
|
|
294
248
|
|
|
295
|
-
##
|
|
249
|
+
## Core API
|
|
296
250
|
|
|
297
|
-
###
|
|
251
|
+
### Exported Modules
|
|
298
252
|
|
|
299
253
|
```javascript
|
|
300
254
|
const {
|
|
255
|
+
// Core pipeline
|
|
301
256
|
createRagPipeline,
|
|
257
|
+
|
|
258
|
+
// Configuration
|
|
259
|
+
loadConfig,
|
|
260
|
+
validateRagrc,
|
|
261
|
+
normalizeConfig,
|
|
262
|
+
|
|
263
|
+
// Plugin system
|
|
302
264
|
pluginRegistry,
|
|
265
|
+
|
|
266
|
+
// DAG workflow engine
|
|
267
|
+
DAGEngine,
|
|
268
|
+
|
|
269
|
+
// Observability
|
|
270
|
+
eventLogger,
|
|
271
|
+
metrics,
|
|
272
|
+
|
|
273
|
+
// Performance
|
|
274
|
+
ParallelProcessor,
|
|
275
|
+
|
|
276
|
+
// AI/ML
|
|
277
|
+
MultiModalProcessor,
|
|
278
|
+
AdaptiveRetrievalEngine,
|
|
279
|
+
|
|
280
|
+
// Enterprise
|
|
281
|
+
AuditLogger,
|
|
282
|
+
DataGovernance,
|
|
283
|
+
|
|
284
|
+
// Utilities
|
|
285
|
+
logger,
|
|
303
286
|
} = require("@devilsdev/rag-pipeline-utils");
|
|
287
|
+
```
|
|
304
288
|
|
|
305
|
-
|
|
306
|
-
pluginRegistry.register("my-embedder", MyCustomEmbedder);
|
|
289
|
+
### createRagPipeline(config)
|
|
307
290
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
291
|
+
Creates a RAG pipeline instance.
|
|
292
|
+
|
|
293
|
+
**Parameters:**
|
|
294
|
+
|
|
295
|
+
- `config.loader` - Document loader plugin
|
|
296
|
+
- `config.embedder` - Text embedding plugin
|
|
297
|
+
- `config.retriever` - Vector storage and retrieval plugin
|
|
298
|
+
- `config.llm` - Language model plugin
|
|
299
|
+
- `config.reranker` (optional) - Result reranking plugin
|
|
300
|
+
|
|
301
|
+
**Returns:** Pipeline instance with `ingest()` and `query()` methods
|
|
302
|
+
|
|
303
|
+
### Configuration Management
|
|
304
|
+
|
|
305
|
+
```javascript
|
|
306
|
+
// Load configuration from file
|
|
307
|
+
const config = await loadConfig(".ragrc.json");
|
|
308
|
+
|
|
309
|
+
// Validate configuration
|
|
310
|
+
const isValid = validateRagrc(config);
|
|
311
|
+
|
|
312
|
+
// Normalize configuration
|
|
313
|
+
const normalized = normalizeConfig(config);
|
|
315
314
|
```
|
|
316
315
|
|
|
317
|
-
###
|
|
316
|
+
### Plugin Registry
|
|
318
317
|
|
|
319
|
-
|
|
318
|
+
```javascript
|
|
319
|
+
const { pluginRegistry } = require("@devilsdev/rag-pipeline-utils");
|
|
320
|
+
|
|
321
|
+
// Register a plugin
|
|
322
|
+
pluginRegistry.register("my-plugin", MyPluginClass);
|
|
323
|
+
|
|
324
|
+
// Get a plugin
|
|
325
|
+
const Plugin = pluginRegistry.get("my-plugin");
|
|
326
|
+
|
|
327
|
+
// List all plugins
|
|
328
|
+
const plugins = pluginRegistry.list();
|
|
329
|
+
|
|
330
|
+
// Check if plugin exists
|
|
331
|
+
const exists = pluginRegistry.has("my-plugin");
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### DAG Workflow Engine
|
|
335
|
+
|
|
336
|
+
Build complex multi-step workflows:
|
|
320
337
|
|
|
321
338
|
```javascript
|
|
322
339
|
const { DAGEngine } = require("@devilsdev/rag-pipeline-utils");
|
|
@@ -326,19 +343,25 @@ const dag = new DAGEngine({
|
|
|
326
343
|
{
|
|
327
344
|
id: "load",
|
|
328
345
|
type: "loader",
|
|
329
|
-
config: {
|
|
346
|
+
config: {
|
|
347
|
+
/* loader config */
|
|
348
|
+
},
|
|
330
349
|
},
|
|
331
350
|
{
|
|
332
351
|
id: "embed",
|
|
333
352
|
type: "embedder",
|
|
334
353
|
dependencies: ["load"],
|
|
335
|
-
config: {
|
|
354
|
+
config: {
|
|
355
|
+
/* embedder config */
|
|
356
|
+
},
|
|
336
357
|
},
|
|
337
358
|
{
|
|
338
359
|
id: "store",
|
|
339
360
|
type: "retriever",
|
|
340
361
|
dependencies: ["embed"],
|
|
341
|
-
config: {
|
|
362
|
+
config: {
|
|
363
|
+
/* retriever config */
|
|
364
|
+
},
|
|
342
365
|
},
|
|
343
366
|
],
|
|
344
367
|
});
|
|
@@ -348,114 +371,325 @@ await dag.execute();
|
|
|
348
371
|
|
|
349
372
|
### Observability
|
|
350
373
|
|
|
351
|
-
Enable monitoring and tracing:
|
|
352
|
-
|
|
353
374
|
```javascript
|
|
354
375
|
const { eventLogger, metrics } = require("@devilsdev/rag-pipeline-utils");
|
|
355
376
|
|
|
356
|
-
// Configure logging
|
|
377
|
+
// Configure event logging
|
|
357
378
|
eventLogger.configure({
|
|
358
379
|
level: "info",
|
|
359
380
|
format: "json",
|
|
360
381
|
});
|
|
361
382
|
|
|
383
|
+
// Log events
|
|
384
|
+
eventLogger.log("info", "Pipeline started", { pipelineId: "abc123" });
|
|
385
|
+
|
|
362
386
|
// Access metrics
|
|
363
387
|
const pipelineMetrics = metrics.getMetrics();
|
|
364
|
-
console.log(pipelineMetrics
|
|
365
|
-
console.log(pipelineMetrics.queries.avgLatency);
|
|
388
|
+
console.log(pipelineMetrics);
|
|
366
389
|
```
|
|
367
390
|
|
|
368
|
-
###
|
|
391
|
+
### Parallel Processing
|
|
369
392
|
|
|
370
393
|
```javascript
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
394
|
+
const { ParallelProcessor } = require("@devilsdev/rag-pipeline-utils");
|
|
395
|
+
|
|
396
|
+
const processor = new ParallelProcessor({
|
|
397
|
+
maxConcurrency: 5,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
await processor.process(items, async (item) => {
|
|
401
|
+
// Process each item
|
|
402
|
+
return processItem(item);
|
|
403
|
+
});
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## Plugin Development
|
|
407
|
+
|
|
408
|
+
This package provides a plugin-based architecture. You need to implement plugins for your specific use case.
|
|
409
|
+
|
|
410
|
+
### Plugin Contracts
|
|
411
|
+
|
|
412
|
+
**New in v2.2.0:** TypeScript interfaces for all plugin contracts. See [TypeScript Support](#typescript-support) for full type definitions.
|
|
413
|
+
|
|
414
|
+
#### Loader Plugin
|
|
415
|
+
|
|
416
|
+
```javascript
|
|
417
|
+
/**
|
|
418
|
+
* Loader plugin interface (NEW TypeScript interface in v2.2.0)
|
|
419
|
+
* Implements: LoaderPlugin
|
|
420
|
+
*/
|
|
421
|
+
class MyLoader {
|
|
422
|
+
async load(source, options) {
|
|
423
|
+
// Load and parse document
|
|
424
|
+
// Return array of Document objects
|
|
425
|
+
return [
|
|
426
|
+
{
|
|
427
|
+
id: "doc-1",
|
|
428
|
+
content: "Document text...",
|
|
429
|
+
metadata: { page: 1, source },
|
|
430
|
+
// embedding: optional pre-computed embedding
|
|
431
|
+
},
|
|
432
|
+
];
|
|
378
433
|
}
|
|
379
434
|
}
|
|
380
435
|
```
|
|
381
436
|
|
|
382
|
-
|
|
437
|
+
#### Embedder Plugin
|
|
438
|
+
|
|
439
|
+
```javascript
|
|
440
|
+
/**
|
|
441
|
+
* Embedder plugin interface (NEW TypeScript interface in v2.2.0)
|
|
442
|
+
* Implements: EmbedderPlugin
|
|
443
|
+
*/
|
|
444
|
+
class MyEmbedder {
|
|
445
|
+
async embed(text, options) {
|
|
446
|
+
// Generate embedding for a single text string
|
|
447
|
+
// Return: Promise<number[]> - embedding vector
|
|
448
|
+
return [0.1, 0.2, 0.3 /* ... 1536 dimensions for OpenAI */];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// Optional batch embedding method
|
|
452
|
+
async embedBatch(texts) {
|
|
453
|
+
// Generate embeddings for multiple texts
|
|
454
|
+
return texts.map((text) => this.embed(text));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
```
|
|
383
458
|
|
|
384
|
-
|
|
459
|
+
#### Retriever Plugin
|
|
460
|
+
|
|
461
|
+
```javascript
|
|
462
|
+
/**
|
|
463
|
+
* Retriever plugin interface (NEW TypeScript interface in v2.2.0)
|
|
464
|
+
* Implements: RetrieverPlugin
|
|
465
|
+
*/
|
|
466
|
+
class MyRetriever {
|
|
467
|
+
async retrieve(query, options) {
|
|
468
|
+
// query can be:
|
|
469
|
+
// - string: search by text
|
|
470
|
+
// - { embedding: number[] }: search by vector
|
|
471
|
+
const { topK = 5, minScore = 0.7, filter } = options || {};
|
|
472
|
+
|
|
473
|
+
// Search for similar vectors
|
|
474
|
+
// Return: Promise<SearchResult[]>
|
|
475
|
+
return [
|
|
476
|
+
{
|
|
477
|
+
id: "result-1",
|
|
478
|
+
score: 0.95,
|
|
479
|
+
document: {
|
|
480
|
+
id: "doc-1",
|
|
481
|
+
content: "Document text...",
|
|
482
|
+
metadata: { source: "file.pdf" },
|
|
483
|
+
},
|
|
484
|
+
metadata: {
|
|
485
|
+
/* additional search metadata */
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
];
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### LLM Plugin
|
|
494
|
+
|
|
495
|
+
```javascript
|
|
496
|
+
/**
|
|
497
|
+
* LLM plugin interface (NEW TypeScript interface in v2.2.0)
|
|
498
|
+
* Implements: LLMPlugin
|
|
499
|
+
*/
|
|
500
|
+
class MyLLM {
|
|
501
|
+
async generate(prompt, options) {
|
|
502
|
+
// Generate text from prompt
|
|
503
|
+
// Return: Promise<LLMResponse>
|
|
504
|
+
return {
|
|
505
|
+
text: "Generated response...",
|
|
506
|
+
usage: {
|
|
507
|
+
promptTokens: 100,
|
|
508
|
+
completionTokens: 50,
|
|
509
|
+
totalTokens: 150,
|
|
510
|
+
},
|
|
511
|
+
metadata: {
|
|
512
|
+
model: "gpt-4",
|
|
513
|
+
finishReason: "stop",
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Optional streaming support
|
|
519
|
+
async *stream(prompt, options) {
|
|
520
|
+
// Stream response chunks
|
|
521
|
+
yield "Generated ";
|
|
522
|
+
yield "response ";
|
|
523
|
+
yield "chunks...";
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
#### Reranker Plugin (Optional)
|
|
529
|
+
|
|
530
|
+
```javascript
|
|
531
|
+
/**
|
|
532
|
+
* Reranker plugin interface (NEW TypeScript interface in v2.2.0)
|
|
533
|
+
* Implements: RerankerPlugin
|
|
534
|
+
*/
|
|
535
|
+
class MyReranker {
|
|
536
|
+
async rerank(results, query, options) {
|
|
537
|
+
// Rerank search results based on relevance to query
|
|
538
|
+
// Return: Promise<SearchResult[]> - reranked results
|
|
539
|
+
return results
|
|
540
|
+
.map((result) => ({
|
|
541
|
+
...result,
|
|
542
|
+
score: calculateRelevanceScore(query, result),
|
|
543
|
+
}))
|
|
544
|
+
.sort((a, b) => b.score - a.score);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
## Environment Configuration
|
|
385
550
|
|
|
386
551
|
```bash
|
|
387
|
-
#
|
|
388
|
-
|
|
552
|
+
# Example environment variables for your plugins
|
|
553
|
+
OPENAI_API_KEY=your_api_key
|
|
554
|
+
PINECONE_API_KEY=your_api_key
|
|
555
|
+
PINECONE_ENVIRONMENT=us-east-1
|
|
556
|
+
CHROMA_URL=http://localhost:8000
|
|
389
557
|
|
|
390
|
-
#
|
|
391
|
-
|
|
558
|
+
# Performance settings
|
|
559
|
+
RAG_MAX_CONCURRENCY=5
|
|
560
|
+
RAG_BATCH_SIZE=10
|
|
561
|
+
```
|
|
392
562
|
|
|
393
|
-
|
|
394
|
-
npx rag-pipeline query "Your question here"
|
|
563
|
+
## Advanced Features
|
|
395
564
|
|
|
396
|
-
|
|
397
|
-
|
|
565
|
+
### Multi-Modal Processing
|
|
566
|
+
|
|
567
|
+
```javascript
|
|
568
|
+
const { MultiModalProcessor } = require("@devilsdev/rag-pipeline-utils");
|
|
569
|
+
|
|
570
|
+
const processor = new MultiModalProcessor({
|
|
571
|
+
// Configuration for processing text, images, audio, etc.
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
await processor.process(multiModalData);
|
|
398
575
|
```
|
|
399
576
|
|
|
400
|
-
|
|
577
|
+
### Adaptive Retrieval
|
|
578
|
+
|
|
579
|
+
```javascript
|
|
580
|
+
const { AdaptiveRetrievalEngine } = require("@devilsdev/rag-pipeline-utils");
|
|
581
|
+
|
|
582
|
+
const retriever = new AdaptiveRetrievalEngine({
|
|
583
|
+
// Configuration for adaptive retrieval strategies
|
|
584
|
+
});
|
|
401
585
|
|
|
402
|
-
|
|
586
|
+
const results = await retriever.retrieve(query, context);
|
|
587
|
+
```
|
|
403
588
|
|
|
404
|
-
|
|
589
|
+
### Enterprise Audit Logging
|
|
405
590
|
|
|
406
591
|
```javascript
|
|
407
|
-
const
|
|
408
|
-
|
|
592
|
+
const { AuditLogger } = require("@devilsdev/rag-pipeline-utils");
|
|
593
|
+
|
|
594
|
+
const auditLogger = new AuditLogger({
|
|
595
|
+
destination: "./audit-logs",
|
|
409
596
|
});
|
|
410
597
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
"
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
598
|
+
auditLogger.log("query", {
|
|
599
|
+
user: "user@example.com",
|
|
600
|
+
query: "sensitive query",
|
|
601
|
+
timestamp: new Date(),
|
|
602
|
+
});
|
|
603
|
+
```
|
|
417
604
|
|
|
418
|
-
|
|
419
|
-
|
|
605
|
+
### Data Governance
|
|
606
|
+
|
|
607
|
+
```javascript
|
|
608
|
+
const { DataGovernance } = require("@devilsdev/rag-pipeline-utils");
|
|
609
|
+
|
|
610
|
+
const governance = new DataGovernance({
|
|
611
|
+
policies: {
|
|
612
|
+
retention: "90d",
|
|
613
|
+
encryption: true,
|
|
614
|
+
},
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
await governance.enforce(data);
|
|
420
618
|
```
|
|
421
619
|
|
|
422
|
-
|
|
620
|
+
## CLI Usage
|
|
621
|
+
|
|
622
|
+
The package includes a CLI tool for pipeline operations:
|
|
623
|
+
|
|
624
|
+
```bash
|
|
625
|
+
# Initialize configuration
|
|
626
|
+
npx rag-pipeline init
|
|
423
627
|
|
|
424
|
-
|
|
628
|
+
# Run pipeline operations (requires plugin implementation)
|
|
629
|
+
npx rag-pipeline ingest ./documents
|
|
630
|
+
npx rag-pipeline query "Your question"
|
|
631
|
+
|
|
632
|
+
# Run system diagnostics
|
|
633
|
+
npx rag-pipeline doctor
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
## Error Handling
|
|
425
637
|
|
|
426
638
|
```javascript
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
639
|
+
try {
|
|
640
|
+
const result = await pipeline.query("What is AI?");
|
|
641
|
+
} catch (error) {
|
|
642
|
+
if (error.code === "PLUGIN_NOT_FOUND") {
|
|
643
|
+
console.error("Required plugin not found:", error.message);
|
|
644
|
+
} else if (error.code === "INVALID_CONFIG") {
|
|
645
|
+
console.error("Invalid configuration:", error.message);
|
|
646
|
+
} else {
|
|
647
|
+
console.error("Pipeline error:", error.message);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
## Use Cases
|
|
653
|
+
|
|
654
|
+
### Document Q&A System
|
|
655
|
+
|
|
656
|
+
```javascript
|
|
657
|
+
// Implement your plugins
|
|
658
|
+
const loader = new PDFLoaderPlugin();
|
|
659
|
+
const embedder = new OpenAIEmbedderPlugin({
|
|
660
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
431
661
|
});
|
|
662
|
+
const retriever = new ChromaRetrieverPlugin({ url: "http://localhost:8000" });
|
|
663
|
+
const llm = new OpenAILLMPlugin({ model: "gpt-4" });
|
|
432
664
|
|
|
433
|
-
|
|
434
|
-
|
|
665
|
+
// Create pipeline
|
|
666
|
+
const pipeline = createRagPipeline({
|
|
667
|
+
loader,
|
|
668
|
+
embedder,
|
|
669
|
+
retriever,
|
|
670
|
+
llm,
|
|
435
671
|
});
|
|
436
|
-
```
|
|
437
672
|
|
|
438
|
-
|
|
673
|
+
// Ingest documents
|
|
674
|
+
await pipeline.ingest("./company-handbook.pdf");
|
|
675
|
+
|
|
676
|
+
// Query
|
|
677
|
+
const answer = await pipeline.query("What is the vacation policy?");
|
|
678
|
+
console.log(answer);
|
|
679
|
+
```
|
|
439
680
|
|
|
440
|
-
|
|
681
|
+
### Knowledge Base Search
|
|
441
682
|
|
|
442
683
|
```javascript
|
|
443
|
-
//
|
|
684
|
+
// Use your custom database retriever
|
|
444
685
|
class PostgresRetriever {
|
|
445
686
|
constructor(connectionString) {
|
|
446
687
|
this.db = new PostgresClient(connectionString);
|
|
447
688
|
}
|
|
448
689
|
|
|
449
|
-
async store(vectors, metadata) {
|
|
450
|
-
await this.db.query(
|
|
451
|
-
"INSERT INTO embeddings (vector, metadata) VALUES ($1, $2)",
|
|
452
|
-
[vectors, metadata],
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
690
|
async retrieve(queryVector, options) {
|
|
457
691
|
const results = await this.db.query(
|
|
458
|
-
"SELECT
|
|
692
|
+
"SELECT content, metadata, vector <-> $1 as score FROM embeddings ORDER BY score LIMIT $2",
|
|
459
693
|
[queryVector, options.topK],
|
|
460
694
|
);
|
|
461
695
|
return results.rows;
|
|
@@ -463,191 +697,216 @@ class PostgresRetriever {
|
|
|
463
697
|
}
|
|
464
698
|
|
|
465
699
|
const pipeline = createRagPipeline({
|
|
466
|
-
loader:
|
|
467
|
-
embedder:
|
|
700
|
+
loader: yourLoader,
|
|
701
|
+
embedder: yourEmbedder,
|
|
468
702
|
retriever: new PostgresRetriever("postgresql://localhost/kb"),
|
|
469
|
-
llm:
|
|
703
|
+
llm: yourLLM,
|
|
470
704
|
});
|
|
471
705
|
```
|
|
472
706
|
|
|
473
|
-
|
|
707
|
+
## Performance Tips
|
|
474
708
|
|
|
475
|
-
|
|
709
|
+
### Batch Processing
|
|
476
710
|
|
|
477
711
|
```javascript
|
|
478
|
-
const
|
|
479
|
-
{ type: "pdf", path: "./research/*.pdf" },
|
|
480
|
-
{ type: "markdown", path: "./docs/*.md" },
|
|
481
|
-
{ type: "api", url: "https://api.example.com/docs" },
|
|
482
|
-
];
|
|
483
|
-
|
|
484
|
-
for (const source of sources) {
|
|
485
|
-
const loader = getLoaderForType(source.type);
|
|
486
|
-
await pipeline.ingest(source.path || source.url, {
|
|
487
|
-
loader,
|
|
488
|
-
metadata: { source: source.type },
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
```
|
|
712
|
+
const { ParallelProcessor } = require("@devilsdev/rag-pipeline-utils");
|
|
492
713
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
714
|
+
const processor = new ParallelProcessor({
|
|
715
|
+
maxConcurrency: 5,
|
|
716
|
+
batchSize: 10,
|
|
717
|
+
});
|
|
496
718
|
|
|
497
|
-
|
|
498
|
-
await
|
|
499
|
-
|
|
500
|
-
chunkOverlap: 200, // Overlap between chunks
|
|
501
|
-
chunkStrategy: "sentence", // 'sentence' | 'paragraph' | 'fixed'
|
|
719
|
+
// Process documents in parallel
|
|
720
|
+
await processor.process(documents, async (doc) => {
|
|
721
|
+
return await pipeline.ingest(doc);
|
|
502
722
|
});
|
|
503
723
|
```
|
|
504
724
|
|
|
505
|
-
###
|
|
725
|
+
### Logging and Monitoring
|
|
506
726
|
|
|
507
727
|
```javascript
|
|
508
|
-
|
|
509
|
-
parallel: true,
|
|
510
|
-
maxConcurrency: 5, // Parallel operations
|
|
511
|
-
batchSize: 10, // Embeddings per batch
|
|
512
|
-
});
|
|
513
|
-
```
|
|
728
|
+
const { logger, metrics } = require("@devilsdev/rag-pipeline-utils");
|
|
514
729
|
|
|
515
|
-
|
|
730
|
+
// Set log level
|
|
731
|
+
logger.setLevel("debug");
|
|
516
732
|
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
522
|
-
cache: true, // Cache embeddings
|
|
523
|
-
cacheTTL: 3600, // Cache lifetime in seconds
|
|
524
|
-
}),
|
|
525
|
-
retriever: new ChromaRetriever({ url: "http://localhost:8000" }),
|
|
526
|
-
llm: new OpenAILLM({ model: "gpt-4" }),
|
|
527
|
-
});
|
|
733
|
+
// Monitor performance
|
|
734
|
+
const stats = metrics.getMetrics();
|
|
735
|
+
console.log("Total queries:", stats.queries?.total || 0);
|
|
736
|
+
console.log("Average latency:", stats.queries?.avgLatency || 0);
|
|
528
737
|
```
|
|
529
738
|
|
|
530
|
-
##
|
|
739
|
+
## Common Integration Examples
|
|
531
740
|
|
|
532
|
-
|
|
741
|
+
### OpenAI + Pinecone Example
|
|
533
742
|
|
|
534
|
-
|
|
535
|
-
import {
|
|
536
|
-
createRagPipeline,
|
|
537
|
-
Pipeline,
|
|
538
|
-
LoaderPlugin,
|
|
539
|
-
EmbedderPlugin,
|
|
540
|
-
RetrieverPlugin,
|
|
541
|
-
LLMPlugin,
|
|
542
|
-
} from "@devilsdev/rag-pipeline-utils";
|
|
743
|
+
**New in v2.2.0:** Complete working example with OpenAI embeddings and Pinecone vector database.
|
|
543
744
|
|
|
544
|
-
|
|
545
|
-
loader: new PDFLoader(),
|
|
546
|
-
embedder: new OpenAIEmbedder({ apiKey: string }),
|
|
547
|
-
retriever: new ChromaRetriever({ url: string }),
|
|
548
|
-
llm: new OpenAILLM({ model: string }),
|
|
549
|
-
});
|
|
745
|
+
See the full example in [`examples/openai-pinecone/`](examples/openai-pinecone/) with:
|
|
550
746
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
747
|
+
- ✅ Complete plugin implementations
|
|
748
|
+
- ✅ Mock mode (no API keys required for testing)
|
|
749
|
+
- ✅ Real OpenAI integration
|
|
750
|
+
- ✅ Real Pinecone integration
|
|
751
|
+
- ✅ Error handling and cost estimation
|
|
752
|
+
- ✅ Comprehensive documentation
|
|
753
|
+
|
|
754
|
+
**Quick start:**
|
|
755
|
+
|
|
756
|
+
```bash
|
|
757
|
+
cd examples/openai-pinecone
|
|
758
|
+
npm install
|
|
759
|
+
|
|
760
|
+
# Test with mock mode (no API keys needed)
|
|
761
|
+
USE_MOCK_MODE=true npm start
|
|
556
762
|
|
|
557
|
-
|
|
763
|
+
# Run with real APIs (requires API keys in .env)
|
|
764
|
+
npm start
|
|
558
765
|
```
|
|
559
766
|
|
|
560
|
-
|
|
767
|
+
### With OpenAI
|
|
561
768
|
|
|
562
|
-
|
|
769
|
+
You need to implement OpenAI plugin wrappers:
|
|
563
770
|
|
|
564
771
|
```javascript
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
// Plugin System
|
|
571
|
-
pluginRegistry,
|
|
772
|
+
class OpenAIEmbedder {
|
|
773
|
+
constructor({ apiKey, model = "text-embedding-ada-002" }) {
|
|
774
|
+
this.client = new OpenAI({ apiKey });
|
|
775
|
+
this.model = model;
|
|
776
|
+
}
|
|
572
777
|
|
|
573
|
-
|
|
574
|
-
|
|
778
|
+
async embed(texts) {
|
|
779
|
+
const response = await this.client.embeddings.create({
|
|
780
|
+
model: this.model,
|
|
781
|
+
input: texts,
|
|
782
|
+
});
|
|
783
|
+
return response.data.map((d) => d.embedding);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
575
786
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
787
|
+
class OpenAILLM {
|
|
788
|
+
constructor({ apiKey, model = "gpt-4" }) {
|
|
789
|
+
this.client = new OpenAI({ apiKey });
|
|
790
|
+
this.model = model;
|
|
791
|
+
}
|
|
579
792
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
793
|
+
async generate(prompt) {
|
|
794
|
+
const response = await this.client.chat.completions.create({
|
|
795
|
+
model: this.model,
|
|
796
|
+
messages: [{ role: "user", content: prompt }],
|
|
797
|
+
});
|
|
798
|
+
return { text: response.choices[0].message.content };
|
|
799
|
+
}
|
|
800
|
+
}
|
|
583
801
|
```
|
|
584
802
|
|
|
585
|
-
###
|
|
803
|
+
### With ChromaDB
|
|
586
804
|
|
|
587
805
|
```javascript
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
806
|
+
class ChromaRetriever {
|
|
807
|
+
constructor({ url, collection }) {
|
|
808
|
+
this.client = new ChromaClient({ path: url });
|
|
809
|
+
this.collectionName = collection;
|
|
810
|
+
}
|
|
593
811
|
|
|
594
|
-
|
|
595
|
-
const
|
|
812
|
+
async store(vectors, metadata) {
|
|
813
|
+
const collection = await this.client.getOrCreateCollection({
|
|
814
|
+
name: this.collectionName,
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
await collection.add({
|
|
818
|
+
embeddings: vectors,
|
|
819
|
+
metadatas: metadata,
|
|
820
|
+
ids: metadata.map((_, i) => `doc_${i}`),
|
|
821
|
+
});
|
|
822
|
+
}
|
|
596
823
|
|
|
597
|
-
|
|
598
|
-
const
|
|
824
|
+
async retrieve(queryVector, options) {
|
|
825
|
+
const collection = await this.client.getCollection({
|
|
826
|
+
name: this.collectionName,
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
const results = await collection.query({
|
|
830
|
+
queryEmbeddings: [queryVector],
|
|
831
|
+
nResults: options.topK || 5,
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
return results.metadatas[0].map((meta, i) => ({
|
|
835
|
+
content: results.documents[0][i],
|
|
836
|
+
metadata: meta,
|
|
837
|
+
score: 1 - results.distances[0][i],
|
|
838
|
+
}));
|
|
839
|
+
}
|
|
840
|
+
}
|
|
599
841
|
```
|
|
600
842
|
|
|
601
843
|
## Troubleshooting
|
|
602
844
|
|
|
603
845
|
### Common Issues
|
|
604
846
|
|
|
605
|
-
**Error:
|
|
847
|
+
**Error: Cannot find module**
|
|
606
848
|
|
|
607
849
|
```bash
|
|
608
|
-
npm install
|
|
850
|
+
npm install @devilsdev/rag-pipeline-utils
|
|
609
851
|
```
|
|
610
852
|
|
|
611
|
-
**Error:
|
|
853
|
+
**Error: Plugin not registered**
|
|
612
854
|
|
|
613
855
|
```javascript
|
|
614
|
-
//
|
|
615
|
-
|
|
616
|
-
const embedder = new OpenAIEmbedder({
|
|
617
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
618
|
-
});
|
|
856
|
+
// Make sure to register your plugins
|
|
857
|
+
pluginRegistry.register("my-embedder", MyEmbedderClass);
|
|
619
858
|
```
|
|
620
859
|
|
|
621
|
-
**Error:
|
|
860
|
+
**Error: Invalid configuration**
|
|
622
861
|
|
|
623
|
-
```
|
|
624
|
-
|
|
625
|
-
|
|
862
|
+
```javascript
|
|
863
|
+
// Validate your configuration
|
|
864
|
+
const { validateRagrc } = require("@devilsdev/rag-pipeline-utils");
|
|
865
|
+
const isValid = validateRagrc(config);
|
|
866
|
+
if (!isValid) {
|
|
867
|
+
console.error("Configuration is invalid");
|
|
868
|
+
}
|
|
626
869
|
```
|
|
627
870
|
|
|
628
871
|
### Debug Mode
|
|
629
872
|
|
|
630
|
-
Enable verbose logging:
|
|
631
|
-
|
|
632
873
|
```javascript
|
|
633
874
|
const { logger } = require("@devilsdev/rag-pipeline-utils");
|
|
634
875
|
|
|
876
|
+
// Enable debug logging
|
|
635
877
|
logger.setLevel("debug");
|
|
636
878
|
```
|
|
637
879
|
|
|
638
880
|
## Examples
|
|
639
881
|
|
|
640
|
-
|
|
882
|
+
### Real-World Integration Examples
|
|
883
|
+
|
|
884
|
+
**[OpenAI + Pinecone Example](examples/openai-pinecone/)** (NEW in v2.2.0)
|
|
885
|
+
|
|
886
|
+
- Complete RAG pipeline implementation
|
|
887
|
+
- OpenAI embeddings (text-embedding-3-small)
|
|
888
|
+
- Pinecone vector database integration
|
|
889
|
+
- Mock mode for testing without API keys
|
|
890
|
+
- Production-ready with error handling
|
|
891
|
+
|
|
892
|
+
**Basic Pipeline Example**
|
|
893
|
+
|
|
894
|
+
- See `examples/basic-pipeline/` for minimal setup
|
|
895
|
+
- Simple in-memory implementation
|
|
896
|
+
- Perfect for learning and prototyping
|
|
897
|
+
|
|
898
|
+
## Documentation
|
|
641
899
|
|
|
642
|
-
-
|
|
643
|
-
-
|
|
644
|
-
-
|
|
645
|
-
-
|
|
646
|
-
-
|
|
900
|
+
- [GitHub Repository](https://github.com/DevilsDev/rag-pipeline-utils)
|
|
901
|
+
- [Issue Tracker](https://github.com/DevilsDev/rag-pipeline-utils/issues)
|
|
902
|
+
- [Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions)
|
|
903
|
+
- [OpenAI + Pinecone Example](examples/openai-pinecone/) (NEW)
|
|
904
|
+
- [Release Notes](https://github.com/DevilsDev/rag-pipeline-utils/releases)
|
|
905
|
+
- [CHANGELOG](CHANGELOG.md)
|
|
647
906
|
|
|
648
907
|
## Contributing
|
|
649
908
|
|
|
650
|
-
Contributions welcome. Please
|
|
909
|
+
Contributions are welcome. Please see the [contribution guidelines](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/docs/CONTRIBUTING.md).
|
|
651
910
|
|
|
652
911
|
## License
|
|
653
912
|
|
|
@@ -655,6 +914,5 @@ GPL-3.0 - See [LICENSE](https://github.com/DevilsDev/rag-pipeline-utils/blob/mai
|
|
|
655
914
|
|
|
656
915
|
## Support
|
|
657
916
|
|
|
658
|
-
- Documentation: https://devilsdev.github.io/rag-pipeline-utils/
|
|
659
917
|
- Issues: https://github.com/DevilsDev/rag-pipeline-utils/issues
|
|
660
|
-
- Discussions: https://github.com/DevilsDev/rag-pipeline-utils/
|
|
918
|
+
- Discussions: https://github.com/DevilsDev/rag-pipeline-utils/discussions
|