@devilsdev/rag-pipeline-utils 1.0.0 → 2.0.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.
Files changed (72) hide show
  1. package/.codecov.yml +21 -0
  2. package/.dockerignore +14 -14
  3. package/.eslintignore +5 -0
  4. package/.eslintrc.json +21 -0
  5. package/.github/workflows/ci.yml +64 -42
  6. package/.husky/pre-commit +5 -0
  7. package/CHANGELOG.md +46 -0
  8. package/Dockerfile +22 -22
  9. package/LICENSE +674 -674
  10. package/README.md +117 -116
  11. package/__tests__/fixtures/.ragrc.json +8 -0
  12. package/__tests__/fixtures/invalid-ragrc.json +4 -0
  13. package/__tests__/fixtures/sample-eval-dataset.json +14 -14
  14. package/__tests__/fixtures/sample.pdf +1 -0
  15. package/__tests__/fixtures/src/mocks/openai-embedder.js +16 -0
  16. package/__tests__/fixtures/src/mocks/openai-llm.js +9 -0
  17. package/__tests__/fixtures/src/mocks/pdf-loader.js +17 -0
  18. package/__tests__/fixtures/src/mocks/pinecone-retriever.js +26 -0
  19. package/__tests__/fixtures/valid-ragrc.json +16 -0
  20. package/__tests__/integration/cli/config-flow.test.js +98 -44
  21. package/__tests__/integration/config/load-config.test.js +67 -52
  22. package/__tests__/unit/config/validate-schema.test.js +121 -0
  23. package/__tests__/unit/core/plugin-registry.test.js +55 -55
  24. package/__tests__/unit/reranker/llm-reranker.test.js +18 -42
  25. package/__tests__/unit/reranker/reranker.enriched.test.js +19 -0
  26. package/__tests__/unit/reranker/reranker.fallback.test.js +15 -0
  27. package/__tests__/unit/reranker/reranker.snapshot.test.js +15 -17
  28. package/__tests__/unit/reranker/reranker.structured-output.test.js +17 -0
  29. package/bin/cli.js +62 -168
  30. package/docs-site/docs/Architecture.md +76 -76
  31. package/docs-site/docs/CLI.md +69 -69
  32. package/docs-site/docs/Evaluation.md +61 -61
  33. package/docs-site/docs/FAQ.md +50 -50
  34. package/docs-site/docs/Plugins.md +61 -61
  35. package/docs-site/docs/Usage.md +72 -72
  36. package/jest.config.js +20 -13
  37. package/package.json +20 -3
  38. package/plugin.config.json +14 -0
  39. package/public/src/App.jsx +57 -57
  40. package/release.config.js +36 -23
  41. package/scripts/banner-injector.js +89 -0
  42. package/scripts/ci-runner.js +51 -0
  43. package/scripts/repair-fixtures.js +30 -0
  44. package/scripts/setup.js +31 -0
  45. package/scripts/test-global-setup.js +18 -0
  46. package/scripts/verify-fixture-mocks.js +45 -0
  47. package/scripts/verify-fixtures.js +36 -0
  48. package/server.js +31 -31
  49. package/src/config/load-config.js +33 -35
  50. package/src/config/load-plugin-config.js +56 -0
  51. package/src/config/validate-plugin-schema.js +28 -0
  52. package/src/config/validate-schema.js +107 -49
  53. package/src/core/create-pipeline.js +96 -82
  54. package/src/core/plugin-contracts.js +21 -0
  55. package/src/core/plugin-registry.js +48 -61
  56. package/src/dag/dag-engine.js +69 -69
  57. package/src/evaluate/evaluator.js +44 -44
  58. package/src/evaluate/scoring.js +73 -73
  59. package/src/loader/csv-loader.js +30 -30
  60. package/src/loader/directory-loader.js +37 -37
  61. package/src/loader/html-loader.js +57 -57
  62. package/src/loader/markdown-loader.js +58 -58
  63. package/src/mocks/openai-embedder.js +30 -0
  64. package/src/mocks/openai-llm.js +18 -0
  65. package/src/mocks/pdf-loader.js +17 -0
  66. package/src/mocks/pinecone-retriever.js +25 -0
  67. package/src/reranker/llm-reranker.js +34 -49
  68. package/src/utils/ci/diagnostic-reporter.js +36 -0
  69. package/src/utils/logger.js +29 -29
  70. package/src/utils/retry.js +42 -42
  71. package/src/utils/validate-plugin-contract.js +36 -0
  72. package/.github/workflows/release.yml +0 -21
@@ -1,76 +1,76 @@
1
- # Architecture
2
-
3
- This page outlines the internal architecture of the RAG pipeline utilities, emphasizing modularity, plugin design, and SOLID-compliant structure.
4
-
5
- ---
6
-
7
- ## 🧩 Core Design Philosophy
8
-
9
- The architecture adheres to enterprise-grade practices:
10
-
11
- - **Single Responsibility**: Each component handles one domain concern
12
- - **Pluggable Interfaces**: Any layer (loader, retriever, LLM) can be swapped
13
- - **Streaming-Ready**: Async flows support token-based output
14
- - **Environment-Safe**: Config via `.ragrc.json`, not hardcoded
15
- - **Testable**: All modules can be mocked and unit tested
16
-
17
- ---
18
-
19
- ## 🏗️ Layered Components
20
-
21
- ```
22
- +-------------------------+
23
- | createRagPipeline() |
24
- +-------------------------+
25
- | | |
26
- ▼ ▼ ▼
27
- Loader Embedder Retriever
28
- ▼ | ▼
29
- Chunks Embeddings Context
30
- \ | /
31
- ▼ ▼ ▼
32
- LLM Runner
33
- |
34
- Output
35
- ```
36
-
37
- ---
38
-
39
- ## 📦 Core Interfaces
40
-
41
- Each plugin is registered via the `PluginRegistry` and looked up by key.
42
-
43
- ```ts
44
- registry.register('loader', 'pdf', new PDFLoader())
45
- const loader = registry.get('loader', 'pdf');
46
- ```
47
-
48
- All plugins implement interface contracts like:
49
-
50
- ```ts
51
- interface Loader {
52
- load(path: string): Promise<{ chunk(): string[] }[]>;
53
- }
54
-
55
- interface Embedder {
56
- embed(chunks: string[]): Vector[];
57
- embedQuery(prompt: string): Vector;
58
- }
59
-
60
- interface Retriever {
61
- store(vectors: Vector[]): Promise<void>;
62
- retrieve(query: Vector): Promise<Context[]>;
63
- }
64
- ```
65
-
66
- ---
67
-
68
- ## 🔁 DAG Support
69
-
70
- The `dag-engine.js` module supports chaining multiple components:
71
- - Example: Summarize → Retrieve → Rerank → LLM
72
- - Enables more complex workflows than linear ingestion/query
73
-
74
- ---
75
-
76
- Next → [Evaluation](./Evaluation.md)
1
+ # Architecture
2
+
3
+ This page outlines the internal architecture of the RAG pipeline utilities, emphasizing modularity, plugin design, and SOLID-compliant structure.
4
+
5
+ ---
6
+
7
+ ## 🧩 Core Design Philosophy
8
+
9
+ The architecture adheres to enterprise-grade practices:
10
+
11
+ - **Single Responsibility**: Each component handles one domain concern
12
+ - **Pluggable Interfaces**: Any layer (loader, retriever, LLM) can be swapped
13
+ - **Streaming-Ready**: Async flows support token-based output
14
+ - **Environment-Safe**: Config via `.ragrc.json`, not hardcoded
15
+ - **Testable**: All modules can be mocked and unit tested
16
+
17
+ ---
18
+
19
+ ## 🏗️ Layered Components
20
+
21
+ ```
22
+ +-------------------------+
23
+ | createRagPipeline() |
24
+ +-------------------------+
25
+ | | |
26
+ ▼ ▼ ▼
27
+ Loader Embedder Retriever
28
+ ▼ | ▼
29
+ Chunks Embeddings Context
30
+ \ | /
31
+ ▼ ▼ ▼
32
+ LLM Runner
33
+ |
34
+ Output
35
+ ```
36
+
37
+ ---
38
+
39
+ ## 📦 Core Interfaces
40
+
41
+ Each plugin is registered via the `PluginRegistry` and looked up by key.
42
+
43
+ ```ts
44
+ registry.register('loader', 'pdf', new PDFLoader())
45
+ const loader = registry.get('loader', 'pdf');
46
+ ```
47
+
48
+ All plugins implement interface contracts like:
49
+
50
+ ```ts
51
+ interface Loader {
52
+ load(path: string): Promise<{ chunk(): string[] }[]>;
53
+ }
54
+
55
+ interface Embedder {
56
+ embed(chunks: string[]): Vector[];
57
+ embedQuery(prompt: string): Vector;
58
+ }
59
+
60
+ interface Retriever {
61
+ store(vectors: Vector[]): Promise<void>;
62
+ retrieve(query: Vector): Promise<Context[]>;
63
+ }
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 🔁 DAG Support
69
+
70
+ The `dag-engine.js` module supports chaining multiple components:
71
+ - Example: Summarize → Retrieve → Rerank → LLM
72
+ - Enables more complex workflows than linear ingestion/query
73
+
74
+ ---
75
+
76
+ Next → [Evaluation](./Evaluation.md)
@@ -1,69 +1,69 @@
1
- # CLI Reference
2
-
3
- The CLI gives you interactive access to the RAG pipeline tools via terminal.
4
-
5
- Install globally (optional):
6
- ```bash
7
- npm install -g @yourorg/rag-pipeline-utils
8
- ```
9
-
10
- Or run directly from your project:
11
- ```bash
12
- npx rag-pipeline <command>
13
- ```
14
-
15
- ---
16
-
17
- ## 🔧 Commands
18
-
19
- ### `ingest`
20
- ```bash
21
- rag-pipeline ingest ./docs/sample.pdf --loader pdf
22
- ```
23
- - Loads and indexes documents into vector store
24
-
25
- ### `query`
26
- ```bash
27
- rag-pipeline query "Explain vector databases" --llm openai-gpt-4
28
- ```
29
- - Retrieves context and generates response
30
-
31
- ### `evaluate`
32
- ```bash
33
- rag-pipeline evaluate ./fixtures/eval.json
34
- ```
35
- - Runs batch evaluation with BLEU/ROUGE scoring
36
-
37
- ### `rerank`
38
- ```bash
39
- rag-pipeline rerank "What is RAG?" --retriever pinecone
40
- ```
41
- - Reorders retrieved context using an LLM reranker
42
-
43
- ---
44
-
45
- ## ⚙️ `.ragrc.json` Config
46
-
47
- Defaults can be set in a file:
48
- ```json
49
- {
50
- "loader": "directory",
51
- "embedder": "openai",
52
- "retriever": "pinecone",
53
- "llm": "openai-gpt-4",
54
- "useReranker": true
55
- }
56
- ```
57
-
58
- ---
59
-
60
- ## 🐳 Docker Usage
61
-
62
- ```bash
63
- docker build -t rag-pipeline .
64
- docker run --rm -v $PWD:/data rag-pipeline query "What is retrieval?"
65
- ```
66
-
67
- ---
68
-
69
- Next → [Architecture](./Architecture.md)
1
+ # CLI Reference
2
+
3
+ The CLI gives you interactive access to the RAG pipeline tools via terminal.
4
+
5
+ Install globally (optional):
6
+ ```bash
7
+ npm install -g @yourorg/rag-pipeline-utils
8
+ ```
9
+
10
+ Or run directly from your project:
11
+ ```bash
12
+ npx rag-pipeline <command>
13
+ ```
14
+
15
+ ---
16
+
17
+ ## 🔧 Commands
18
+
19
+ ### `ingest`
20
+ ```bash
21
+ rag-pipeline ingest ./docs/sample.pdf --loader pdf
22
+ ```
23
+ - Loads and indexes documents into vector store
24
+
25
+ ### `query`
26
+ ```bash
27
+ rag-pipeline query "Explain vector databases" --llm openai-gpt-4
28
+ ```
29
+ - Retrieves context and generates response
30
+
31
+ ### `evaluate`
32
+ ```bash
33
+ rag-pipeline evaluate ./fixtures/eval.json
34
+ ```
35
+ - Runs batch evaluation with BLEU/ROUGE scoring
36
+
37
+ ### `rerank`
38
+ ```bash
39
+ rag-pipeline rerank "What is RAG?" --retriever pinecone
40
+ ```
41
+ - Reorders retrieved context using an LLM reranker
42
+
43
+ ---
44
+
45
+ ## ⚙️ `.ragrc.json` Config
46
+
47
+ Defaults can be set in a file:
48
+ ```json
49
+ {
50
+ "loader": "directory",
51
+ "embedder": "openai",
52
+ "retriever": "pinecone",
53
+ "llm": "openai-gpt-4",
54
+ "useReranker": true
55
+ }
56
+ ```
57
+
58
+ ---
59
+
60
+ ## 🐳 Docker Usage
61
+
62
+ ```bash
63
+ docker build -t rag-pipeline .
64
+ docker run --rm -v $PWD:/data rag-pipeline query "What is retrieval?"
65
+ ```
66
+
67
+ ---
68
+
69
+ Next → [Architecture](./Architecture.md)
@@ -1,61 +1,61 @@
1
- # Evaluation
2
-
3
- This module allows you to evaluate the quality of generated LLM responses in a RAG pipeline.
4
-
5
- ---
6
-
7
- ## 🎯 Objective
8
-
9
- Quantify how well the pipeline performs on question-answer pairs using:
10
- - **BLEU**: Precision on matching tokens
11
- - **ROUGE**: Recall + overlap on longest subsequences
12
- - **LLM Feedback** *(planned)*: Score generation based on LLM ratings
13
-
14
- ---
15
-
16
- ## 📄 Dataset Format
17
-
18
- Each entry in your JSON dataset should include:
19
-
20
- ```json
21
- {
22
- "prompt": "What is a vector index?",
23
- "groundTruth": "A data structure for fast similarity search in vector spaces."
24
- }
25
- ```
26
-
27
- Saved as: `sample-eval-dataset.json`
28
-
29
- ---
30
-
31
- ## 🚀 CLI Evaluation
32
-
33
- ```bash
34
- rag-pipeline evaluate ./fixtures/sample-eval-dataset.json
35
- ```
36
-
37
- Outputs:
38
- - ✅ Pass/fail per item
39
- - 📊 BLEU/ROUGE scores
40
- - 📈 Aggregated metrics
41
-
42
- ---
43
-
44
- ## 📊 Dashboard Visualization
45
-
46
- Use the React dashboard under `/public`:
47
-
48
- ```bash
49
- node server.js
50
- ```
51
-
52
- Visit: [http://localhost:3000](http://localhost:3000)
53
-
54
- Displays:
55
- - Prompt vs Answer
56
- - Success criteria
57
- - Metric charts (BLEU, ROUGE)
58
-
59
- ---
60
-
61
- Next → [Plugins](./Plugins.md)
1
+ # Evaluation
2
+
3
+ This module allows you to evaluate the quality of generated LLM responses in a RAG pipeline.
4
+
5
+ ---
6
+
7
+ ## 🎯 Objective
8
+
9
+ Quantify how well the pipeline performs on question-answer pairs using:
10
+ - **BLEU**: Precision on matching tokens
11
+ - **ROUGE**: Recall + overlap on longest subsequences
12
+ - **LLM Feedback** *(planned)*: Score generation based on LLM ratings
13
+
14
+ ---
15
+
16
+ ## 📄 Dataset Format
17
+
18
+ Each entry in your JSON dataset should include:
19
+
20
+ ```json
21
+ {
22
+ "prompt": "What is a vector index?",
23
+ "groundTruth": "A data structure for fast similarity search in vector spaces."
24
+ }
25
+ ```
26
+
27
+ Saved as: `sample-eval-dataset.json`
28
+
29
+ ---
30
+
31
+ ## 🚀 CLI Evaluation
32
+
33
+ ```bash
34
+ rag-pipeline evaluate ./fixtures/sample-eval-dataset.json
35
+ ```
36
+
37
+ Outputs:
38
+ - ✅ Pass/fail per item
39
+ - 📊 BLEU/ROUGE scores
40
+ - 📈 Aggregated metrics
41
+
42
+ ---
43
+
44
+ ## 📊 Dashboard Visualization
45
+
46
+ Use the React dashboard under `/public`:
47
+
48
+ ```bash
49
+ node server.js
50
+ ```
51
+
52
+ Visit: [http://localhost:3000](http://localhost:3000)
53
+
54
+ Displays:
55
+ - Prompt vs Answer
56
+ - Success criteria
57
+ - Metric charts (BLEU, ROUGE)
58
+
59
+ ---
60
+
61
+ Next → [Plugins](./Plugins.md)
@@ -1,50 +1,50 @@
1
- # FAQ
2
-
3
- ### ❓ Can I use this with my own vector database?
4
- Yes! You can implement the `Retriever` interface and register it:
5
- ```ts
6
- registry.register('retriever', 'mydb', new MyRetriever());
7
- ```
8
- Then use it via CLI or `.ragrc.json`.
9
-
10
- ---
11
-
12
- ### ❓ Is streaming LLM response supported?
13
- Yes. LLM runners can yield async output tokens. This is handled internally via `AsyncIterable` in compatible models.
14
-
15
- ---
16
-
17
- ### ❓ How do I evaluate performance?
18
- Use `rag-pipeline evaluate dataset.json` or open the dashboard at `http://localhost:3000` to visualize BLEU/ROUGE and pass rates.
19
-
20
- ---
21
-
22
- ### ❓ What file types can I ingest?
23
- Currently supported:
24
- - `.pdf` (mocked)
25
- - `.md`
26
- - `.html`
27
- - `.csv`
28
- - Full directory ingestion
29
-
30
- ---
31
-
32
- ### ❓ Can I rerank results using a local model?
33
- Yes, as long as your local LLM implements:
34
- ```ts
35
- llm.generate(prompt, context): Promise<string>
36
- ```
37
- Use it to power `LLMReranker`.
38
-
39
- ---
40
-
41
- ### ❓ How do I contribute?
42
- Fork the repo → add your plugin or CLI feature → test → submit PR.
43
-
44
- ---
45
-
46
- Still stuck? Open an issue at [GitHub](https://github.com/DevilsDev/rag-pipeline-utils/issues).
47
-
48
- ---
49
-
50
- Next → [Back to Introduction](./Introduction.md)
1
+ # FAQ
2
+
3
+ ### ❓ Can I use this with my own vector database?
4
+ Yes! You can implement the `Retriever` interface and register it:
5
+ ```ts
6
+ registry.register('retriever', 'mydb', new MyRetriever());
7
+ ```
8
+ Then use it via CLI or `.ragrc.json`.
9
+
10
+ ---
11
+
12
+ ### ❓ Is streaming LLM response supported?
13
+ Yes. LLM runners can yield async output tokens. This is handled internally via `AsyncIterable` in compatible models.
14
+
15
+ ---
16
+
17
+ ### ❓ How do I evaluate performance?
18
+ Use `rag-pipeline evaluate dataset.json` or open the dashboard at `http://localhost:3000` to visualize BLEU/ROUGE and pass rates.
19
+
20
+ ---
21
+
22
+ ### ❓ What file types can I ingest?
23
+ Currently supported:
24
+ - `.pdf` (mocked)
25
+ - `.md`
26
+ - `.html`
27
+ - `.csv`
28
+ - Full directory ingestion
29
+
30
+ ---
31
+
32
+ ### ❓ Can I rerank results using a local model?
33
+ Yes, as long as your local LLM implements:
34
+ ```ts
35
+ llm.generate(prompt, context): Promise<string>
36
+ ```
37
+ Use it to power `LLMReranker`.
38
+
39
+ ---
40
+
41
+ ### ❓ How do I contribute?
42
+ Fork the repo → add your plugin or CLI feature → test → submit PR.
43
+
44
+ ---
45
+
46
+ Still stuck? Open an issue at [GitHub](https://github.com/DevilsDev/rag-pipeline-utils/issues).
47
+
48
+ ---
49
+
50
+ Next → [Back to Introduction](./Introduction.md)
@@ -1,61 +1,61 @@
1
- # Plugins
2
-
3
- The toolkit is fully modular. You can inject your own loaders, retrievers, embedders, or LLMs.
4
-
5
- ---
6
-
7
- ## 🔌 Plugin Architecture
8
-
9
- All plugins follow a strict interface pattern. Each is registered under a namespace using the plugin registry:
10
-
11
- ```ts
12
- registry.register('loader', 'my-custom', new MyLoader());
13
- const loader = registry.get('loader', 'my-custom');
14
- ```
15
-
16
- You can register plugins for:
17
- - `loader`
18
- - `embedder`
19
- - `retriever`
20
- - `llm`
21
-
22
- ---
23
-
24
- ## 🧱 Loader Example
25
-
26
- ```ts
27
- class MyMarkdownLoader {
28
- async load(filePath) {
29
- const raw = fs.readFileSync(filePath, 'utf-8');
30
- return [{ chunk: () => raw.split('\n\n') }];
31
- }
32
- }
33
- ```
34
-
35
- Register it:
36
- ```ts
37
- registry.register('loader', 'md', new MyMarkdownLoader());
38
- ```
39
-
40
- ---
41
-
42
- ## ⚡ Runtime Override
43
-
44
- CLI and API will resolve plugin names from `pluginRegistry`. Use:
45
-
46
- ```json
47
- {
48
- "loader": "md",
49
- "embedder": "cohere",
50
- "retriever": "chroma",
51
- "llm": "openai-gpt-4"
52
- }
53
- ```
54
-
55
- in `.ragrc.json`
56
-
57
- ---
58
-
59
- This design keeps the core minimal and lets you evolve.
60
-
61
- Next → [FAQ](./FAQ.md)
1
+ # Plugins
2
+
3
+ The toolkit is fully modular. You can inject your own loaders, retrievers, embedders, or LLMs.
4
+
5
+ ---
6
+
7
+ ## 🔌 Plugin Architecture
8
+
9
+ All plugins follow a strict interface pattern. Each is registered under a namespace using the plugin registry:
10
+
11
+ ```ts
12
+ registry.register('loader', 'my-custom', new MyLoader());
13
+ const loader = registry.get('loader', 'my-custom');
14
+ ```
15
+
16
+ You can register plugins for:
17
+ - `loader`
18
+ - `embedder`
19
+ - `retriever`
20
+ - `llm`
21
+
22
+ ---
23
+
24
+ ## 🧱 Loader Example
25
+
26
+ ```ts
27
+ class MyMarkdownLoader {
28
+ async load(filePath) {
29
+ const raw = fs.readFileSync(filePath, 'utf-8');
30
+ return [{ chunk: () => raw.split('\n\n') }];
31
+ }
32
+ }
33
+ ```
34
+
35
+ Register it:
36
+ ```ts
37
+ registry.register('loader', 'md', new MyMarkdownLoader());
38
+ ```
39
+
40
+ ---
41
+
42
+ ## ⚡ Runtime Override
43
+
44
+ CLI and API will resolve plugin names from `pluginRegistry`. Use:
45
+
46
+ ```json
47
+ {
48
+ "loader": "md",
49
+ "embedder": "cohere",
50
+ "retriever": "chroma",
51
+ "llm": "openai-gpt-4"
52
+ }
53
+ ```
54
+
55
+ in `.ragrc.json`
56
+
57
+ ---
58
+
59
+ This design keeps the core minimal and lets you evolve.
60
+
61
+ Next → [FAQ](./FAQ.md)