@devilsdev/rag-pipeline-utils 2.1.9 → 2.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +660 -395
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,395 +1,660 @@
1
- # @DevilsDev/rag-pipeline-utils
2
-
3
- [![CI](https://github.com/DevilsDev/rag-pipeline-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/DevilsDev/rag-pipeline-utils/actions)
4
- [![npm version](https://badge.fury.io/js/%40devilsdev%2Frag-pipeline-utils.svg)](https://badge.fury.io/js/%40devilsdev%2Frag-pipeline-utils)
5
- [![Enterprise Ready](https://img.shields.io/badge/Enterprise-Ready-green.svg)](https://github.com/DevilsDev/rag-pipeline-utils)
6
- [![Node.js Version](https://img.shields.io/node/v/@devilsdev/rag-pipeline-utils.svg)](https://nodejs.org/)
7
- [![License](https://img.shields.io/npm/l/@devilsdev/rag-pipeline-utils.svg)](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/LICENSE)
8
- [![codecov](https://codecov.io/gh/DevilsDev/rag-pipeline-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/DevilsDev/rag-pipeline-utils)
9
- [![Downloads](https://img.shields.io/npm/dm/@devilsdev/rag-pipeline-utils.svg)](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
10
-
11
- > **Enterprise-grade RAG Pipeline Utils toolkit for Node.js** — Build production-ready Retrieval-Augmented Generation systems with modular plugins, streaming support, and comprehensive observability.
12
-
13
- ## Overview
14
-
15
- `@devilsdev/rag-pipeline-utils` is a modular toolkit for building scalable RAG (Retrieval-Augmented Generation) pipelines in Node.js. Designed for enterprise applications, it provides a plugin-based architecture with built-in streaming, performance optimization, observability, and comprehensive testing utilities.
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- ## ✨ Key Features
24
-
25
- ### 🔌 **Plugin Architecture**
26
- - **Modular Components**: Swap loaders, embedders, retrievers, LLMs, and rerankers without code changes
27
- - **Contract Validation**: Runtime and CI verification of plugin interfaces
28
- - **Plugin Marketplace**: Discover and publish community plugins
29
- - **Hot-swappable**: Change components via configuration without restarts
30
-
31
- ### 🚀 **Performance & Scalability**
32
- - **Streaming Support**: Real-time token streaming for LLM responses
33
- - **Parallel Processing**: Concurrent embedding and retrieval operations
34
- - **Memory Safeguards**: Automatic backpressure and memory management
35
- - **Benchmarking Tools**: Built-in performance measurement and optimization
36
-
37
- ### 📊 **Enterprise Observability**
38
- - **Structured Logging**: Comprehensive event tracking and debugging
39
- - **Metrics Collection**: Performance counters, histograms, and gauges
40
- - **Distributed Tracing**: OpenTelemetry-compatible request tracing
41
- - **Health Monitoring**: Built-in diagnostics and system health checks
42
-
43
- ### 🛠️ **Developer Experience**
44
- - **CLI Tools**: Full-featured command-line interface
45
- - **Interactive Wizard**: Guided pipeline setup and configuration
46
- - **Plugin Scaffolding**: Generate new plugins with best practices
47
- - **Comprehensive Testing**: Unit, integration, and contract testing utilities
48
-
49
- ### 🔒 **Production Ready**
50
- - **Schema Validation**: Strict configuration validation with JSON Schema
51
- - **Error Handling**: Robust error recovery and reporting
52
- - **Type Safety**: Full TypeScript support and JSDoc annotations
53
- - **CI/CD Integration**: GitHub Actions workflows and automated testing
54
-
55
- ### 🛡️ **Enterprise Security**
56
- - **Zero Critical Vulnerabilities**: 98→17 vulnerabilities eliminated (83% reduction)
57
- - **Automated Security Monitoring**: GitHub Dependabot with weekly vulnerability scans
58
- - **CI/CD Security Integration**: Build failure on critical vulnerabilities
59
- - **Compliance Ready**: OWASP, NIST, and CIS security standards
60
- - **Dependency Validation**: Automated license and security compliance checking
61
- - **Security Audit Tools**: Built-in `npm run security:audit` and reporting
62
-
63
- ## 📦 Installation
64
-
65
- ### Prerequisites
66
- - **Node.js** 18.0.0 or higher
67
- - **npm** or **yarn** package manager
68
-
69
- ### Install via npm
70
- ```bash
71
- npm install -g @devilsdev/rag-pipeline-utils
72
- ```
73
-
74
- ### Install as project dependency
75
- ```bash
76
- npm install @devilsdev/rag-pipeline-utils
77
- ```
78
-
79
- ## 🚀 Quick Start
80
-
81
- ### 1. Initialize a new RAG pipeline
82
- ```bash
83
- rag-pipeline init
84
- ```
85
- This launches an interactive wizard to configure your pipeline with preferred plugins.
86
-
87
- ### 2. Configure your pipeline
88
- Create a `.ragrc.json` configuration file:
89
-
90
- ```json
91
- {
92
- "loader": {
93
- "pdf": "@devilsdev/pdf-loader",
94
- "markdown": "@devilsdev/markdown-loader"
95
- },
96
- "embedder": {
97
- "openai": "@devilsdev/openai-embedder"
98
- },
99
- "retriever": {
100
- "chroma": "@devilsdev/chroma-retriever"
101
- },
102
- "llm": {
103
- "openai": "@devilsdev/openai-llm"
104
- },
105
- "pipeline": {
106
- "loader": "pdf",
107
- "embedder": "openai",
108
- "retriever": "chroma",
109
- "llm": "openai"
110
- },
111
- "performance": {
112
- "maxConcurrency": 5,
113
- "enableStreaming": true,
114
- "enableObservability": true
115
- }
116
- }
117
- ```
118
-
119
- ## 🖥️ CLI Usage
120
-
121
- ### Document Ingestion
122
- ```bash
123
- # Ingest documents with automatic plugin detection
124
- rag-pipeline ingest ./docs --loader pdf --embedder openai --retriever chroma
125
-
126
- # Ingest with streaming and performance monitoring
127
- rag-pipeline ingest ./docs --stream --benchmark --trace
128
-
129
- # Batch ingest multiple document types
130
- rag-pipeline ingest ./docs/**/*.{pdf,md,txt} --parallel --batch-size 10
131
- ```
132
-
133
- ### Querying
134
- ```bash
135
- # Basic query
136
- rag-pipeline query "What is vector search?" --llm openai
137
-
138
- # Streaming query with real-time responses
139
- rag-pipeline query "Explain RAG architecture" --llm openai --stream
140
-
141
- # Query with custom retrieval parameters
142
- rag-pipeline query "How does embedding work?" --top-k 5 --similarity-threshold 0.8
143
- ```
144
-
145
- ### Advanced Workflows
146
- ```bash
147
- # Run complex DAG pipelines
148
- rag-pipeline dag run ./examples/academic-rag.yaml
149
-
150
- # Interactive pipeline builder
151
- rag-pipeline wizard
152
-
153
- # System diagnostics and health check
154
- rag-pipeline doctor
155
-
156
- # Plugin management
157
- rag-pipeline plugin list
158
- rag-pipeline plugin install @community/custom-embedder
159
- rag-pipeline plugin scaffold my-custom-loader
160
- ```
161
-
162
- ## 🔌 Plugin Architecture
163
-
164
- ### Plugin Contracts
165
- Each plugin type implements a standardized interface with runtime validation:
166
-
167
- | Plugin Type | Required Methods | Optional Methods | Description |
168
- |-------------|------------------|------------------|-------------|
169
- | **Loader** | `load(filePath)` | `validate()`, `getMetadata()` | Document ingestion and parsing |
170
- | **Embedder** | `embed(texts)`, `embedQuery(query)` | `getDimensions()`, `getBatchSize()` | Text vectorization |
171
- | **Retriever** | `store(vectors)`, `retrieve(queryVector)` | `delete()`, `update()` | Vector storage and similarity search |
172
- | **LLM** | `generate(prompt)`, `stream(prompt)` | `getTokenCount()`, `getModels()` | Language model inference |
173
- | **Reranker** | `rerank(query, documents)` | `getScore()` | Result relevance optimization |
174
-
175
- ### Plugin Development
176
- ```javascript
177
- // Example: Custom embedder plugin
178
- export class MyCustomEmbedder {
179
- constructor(options = {}) {
180
- this.apiKey = options.apiKey;
181
- this.model = options.model || 'text-embedding-ada-002';
182
- }
183
-
184
- async embed(texts) {
185
- // Implementation for batch embedding
186
- return vectors;
187
- }
188
-
189
- async embedQuery(query) {
190
- // Implementation for single query embedding
191
- return vector;
192
- }
193
-
194
- // Plugin metadata (required)
195
- static metadata = {
196
- name: 'my-custom-embedder',
197
- version: '1.0.0',
198
- type: 'embedder',
199
- description: 'Custom embedding implementation'
200
- };
201
- }
202
- ```
203
-
204
- ## 🏗️ Architecture Overview
205
-
206
- ```
207
- ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
208
- │ CLI Interface │────│ Pipeline Engine │────│ Plugin Registry │
209
- └─────────────────┘ └──────────────────┘ └─────────────────┘
210
- │
211
- ┌───────────────┼───────────────┐
212
- │ │ │
213
- ┌───────▼──────┐ ┌──────▼──────┐ ┌─────▼─────┐
214
- │ Observability│ │Performance │ │ DAG │
215
- │ System │ │ Optimizer │ │ Engine │
216
- └──────────────┘ └─────────────┘ └───────────┘
217
- │ │ │
218
- ┌───────▼──────┐ ┌──────▼──────┐ ┌─────▼─────┐
219
- │ Logging │ │ Streaming │ │Workflow │
220
- │ Tracing │ │ Parallel │ │Execution │
221
- │ Metrics │ │ Memory │ │Validation │
222
- └──────────────┘ └─────────────┘ └───────────┘
223
- ```
224
-
225
- ## 📁 Project Structure
226
-
227
- ```
228
- @devilsdev/rag-pipeline-utils/
229
- ├── bin/
230
- │ └── cli.js # CLI entry point
231
- ├── src/
232
- │ ├── cli/ # Command-line interface
233
- │ │ ├── enhanced-cli-commands.js
234
- │ │ ├── interactive-wizard.js
235
- │ │ ├── doctor-command.js
236
- │ │ └── plugin-marketplace-commands.js
237
- │ ├── core/ # Core pipeline engine
238
- │ │ ├── create-pipeline.js
239
- │ │ ├── plugin-registry.js
240
- │ │ ├── plugin-contracts.js
241
- │ │ ├── observability/ # Monitoring & logging
242
- │ │ ├── performance/ # Optimization tools
243
- │ │ └── plugin-marketplace/
244
- │ ├── config/ # Configuration management
245
- │ │ ├── load-config.js
246
- │ │ └── enhanced-ragrc-schema.js
247
- │ ├── dag/ # DAG workflow engine
248
- │ │ └── dag-engine.js
249
- │ ├── utils/ # Utility functions
250
- │ │ ├── logger.js
251
- │ │ ├── retry.js
252
- │ │ └── plugin-scaffolder.js
253
- │ └── mocks/ # Development mocks
254
- ├── __tests__/ # Test suites
255
- │ ├── unit/
256
- │ ├── integration/
257
- │ └── fixtures/
258
- ├── docs/ # Documentation
259
- ├── examples/ # Usage examples
260
- ├── scripts/ # Build & maintenance
261
- ├── .ragrc.schema.json # Configuration schema
262
- ├── package.json
263
- └── README.md
264
- ```
265
-
266
-
267
-
268
- ## 📚 Configuration
269
-
270
- ### Environment Variables
271
- ```bash
272
- # OpenAI Configuration
273
- OPENAI_API_KEY=your_openai_api_key
274
- OPENAI_MODEL=gpt-4
275
-
276
- # Vector Database Configuration
277
- PINECONE_API_KEY=your_pinecone_key
278
- PINECONE_ENVIRONMENT=us-west1-gcp
279
-
280
- # Performance Settings
281
- RAG_MAX_CONCURRENCY=5
282
- RAG_BATCH_SIZE=10
283
- RAG_ENABLE_STREAMING=true
284
- ```
285
-
286
- ### Advanced Configuration
287
- ```json
288
- {
289
- "pipeline": {
290
- "loader": "pdf",
291
- "embedder": "openai",
292
- "retriever": "chroma",
293
- "llm": "openai",
294
- "reranker": "cross-encoder"
295
- },
296
- "performance": {
297
- "maxConcurrency": 5,
298
- "batchSize": 10,
299
- "enableStreaming": true,
300
- "enableObservability": true,
301
- "maxMemoryMB": 512,
302
- "tokenLimit": 100000
303
- },
304
- "observability": {
305
- "enableLogging": true,
306
- "enableTracing": true,
307
- "enableMetrics": true,
308
- "logLevel": "info",
309
- "exportFormat": "json"
310
- },
311
- "plugins": {
312
- "marketplace": {
313
- "registryUrl": "https://registry.rag-pipeline.dev",
314
- "autoUpdate": false,
315
- "allowPrerelease": false
316
- }
317
- }
318
- }
319
- ```
320
-
321
- ## 🚀 Use Cases
322
-
323
- ### Enterprise Document Processing
324
- - **Legal Document Analysis**: Process contracts, agreements, and legal documents
325
- - **Technical Documentation**: Index API docs, manuals, and knowledge bases
326
- - **Research Papers**: Academic literature search and analysis
327
- - **Customer Support**: FAQ automation and ticket resolution
328
-
329
- ### Development Workflows
330
- - **Code Documentation**: Generate and maintain code documentation
331
- - **API Integration**: Semantic search across API documentation
332
- - **Knowledge Management**: Team knowledge base and onboarding
333
- - **Content Generation**: Automated content creation and editing
334
-
335
- ### Industry Applications
336
- - **Healthcare**: Medical literature search and clinical decision support
337
- - **Finance**: Financial document analysis and compliance
338
- - **Education**: Personalized learning and content recommendation
339
- - **E-commerce**: Product search and recommendation systems
340
-
341
- ## 🤝 Contributing
342
-
343
- We welcome contributions from the community! Here's how you can help:
344
-
345
- ### Development Setup
346
- ```bash
347
- # Clone the repository
348
- git clone https://github.com/DevilsDev/rag-pipeline-utils.git
349
- cd rag-pipeline-utils
350
-
351
- # Install dependencies
352
- npm install
353
-
354
- # Run tests
355
- npm test
356
-
357
- # Run linting
358
- npm run lint
359
-
360
- # Start development server
361
- npm run dev
362
- ```
363
-
364
- ### Contribution Guidelines
365
- - **Plugin Development**: Create new plugins following our [Plugin Developer Guide](./docs/PLUGIN_DEVELOPER_GUIDE.md)
366
- - **Bug Reports**: Use GitHub Issues with detailed reproduction steps
367
- - **Feature Requests**: Discuss new features in GitHub Discussions
368
- - **Documentation**: Help improve docs and examples
369
- - **Testing**: Add tests for new features and bug fixes
370
-
371
- ### Community
372
- - 💬 [GitHub Discussions](https://github.com/DevilsDev/rag-pipeline-utils/discussions) - Questions and community chat
373
- - 🐛 [GitHub Issues](https://github.com/DevilsDev/rag-pipeline-utils/issues) - Bug reports and feature requests
374
- - 📖 [Documentation](https://devilsdev.github.io/rag-pipeline-utils/) - Comprehensive guides and API docs
375
- - 🔌 [Plugin Marketplace](https://registry.rag-pipeline.dev) - Community plugins and extensions
376
-
377
- ## 📄 License
378
-
379
- This project is licensed under the **Apache License 2.0** - see the [LICENSE](LICENSE) file for details.
380
-
381
- ## 🙏 Acknowledgments
382
-
383
- - Built with ❤️ by [Ali Kahwaji](https://github.com/alikahwaji) and the DevilsDev team
384
- - Inspired by the open-source AI/ML community
385
- - Special thanks to all [contributors](https://github.com/DevilsDev/rag-pipeline-utils/graphs/contributors)
386
-
387
- ---
388
-
389
- <div align="center">
390
- <strong>Ready to build your next RAG application?</strong><br>
391
- <a href="#-installation">Get Started</a> •
392
- <a href="https://devilsdev.github.io/rag-pipeline-utils/">Documentation</a> •
393
- <a href="https://github.com/DevilsDev/rag-pipeline-utils/discussions">Community</a>
394
- </div>
395
-
1
+ # @devilsdev/rag-pipeline-utils
2
+
3
+ [![CI](https://github.com/DevilsDev/rag-pipeline-utils/actions/workflows/ci.yml/badge.svg)](https://github.com/DevilsDev/rag-pipeline-utils/actions)
4
+ [![npm version](https://badge.fury.io/js/%40devilsdev%2Frag-pipeline-utils.svg)](https://badge.fury.io/js/%40devilsdev%2Frag-pipeline-utils)
5
+ [![Node.js Version](https://img.shields.io/node/v/@devilsdev/rag-pipeline-utils.svg)](https://nodejs.org/)
6
+ [![License](https://img.shields.io/npm/l/@devilsdev/rag-pipeline-utils.svg)](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/LICENSE)
7
+ [![Downloads](https://img.shields.io/npm/dm/@devilsdev/rag-pipeline-utils.svg)](https://www.npmjs.com/package/@devilsdev/rag-pipeline-utils)
8
+
9
+ Enterprise-grade toolkit for building Retrieval-Augmented Generation (RAG) pipelines in Node.js with modular plugin architecture, streaming support, and observability.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @devilsdev/rag-pipeline-utils
15
+ ```
16
+
17
+ **Requirements:** Node.js >= 18.0.0
18
+
19
+ ## Quick Start
20
+
21
+ ### Basic Pipeline
22
+
23
+ ```javascript
24
+ const { createRagPipeline } = require("@devilsdev/rag-pipeline-utils");
25
+
26
+ // Initialize pipeline with plugins
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
+ });
42
+
43
+ // Ingest documents
44
+ await pipeline.ingest("./documents/whitepaper.pdf");
45
+
46
+ // Query
47
+ const result = await pipeline.query("What is the main conclusion?");
48
+ console.log(result.answer);
49
+ ```
50
+
51
+ ### Streaming Responses
52
+
53
+ ```javascript
54
+ // Stream tokens in real-time
55
+ const stream = await pipeline.query("Explain the methodology", {
56
+ stream: true,
57
+ });
58
+
59
+ for await (const chunk of stream) {
60
+ process.stdout.write(chunk);
61
+ }
62
+ ```
63
+
64
+ ### Batch Processing
65
+
66
+ ```javascript
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
+ ```
76
+
77
+ ## Core API
78
+
79
+ ### createRagPipeline(config)
80
+
81
+ Creates a pipeline instance with the specified plugins.
82
+
83
+ **Parameters:**
84
+
85
+ - `config.loader` - Document loader plugin
86
+ - `config.embedder` - Text embedding plugin
87
+ - `config.retriever` - Vector storage and retrieval plugin
88
+ - `config.llm` - Language model plugin
89
+ - `config.reranker` (optional) - Result reranking plugin
90
+
91
+ **Returns:** Pipeline instance
92
+
93
+ ### Pipeline Methods
94
+
95
+ #### `pipeline.ingest(filePath, options)`
96
+
97
+ Ingest a document into the pipeline.
98
+
99
+ ```javascript
100
+ await pipeline.ingest("./document.pdf", {
101
+ chunkSize: 1000,
102
+ chunkOverlap: 200,
103
+ metadata: { source: "research", year: 2024 },
104
+ });
105
+ ```
106
+
107
+ #### `pipeline.query(question, options)`
108
+
109
+ Query the pipeline.
110
+
111
+ ```javascript
112
+ const result = await pipeline.query("What is RAG?", {
113
+ topK: 5,
114
+ similarityThreshold: 0.7,
115
+ stream: false,
116
+ });
117
+ ```
118
+
119
+ **Result structure:**
120
+
121
+ ```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.
140
+
141
+ ```javascript
142
+ await pipeline.ingestBatch(["file1.pdf", "file2.pdf"], {
143
+ parallel: true,
144
+ maxConcurrency: 3,
145
+ });
146
+ ```
147
+
148
+ ## Plugin System
149
+
150
+ ### Plugin Contracts
151
+
152
+ All plugins implement standardized interfaces for interoperability.
153
+
154
+ #### Loader Plugin
155
+
156
+ ```javascript
157
+ class CustomLoader {
158
+ async load(filePath) {
159
+ // Return array of document chunks
160
+ return [{ content: string, metadata: object }];
161
+ }
162
+ }
163
+ ```
164
+
165
+ #### Embedder Plugin
166
+
167
+ ```javascript
168
+ class CustomEmbedder {
169
+ async embed(texts) {
170
+ // Return array of vectors
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
+ }
178
+
179
+ getDimensions() {
180
+ return 1536; // Vector dimensions
181
+ }
182
+ }
183
+ ```
184
+
185
+ #### Retriever Plugin
186
+
187
+ ```javascript
188
+ class CustomRetriever {
189
+ async store(vectors, metadata) {
190
+ // Store vectors with metadata
191
+ }
192
+
193
+ async retrieve(queryVector, options = {}) {
194
+ const { topK = 5, threshold = 0.7 } = options;
195
+ // Return similar documents
196
+ return [{ content: string, metadata: object, score: number }];
197
+ }
198
+ }
199
+ ```
200
+
201
+ #### LLM Plugin
202
+
203
+ ```javascript
204
+ class CustomLLM {
205
+ async generate(prompt, options = {}) {
206
+ // Return generated text
207
+ return { text: string, usage: object };
208
+ }
209
+
210
+ async stream(prompt, options = {}) {
211
+ // Return async iterable
212
+ async function* generate() {
213
+ yield chunk1;
214
+ yield chunk2;
215
+ }
216
+ return generate();
217
+ }
218
+ }
219
+ ```
220
+
221
+ #### Reranker Plugin (Optional)
222
+
223
+ ```javascript
224
+ class CustomReranker {
225
+ async rerank(query, documents, options = {}) {
226
+ // Return reranked documents
227
+ return documents.map((doc) => ({
228
+ ...doc,
229
+ score: newScore,
230
+ }));
231
+ }
232
+ }
233
+ ```
234
+
235
+ ## Configuration
236
+
237
+ ### Environment Variables
238
+
239
+ ```bash
240
+ # OpenAI
241
+ OPENAI_API_KEY=sk-...
242
+ OPENAI_MODEL=gpt-4
243
+
244
+ # Pinecone
245
+ PINECONE_API_KEY=...
246
+ PINECONE_ENVIRONMENT=us-east-1
247
+
248
+ # ChromaDB
249
+ CHROMA_URL=http://localhost:8000
250
+
251
+ # Performance
252
+ RAG_MAX_CONCURRENCY=5
253
+ RAG_BATCH_SIZE=10
254
+ ```
255
+
256
+ ### Configuration File
257
+
258
+ Create `.ragrc.json`:
259
+
260
+ ```json
261
+ {
262
+ "loader": {
263
+ "pdf": "@devilsdev/pdf-loader",
264
+ "markdown": "@devilsdev/markdown-loader"
265
+ },
266
+ "embedder": {
267
+ "openai": "@devilsdev/openai-embedder"
268
+ },
269
+ "retriever": {
270
+ "chroma": "@devilsdev/chroma-retriever"
271
+ },
272
+ "llm": {
273
+ "openai": "@devilsdev/openai-llm"
274
+ },
275
+ "pipeline": {
276
+ "loader": "pdf",
277
+ "embedder": "openai",
278
+ "retriever": "chroma",
279
+ "llm": "openai"
280
+ },
281
+ "performance": {
282
+ "maxConcurrency": 5,
283
+ "enableStreaming": true
284
+ }
285
+ }
286
+ ```
287
+
288
+ Load configuration:
289
+
290
+ ```javascript
291
+ const { loadConfig } = require("@devilsdev/rag-pipeline-utils");
292
+ const config = await loadConfig(".ragrc.json");
293
+ ```
294
+
295
+ ## Advanced Usage
296
+
297
+ ### Custom Pipeline Components
298
+
299
+ ```javascript
300
+ const {
301
+ createRagPipeline,
302
+ pluginRegistry,
303
+ } = require("@devilsdev/rag-pipeline-utils");
304
+
305
+ // Register custom plugin
306
+ pluginRegistry.register("my-embedder", MyCustomEmbedder);
307
+
308
+ // Use in pipeline
309
+ const pipeline = createRagPipeline({
310
+ loader: new PDFLoader(),
311
+ embedder: pluginRegistry.get("my-embedder"),
312
+ retriever: new ChromaRetriever({ url: "http://localhost:8000" }),
313
+ llm: new OpenAILLM({ model: "gpt-4" }),
314
+ });
315
+ ```
316
+
317
+ ### DAG Workflows
318
+
319
+ Build complex multi-step pipelines using the DAG engine:
320
+
321
+ ```javascript
322
+ const { DAGEngine } = require("@devilsdev/rag-pipeline-utils");
323
+
324
+ const dag = new DAGEngine({
325
+ nodes: [
326
+ {
327
+ id: "load",
328
+ type: "loader",
329
+ config: { source: "./docs" },
330
+ },
331
+ {
332
+ id: "embed",
333
+ type: "embedder",
334
+ dependencies: ["load"],
335
+ config: { model: "text-embedding-ada-002" },
336
+ },
337
+ {
338
+ id: "store",
339
+ type: "retriever",
340
+ dependencies: ["embed"],
341
+ config: { collection: "documents" },
342
+ },
343
+ ],
344
+ });
345
+
346
+ await dag.execute();
347
+ ```
348
+
349
+ ### Observability
350
+
351
+ Enable monitoring and tracing:
352
+
353
+ ```javascript
354
+ const { eventLogger, metrics } = require("@devilsdev/rag-pipeline-utils");
355
+
356
+ // Configure logging
357
+ eventLogger.configure({
358
+ level: "info",
359
+ format: "json",
360
+ });
361
+
362
+ // Access metrics
363
+ const pipelineMetrics = metrics.getMetrics();
364
+ console.log(pipelineMetrics.queries.total);
365
+ console.log(pipelineMetrics.queries.avgLatency);
366
+ ```
367
+
368
+ ### Error Handling
369
+
370
+ ```javascript
371
+ try {
372
+ const result = await pipeline.query("What is AI?");
373
+ } catch (error) {
374
+ if (error.code === "RETRIEVAL_ERROR") {
375
+ console.error("Vector search failed:", error.message);
376
+ } else if (error.code === "LLM_ERROR") {
377
+ console.error("Generation failed:", error.message);
378
+ }
379
+ }
380
+ ```
381
+
382
+ ## CLI Usage
383
+
384
+ The package includes a CLI for common operations:
385
+
386
+ ```bash
387
+ # Initialize configuration
388
+ npx rag-pipeline init
389
+
390
+ # Ingest documents
391
+ npx rag-pipeline ingest ./docs --loader pdf
392
+
393
+ # Query interactively
394
+ npx rag-pipeline query "Your question here"
395
+
396
+ # Run health check
397
+ npx rag-pipeline doctor
398
+ ```
399
+
400
+ ## Use Cases
401
+
402
+ ### Document Q&A Systems
403
+
404
+ Build question-answering systems over proprietary documents:
405
+
406
+ ```javascript
407
+ const pipeline = createRagPipeline({
408
+ /* config */
409
+ });
410
+
411
+ // Ingest company documentation
412
+ await pipeline.ingestBatch([
413
+ "./docs/handbook.pdf",
414
+ "./docs/policies.pdf",
415
+ "./docs/procedures.pdf",
416
+ ]);
417
+
418
+ // Answer questions
419
+ const answer = await pipeline.query("What is the vacation policy?");
420
+ ```
421
+
422
+ ### Semantic Search
423
+
424
+ Implement semantic search over large document collections:
425
+
426
+ ```javascript
427
+ const results = await pipeline.query("machine learning papers", {
428
+ topK: 10,
429
+ similarityThreshold: 0.75,
430
+ returnSources: true,
431
+ });
432
+
433
+ results.sources.forEach((source) => {
434
+ console.log(`${source.metadata.title} (score: ${source.score})`);
435
+ });
436
+ ```
437
+
438
+ ### Knowledge Base Integration
439
+
440
+ Integrate with existing knowledge bases:
441
+
442
+ ```javascript
443
+ // Custom retriever for your database
444
+ class PostgresRetriever {
445
+ constructor(connectionString) {
446
+ this.db = new PostgresClient(connectionString);
447
+ }
448
+
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
+ async retrieve(queryVector, options) {
457
+ const results = await this.db.query(
458
+ "SELECT * FROM embeddings ORDER BY vector <-> $1 LIMIT $2",
459
+ [queryVector, options.topK],
460
+ );
461
+ return results.rows;
462
+ }
463
+ }
464
+
465
+ const pipeline = createRagPipeline({
466
+ loader: new PDFLoader(),
467
+ embedder: new OpenAIEmbedder({ apiKey: process.env.OPENAI_API_KEY }),
468
+ retriever: new PostgresRetriever("postgresql://localhost/kb"),
469
+ llm: new OpenAILLM({ model: "gpt-4" }),
470
+ });
471
+ ```
472
+
473
+ ### Multi-Source Aggregation
474
+
475
+ Combine data from multiple sources:
476
+
477
+ ```javascript
478
+ const sources = [
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
+ ```
492
+
493
+ ## Performance Optimization
494
+
495
+ ### Chunking Strategies
496
+
497
+ ```javascript
498
+ await pipeline.ingest("./large-document.pdf", {
499
+ chunkSize: 1000, // Characters per chunk
500
+ chunkOverlap: 200, // Overlap between chunks
501
+ chunkStrategy: "sentence", // 'sentence' | 'paragraph' | 'fixed'
502
+ });
503
+ ```
504
+
505
+ ### Concurrent Processing
506
+
507
+ ```javascript
508
+ await pipeline.ingestBatch(files, {
509
+ parallel: true,
510
+ maxConcurrency: 5, // Parallel operations
511
+ batchSize: 10, // Embeddings per batch
512
+ });
513
+ ```
514
+
515
+ ### Caching
516
+
517
+ ```javascript
518
+ const pipeline = createRagPipeline({
519
+ loader: new PDFLoader(),
520
+ embedder: new OpenAIEmbedder({
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
+ });
528
+ ```
529
+
530
+ ## TypeScript Support
531
+
532
+ Full TypeScript definitions included:
533
+
534
+ ```typescript
535
+ import {
536
+ createRagPipeline,
537
+ Pipeline,
538
+ LoaderPlugin,
539
+ EmbedderPlugin,
540
+ RetrieverPlugin,
541
+ LLMPlugin,
542
+ } from "@devilsdev/rag-pipeline-utils";
543
+
544
+ const pipeline: Pipeline = createRagPipeline({
545
+ loader: new PDFLoader(),
546
+ embedder: new OpenAIEmbedder({ apiKey: string }),
547
+ retriever: new ChromaRetriever({ url: string }),
548
+ llm: new OpenAILLM({ model: string }),
549
+ });
550
+
551
+ interface QueryResult {
552
+ answer: string;
553
+ sources: Source[];
554
+ metrics: Metrics;
555
+ }
556
+
557
+ const result: QueryResult = await pipeline.query("question");
558
+ ```
559
+
560
+ ## API Reference
561
+
562
+ ### Exported Modules
563
+
564
+ ```javascript
565
+ const {
566
+ // Core
567
+ createRagPipeline,
568
+ loadConfig,
569
+
570
+ // Plugin System
571
+ pluginRegistry,
572
+
573
+ // Workflow Engine
574
+ DAGEngine,
575
+
576
+ // Observability
577
+ eventLogger,
578
+ metrics,
579
+
580
+ // Utilities
581
+ logger,
582
+ } = require("@devilsdev/rag-pipeline-utils");
583
+ ```
584
+
585
+ ### Plugin Registry API
586
+
587
+ ```javascript
588
+ // Register plugin
589
+ pluginRegistry.register("name", PluginClass);
590
+
591
+ // Get plugin
592
+ const Plugin = pluginRegistry.get("name");
593
+
594
+ // List plugins
595
+ const plugins = pluginRegistry.list();
596
+
597
+ // Check if plugin exists
598
+ const exists = pluginRegistry.has("name");
599
+ ```
600
+
601
+ ## Troubleshooting
602
+
603
+ ### Common Issues
604
+
605
+ **Error: Module not found**
606
+
607
+ ```bash
608
+ npm install --save @devilsdev/rag-pipeline-utils
609
+ ```
610
+
611
+ **Error: Invalid API key**
612
+
613
+ ```javascript
614
+ // Ensure environment variables are set
615
+ require("dotenv").config();
616
+ const embedder = new OpenAIEmbedder({
617
+ apiKey: process.env.OPENAI_API_KEY,
618
+ });
619
+ ```
620
+
621
+ **Error: Connection refused (ChromaDB)**
622
+
623
+ ```bash
624
+ # Start ChromaDB server
625
+ docker run -p 8000:8000 chromadb/chroma
626
+ ```
627
+
628
+ ### Debug Mode
629
+
630
+ Enable verbose logging:
631
+
632
+ ```javascript
633
+ const { logger } = require("@devilsdev/rag-pipeline-utils");
634
+
635
+ logger.setLevel("debug");
636
+ ```
637
+
638
+ ## Examples
639
+
640
+ See the [examples directory](https://github.com/DevilsDev/rag-pipeline-utils/tree/main/examples) for complete working examples:
641
+
642
+ - Basic RAG pipeline
643
+ - Streaming responses
644
+ - Custom plugins
645
+ - DAG workflows
646
+ - Multi-source ingestion
647
+
648
+ ## Contributing
649
+
650
+ Contributions welcome. Please read the [contribution guidelines](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/docs/CONTRIBUTING.md) and [plugin developer guide](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/docs/PLUGIN_DEVELOPER_GUIDE.md).
651
+
652
+ ## License
653
+
654
+ GPL-3.0 - See [LICENSE](https://github.com/DevilsDev/rag-pipeline-utils/blob/main/LICENSE) for details.
655
+
656
+ ## Support
657
+
658
+ - Documentation: https://devilsdev.github.io/rag-pipeline-utils/
659
+ - Issues: https://github.com/DevilsDev/rag-pipeline-utils/issues
660
+ - Discussions: https://github.com/DevilsDev/rag-pipeline-utils/discussionsDo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devilsdev/rag-pipeline-utils",
3
- "version": "2.1.9",
3
+ "version": "2.1.11",
4
4
  "description": "A comprehensive enterprise-grade toolkit for building RAG (Retrieval-Augmented Generation) pipelines with advanced AI/ML capabilities",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "commonjs",