@devilsdev/rag-pipeline-utils 2.1.12 → 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 +292 -32
- 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
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/DevilsDev/rag-pipeline-utils/main/.ragrc.schema.json",
|
|
4
|
+
"title": "RAG Pipeline Configuration Schema",
|
|
5
|
+
"description": "Configuration schema for @devilsdev/rag-pipeline-utils",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["plugins"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"plugins": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"description": "Plugin specifications for RAG pipeline components",
|
|
12
|
+
"required": ["loader", "embedder", "retriever", "llm"],
|
|
13
|
+
"properties": {
|
|
14
|
+
"loader": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"description": "Document loader plugins",
|
|
17
|
+
"minProperties": 1,
|
|
18
|
+
"additionalProperties": {
|
|
19
|
+
"oneOf": [
|
|
20
|
+
{ "type": "string" },
|
|
21
|
+
{
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["name"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"name": { "type": "string" },
|
|
26
|
+
"version": { "type": "string" },
|
|
27
|
+
"source": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"enum": ["registry", "local", "git", "npm"]
|
|
30
|
+
},
|
|
31
|
+
"path": { "type": "string" },
|
|
32
|
+
"config": { "type": "object" },
|
|
33
|
+
"enabled": { "type": "boolean" }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"embedder": {
|
|
40
|
+
"type": "object",
|
|
41
|
+
"description": "Text embedding plugins",
|
|
42
|
+
"minProperties": 1,
|
|
43
|
+
"additionalProperties": {
|
|
44
|
+
"oneOf": [
|
|
45
|
+
{ "type": "string" },
|
|
46
|
+
{
|
|
47
|
+
"type": "object",
|
|
48
|
+
"required": ["name"],
|
|
49
|
+
"properties": {
|
|
50
|
+
"name": { "type": "string" },
|
|
51
|
+
"version": { "type": "string" },
|
|
52
|
+
"source": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"enum": ["registry", "local", "git", "npm"]
|
|
55
|
+
},
|
|
56
|
+
"path": { "type": "string" },
|
|
57
|
+
"config": { "type": "object" },
|
|
58
|
+
"enabled": { "type": "boolean" }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"retriever": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"description": "Vector retrieval plugins",
|
|
67
|
+
"minProperties": 1,
|
|
68
|
+
"additionalProperties": {
|
|
69
|
+
"oneOf": [
|
|
70
|
+
{ "type": "string" },
|
|
71
|
+
{
|
|
72
|
+
"type": "object",
|
|
73
|
+
"required": ["name"],
|
|
74
|
+
"properties": {
|
|
75
|
+
"name": { "type": "string" },
|
|
76
|
+
"version": { "type": "string" },
|
|
77
|
+
"source": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"enum": ["registry", "local", "git", "npm"]
|
|
80
|
+
},
|
|
81
|
+
"path": { "type": "string" },
|
|
82
|
+
"config": { "type": "object" },
|
|
83
|
+
"enabled": { "type": "boolean" }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"llm": {
|
|
90
|
+
"type": "object",
|
|
91
|
+
"description": "Language model plugins",
|
|
92
|
+
"minProperties": 1,
|
|
93
|
+
"additionalProperties": {
|
|
94
|
+
"oneOf": [
|
|
95
|
+
{ "type": "string" },
|
|
96
|
+
{
|
|
97
|
+
"type": "object",
|
|
98
|
+
"required": ["name"],
|
|
99
|
+
"properties": {
|
|
100
|
+
"name": { "type": "string" },
|
|
101
|
+
"version": { "type": "string" },
|
|
102
|
+
"source": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"enum": ["registry", "local", "git", "npm"]
|
|
105
|
+
},
|
|
106
|
+
"path": { "type": "string" },
|
|
107
|
+
"config": { "type": "object" },
|
|
108
|
+
"enabled": { "type": "boolean" }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"reranker": {
|
|
115
|
+
"type": "object",
|
|
116
|
+
"description": "Result reranking plugins (optional)",
|
|
117
|
+
"minProperties": 1,
|
|
118
|
+
"additionalProperties": {
|
|
119
|
+
"oneOf": [
|
|
120
|
+
{ "type": "string" },
|
|
121
|
+
{
|
|
122
|
+
"type": "object",
|
|
123
|
+
"required": ["name"],
|
|
124
|
+
"properties": {
|
|
125
|
+
"name": { "type": "string" },
|
|
126
|
+
"version": { "type": "string" },
|
|
127
|
+
"source": {
|
|
128
|
+
"type": "string",
|
|
129
|
+
"enum": ["registry", "local", "git", "npm"]
|
|
130
|
+
},
|
|
131
|
+
"path": { "type": "string" },
|
|
132
|
+
"config": { "type": "object" },
|
|
133
|
+
"enabled": { "type": "boolean" }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"additionalProperties": false
|
|
141
|
+
},
|
|
142
|
+
"pipeline": {
|
|
143
|
+
"type": "object",
|
|
144
|
+
"description": "Pipeline execution configuration",
|
|
145
|
+
"properties": {
|
|
146
|
+
"stages": {
|
|
147
|
+
"type": "array",
|
|
148
|
+
"description": "Pipeline execution stages",
|
|
149
|
+
"items": {
|
|
150
|
+
"type": "string",
|
|
151
|
+
"enum": ["loader", "embedder", "retriever", "llm", "reranker"]
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
"mode": {
|
|
155
|
+
"type": "string",
|
|
156
|
+
"description": "Pipeline execution mode",
|
|
157
|
+
"enum": ["sequential", "parallel", "dag"],
|
|
158
|
+
"default": "sequential"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"performance": {
|
|
163
|
+
"type": "object",
|
|
164
|
+
"description": "Performance and optimization settings",
|
|
165
|
+
"properties": {
|
|
166
|
+
"parallel": {
|
|
167
|
+
"type": "object",
|
|
168
|
+
"properties": {
|
|
169
|
+
"enabled": { "type": "boolean", "default": false },
|
|
170
|
+
"maxConcurrency": { "type": "number", "default": 5 },
|
|
171
|
+
"batchSize": { "type": "number", "default": 10 }
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
"streaming": {
|
|
175
|
+
"type": "object",
|
|
176
|
+
"properties": {
|
|
177
|
+
"enabled": { "type": "boolean", "default": false },
|
|
178
|
+
"maxMemoryMB": { "type": "number", "default": 512 },
|
|
179
|
+
"bufferSize": { "type": "number", "default": 100 }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"observability": {
|
|
185
|
+
"type": "object",
|
|
186
|
+
"description": "Logging and monitoring configuration",
|
|
187
|
+
"properties": {
|
|
188
|
+
"logging": {
|
|
189
|
+
"type": "object",
|
|
190
|
+
"properties": {
|
|
191
|
+
"level": {
|
|
192
|
+
"type": "string",
|
|
193
|
+
"enum": ["debug", "info", "warn", "error"],
|
|
194
|
+
"default": "info"
|
|
195
|
+
},
|
|
196
|
+
"structured": { "type": "boolean", "default": true }
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"metrics": {
|
|
200
|
+
"type": "object",
|
|
201
|
+
"properties": {
|
|
202
|
+
"enabled": { "type": "boolean", "default": false },
|
|
203
|
+
"exportFormat": {
|
|
204
|
+
"type": "string",
|
|
205
|
+
"enum": ["prometheus", "json", "statsd"],
|
|
206
|
+
"default": "json"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
"namespace": {
|
|
213
|
+
"type": "string",
|
|
214
|
+
"description": "Configuration namespace for isolation"
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"additionalProperties": false
|
|
218
|
+
}
|
package/README.md
CHANGED
|
@@ -8,6 +8,60 @@
|
|
|
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
|
+
## 🎉 What's New in v2.2.0
|
|
12
|
+
|
|
13
|
+
### Major Improvements
|
|
14
|
+
|
|
15
|
+
**✅ Fixed ESM Build (Critical)**
|
|
16
|
+
|
|
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
|
+
|
|
21
|
+
**📦 50% Smaller Install Size**
|
|
22
|
+
|
|
23
|
+
- Reduced from ~30MB to ~15MB by optimizing dependencies
|
|
24
|
+
- Moved CLI-only tools to devDependencies
|
|
25
|
+
- Zero production vulnerabilities (npm audit clean)
|
|
26
|
+
|
|
27
|
+
**📝 Enhanced TypeScript Support**
|
|
28
|
+
|
|
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
|
|
38
|
+
|
|
39
|
+
**🔧 Real-World Example**
|
|
40
|
+
|
|
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
|
|
45
|
+
|
|
46
|
+
**📚 Documentation Enhancements**
|
|
47
|
+
|
|
48
|
+
- Platform compatibility matrix (Linux, macOS, Windows, Docker)
|
|
49
|
+
- Module system examples (CommonJS + ES Modules)
|
|
50
|
+
- Docker usage examples
|
|
51
|
+
- Troubleshooting guides
|
|
52
|
+
|
|
53
|
+
### Migration from v2.1.x
|
|
54
|
+
|
|
55
|
+
**No breaking changes!** v2.2.0 is fully backward compatible. Simply update:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @devilsdev/rag-pipeline-utils@latest
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
All existing code will continue to work without modifications.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
11
65
|
## Installation
|
|
12
66
|
|
|
13
67
|
```bash
|
|
@@ -16,6 +70,128 @@ npm install @devilsdev/rag-pipeline-utils
|
|
|
16
70
|
|
|
17
71
|
**Requirements:** Node.js >= 18.0.0
|
|
18
72
|
|
|
73
|
+
## Compatibility
|
|
74
|
+
|
|
75
|
+
### Platform Support
|
|
76
|
+
|
|
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 |
|
|
83
|
+
|
|
84
|
+
### Module Systems
|
|
85
|
+
|
|
86
|
+
This package supports both CommonJS and ES Modules:
|
|
87
|
+
|
|
88
|
+
**CommonJS (require)**
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const {
|
|
92
|
+
createRagPipeline,
|
|
93
|
+
DAGEngine,
|
|
94
|
+
} = require("@devilsdev/rag-pipeline-utils");
|
|
95
|
+
|
|
96
|
+
const pipeline = createRagPipeline({
|
|
97
|
+
/* config */
|
|
98
|
+
});
|
|
99
|
+
const dag = new DAGEngine();
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**ES Modules (import)**
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
import { createRagPipeline, DAGEngine } from "@devilsdev/rag-pipeline-utils";
|
|
106
|
+
|
|
107
|
+
const pipeline = createRagPipeline({
|
|
108
|
+
/* config */
|
|
109
|
+
});
|
|
110
|
+
const dag = new DAGEngine();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### TypeScript Support
|
|
114
|
+
|
|
115
|
+
**New in v2.2.0:** Complete plugin contract interfaces with 236 lines of type definitions:
|
|
116
|
+
|
|
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";
|
|
134
|
+
|
|
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
|
+
];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const config: RagPipelineConfig = {
|
|
150
|
+
loader: new MyLoader(),
|
|
151
|
+
embedder: "my-embedder",
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const pipeline = createRagPipeline(config);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Package Size & Dependencies
|
|
158
|
+
|
|
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)
|
|
164
|
+
|
|
165
|
+
### Docker Usage
|
|
166
|
+
|
|
167
|
+
**Basic Docker setup:**
|
|
168
|
+
|
|
169
|
+
```dockerfile
|
|
170
|
+
FROM node:18-alpine
|
|
171
|
+
|
|
172
|
+
WORKDIR /app
|
|
173
|
+
COPY package*.json ./
|
|
174
|
+
RUN npm ci --production
|
|
175
|
+
COPY . .
|
|
176
|
+
|
|
177
|
+
CMD ["node", "index.js"]
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Docker Compose example:**
|
|
181
|
+
|
|
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
|
|
193
|
+
```
|
|
194
|
+
|
|
19
195
|
## Quick Start
|
|
20
196
|
|
|
21
197
|
### Basic Pipeline Setup
|
|
@@ -233,17 +409,25 @@ This package provides a plugin-based architecture. You need to implement plugins
|
|
|
233
409
|
|
|
234
410
|
### Plugin Contracts
|
|
235
411
|
|
|
412
|
+
**New in v2.2.0:** TypeScript interfaces for all plugin contracts. See [TypeScript Support](#typescript-support) for full type definitions.
|
|
413
|
+
|
|
236
414
|
#### Loader Plugin
|
|
237
415
|
|
|
238
416
|
```javascript
|
|
417
|
+
/**
|
|
418
|
+
* Loader plugin interface (NEW TypeScript interface in v2.2.0)
|
|
419
|
+
* Implements: LoaderPlugin
|
|
420
|
+
*/
|
|
239
421
|
class MyLoader {
|
|
240
|
-
async load(
|
|
422
|
+
async load(source, options) {
|
|
241
423
|
// Load and parse document
|
|
242
|
-
// Return array of
|
|
424
|
+
// Return array of Document objects
|
|
243
425
|
return [
|
|
244
426
|
{
|
|
427
|
+
id: "doc-1",
|
|
245
428
|
content: "Document text...",
|
|
246
|
-
metadata: { page: 1, source
|
|
429
|
+
metadata: { page: 1, source },
|
|
430
|
+
// embedding: optional pre-computed embedding
|
|
247
431
|
},
|
|
248
432
|
];
|
|
249
433
|
}
|
|
@@ -253,19 +437,21 @@ class MyLoader {
|
|
|
253
437
|
#### Embedder Plugin
|
|
254
438
|
|
|
255
439
|
```javascript
|
|
440
|
+
/**
|
|
441
|
+
* Embedder plugin interface (NEW TypeScript interface in v2.2.0)
|
|
442
|
+
* Implements: EmbedderPlugin
|
|
443
|
+
*/
|
|
256
444
|
class MyEmbedder {
|
|
257
|
-
async embed(
|
|
258
|
-
// Generate
|
|
259
|
-
// Return
|
|
260
|
-
return [
|
|
261
|
-
[0.1, 0.2, 0.3, ...], // vector for text[0]
|
|
262
|
-
[0.4, 0.5, 0.6, ...] // vector for text[1]
|
|
263
|
-
];
|
|
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 */];
|
|
264
449
|
}
|
|
265
450
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
451
|
+
// Optional batch embedding method
|
|
452
|
+
async embedBatch(texts) {
|
|
453
|
+
// Generate embeddings for multiple texts
|
|
454
|
+
return texts.map((text) => this.embed(text));
|
|
269
455
|
}
|
|
270
456
|
}
|
|
271
457
|
```
|
|
@@ -273,23 +459,31 @@ class MyEmbedder {
|
|
|
273
459
|
#### Retriever Plugin
|
|
274
460
|
|
|
275
461
|
```javascript
|
|
462
|
+
/**
|
|
463
|
+
* Retriever plugin interface (NEW TypeScript interface in v2.2.0)
|
|
464
|
+
* Implements: RetrieverPlugin
|
|
465
|
+
*/
|
|
276
466
|
class MyRetriever {
|
|
277
|
-
async
|
|
278
|
-
//
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const { topK = 5, threshold = 0.7 } = options;
|
|
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 || {};
|
|
283
472
|
|
|
284
473
|
// Search for similar vectors
|
|
285
|
-
// Return
|
|
474
|
+
// Return: Promise<SearchResult[]>
|
|
286
475
|
return [
|
|
287
476
|
{
|
|
288
|
-
|
|
477
|
+
id: "result-1",
|
|
478
|
+
score: 0.95,
|
|
479
|
+
document: {
|
|
480
|
+
id: "doc-1",
|
|
481
|
+
content: "Document text...",
|
|
482
|
+
metadata: { source: "file.pdf" },
|
|
483
|
+
},
|
|
289
484
|
metadata: {
|
|
290
|
-
/*
|
|
485
|
+
/* additional search metadata */
|
|
291
486
|
},
|
|
292
|
-
score: 0.95,
|
|
293
487
|
},
|
|
294
488
|
];
|
|
295
489
|
}
|
|
@@ -299,16 +493,30 @@ class MyRetriever {
|
|
|
299
493
|
#### LLM Plugin
|
|
300
494
|
|
|
301
495
|
```javascript
|
|
496
|
+
/**
|
|
497
|
+
* LLM plugin interface (NEW TypeScript interface in v2.2.0)
|
|
498
|
+
* Implements: LLMPlugin
|
|
499
|
+
*/
|
|
302
500
|
class MyLLM {
|
|
303
|
-
async generate(prompt, options
|
|
501
|
+
async generate(prompt, options) {
|
|
304
502
|
// Generate text from prompt
|
|
503
|
+
// Return: Promise<LLMResponse>
|
|
305
504
|
return {
|
|
306
505
|
text: "Generated response...",
|
|
307
|
-
usage: {
|
|
506
|
+
usage: {
|
|
507
|
+
promptTokens: 100,
|
|
508
|
+
completionTokens: 50,
|
|
509
|
+
totalTokens: 150,
|
|
510
|
+
},
|
|
511
|
+
metadata: {
|
|
512
|
+
model: "gpt-4",
|
|
513
|
+
finishReason: "stop",
|
|
514
|
+
},
|
|
308
515
|
};
|
|
309
516
|
}
|
|
310
517
|
|
|
311
|
-
|
|
518
|
+
// Optional streaming support
|
|
519
|
+
async *stream(prompt, options) {
|
|
312
520
|
// Stream response chunks
|
|
313
521
|
yield "Generated ";
|
|
314
522
|
yield "response ";
|
|
@@ -320,13 +528,18 @@ class MyLLM {
|
|
|
320
528
|
#### Reranker Plugin (Optional)
|
|
321
529
|
|
|
322
530
|
```javascript
|
|
531
|
+
/**
|
|
532
|
+
* Reranker plugin interface (NEW TypeScript interface in v2.2.0)
|
|
533
|
+
* Implements: RerankerPlugin
|
|
534
|
+
*/
|
|
323
535
|
class MyReranker {
|
|
324
|
-
async rerank(
|
|
325
|
-
// Rerank
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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),
|
|
330
543
|
}))
|
|
331
544
|
.sort((a, b) => b.score - a.score);
|
|
332
545
|
}
|
|
@@ -525,6 +738,32 @@ console.log("Average latency:", stats.queries?.avgLatency || 0);
|
|
|
525
738
|
|
|
526
739
|
## Common Integration Examples
|
|
527
740
|
|
|
741
|
+
### OpenAI + Pinecone Example
|
|
742
|
+
|
|
743
|
+
**New in v2.2.0:** Complete working example with OpenAI embeddings and Pinecone vector database.
|
|
744
|
+
|
|
745
|
+
See the full example in [`examples/openai-pinecone/`](examples/openai-pinecone/) with:
|
|
746
|
+
|
|
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
|
|
762
|
+
|
|
763
|
+
# Run with real APIs (requires API keys in .env)
|
|
764
|
+
npm start
|
|
765
|
+
```
|
|
766
|
+
|
|
528
767
|
### With OpenAI
|
|
529
768
|
|
|
530
769
|
You need to implement OpenAI plugin wrappers:
|
|
@@ -638,11 +877,32 @@ const { logger } = require("@devilsdev/rag-pipeline-utils");
|
|
|
638
877
|
logger.setLevel("debug");
|
|
639
878
|
```
|
|
640
879
|
|
|
880
|
+
## Examples
|
|
881
|
+
|
|
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
|
+
|
|
641
898
|
## Documentation
|
|
642
899
|
|
|
643
900
|
- [GitHub Repository](https://github.com/DevilsDev/rag-pipeline-utils)
|
|
644
901
|
- [Issue Tracker](https://github.com/DevilsDev/rag-pipeline-utils/issues)
|
|
645
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)
|
|
646
906
|
|
|
647
907
|
## Contributing
|
|
648
908
|
|
package/bin/cli.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Run the enhanced CLI
|
|
11
|
-
runEnhancedCLI().catch(error => {
|
|
12
|
-
console.error('❌ CLI error:', error.message);
|
|
13
|
-
process.exit(1);
|
|
14
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
require("../src/cli.js")
|
|
4
|
+
.run(process.argv)
|
|
5
|
+
.catch((err) => {
|
|
6
|
+
console.error(err);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
});
|