@devilsdev/rag-pipeline-utils 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +14 -14
- package/.eslintignore +5 -0
- package/.eslintrc.json +21 -0
- package/.github/workflows/ci.yml +46 -42
- package/.github/workflows/release.yml +20 -21
- package/CHANGELOG.md +13 -0
- package/Dockerfile +22 -22
- package/LICENSE +674 -674
- package/README.md +117 -116
- package/__tests__/fixtures/sample-eval-dataset.json +14 -14
- package/__tests__/fixtures/sample.pdf +1 -0
- package/__tests__/integration/cli/config-flow.test.js +29 -44
- package/__tests__/integration/config/load-config.test.js +52 -52
- package/__tests__/unit/core/plugin-registry.test.js +55 -55
- package/__tests__/unit/reranker/llm-reranker.test.js +42 -42
- package/__tests__/unit/reranker/reranker.snapshot.test.js +17 -17
- package/bin/cli.js +168 -168
- package/docs-site/docs/Architecture.md +76 -76
- package/docs-site/docs/CLI.md +69 -69
- package/docs-site/docs/Evaluation.md +61 -61
- package/docs-site/docs/FAQ.md +50 -50
- package/docs-site/docs/Plugins.md +61 -61
- package/docs-site/docs/Usage.md +72 -72
- package/jest.config.js +20 -13
- package/package.json +4 -2
- package/public/src/App.jsx +57 -57
- package/release.config.js +36 -23
- package/scripts/setup.js +7 -0
- package/scripts/test-global-setup.js +18 -0
- package/server.js +31 -31
- package/src/config/load-config.js +35 -35
- package/src/config/validate-schema.js +49 -49
- package/src/core/create-pipeline.js +82 -82
- package/src/core/plugin-registry.js +61 -61
- package/src/dag/dag-engine.js +69 -69
- package/src/evaluate/evaluator.js +44 -44
- package/src/evaluate/scoring.js +73 -73
- package/src/loader/csv-loader.js +30 -30
- package/src/loader/directory-loader.js +37 -37
- package/src/loader/html-loader.js +57 -57
- package/src/loader/markdown-loader.js +58 -58
- package/src/reranker/llm-reranker.js +48 -48
- package/src/utils/logger.js +29 -29
- package/src/utils/retry.js +42 -42
package/README.md
CHANGED
|
@@ -1,116 +1,117 @@
|
|
|
1
|
-
# @DevilsDev/rag-pipeline-utils
|
|
2
|
-
|
|
3
|
-
[](https://github.com/DevilsDev/rag-pipeline-utils/actions)
|
|
4
|
-
[](https://codecov.io/gh/DevilsDev/rag-pipeline-utils)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- ✅
|
|
14
|
-
- ✅
|
|
15
|
-
- ✅
|
|
16
|
-
- ✅
|
|
17
|
-
- ✅
|
|
18
|
-
- ✅
|
|
19
|
-
- ✅
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
rag-pipeline
|
|
63
|
-
rag-pipeline
|
|
64
|
-
rag-pipeline
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
├──
|
|
87
|
-
├──
|
|
88
|
-
├──
|
|
89
|
-
├──
|
|
90
|
-
/
|
|
91
|
-
/
|
|
92
|
-
/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
# @DevilsDev/rag-pipeline-utils
|
|
2
|
+
|
|
3
|
+
[](https://github.com/DevilsDev/rag-pipeline-utils/actions)
|
|
4
|
+
[](https://codecov.io/gh/DevilsDev/rag-pipeline-utils)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**A modular Node.js toolkit for building RAG (Retrieval-Augmented Generation) pipelines with clean abstractions, pluggable components, and scalable architecture.**
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- ✅ Plugin-based architecture for RAG pipelines
|
|
14
|
+
- ✅ Embedding + retrieval abstraction
|
|
15
|
+
- ✅ Vector DB integrations (e.g., Pinecone)
|
|
16
|
+
- ✅ Modular document loaders (PDF, HTML, Markdown, CSV, Directory)
|
|
17
|
+
- ✅ CLI with `.ragrc.json` config fallback
|
|
18
|
+
- ✅ Retry, backoff, and logging built-in
|
|
19
|
+
- ✅ Reranker support and evaluation tooling
|
|
20
|
+
- ✅ React dashboard for evaluation results
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @yourorg/rag-pipeline-utils
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import { createRagPipeline } from '@yourorg/rag-pipeline-utils';
|
|
36
|
+
|
|
37
|
+
const rag = createRagPipeline({
|
|
38
|
+
loader: 'markdown',
|
|
39
|
+
embedder: 'openai',
|
|
40
|
+
retriever: 'pinecone',
|
|
41
|
+
llm: 'openai-gpt-4',
|
|
42
|
+
useReranker: true
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const answer = await rag.query('What is a vector database?');
|
|
46
|
+
console.log(answer);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Testing
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm test
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## CLI
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
rag-pipeline ingest ./docs/my.pdf --loader pdf
|
|
63
|
+
rag-pipeline query "Explain RAG pipelines" --llm openai-gpt-4
|
|
64
|
+
rag-pipeline evaluate ./fixtures/sample-eval-dataset.json
|
|
65
|
+
rag-pipeline rerank "Explain embeddings" --retriever pinecone
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Supports `.ragrc.json` fallback configuration:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"loader": "directory",
|
|
73
|
+
"embedder": "openai",
|
|
74
|
+
"retriever": "pinecone",
|
|
75
|
+
"llm": "openai-gpt-4",
|
|
76
|
+
"useReranker": true
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Project Structure
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
/src
|
|
86
|
+
├── core/ # Pipeline + registry
|
|
87
|
+
├── loader/ # Loaders for md, html, csv, dir
|
|
88
|
+
├── reranker/ # LLM-based context reranker
|
|
89
|
+
├── evaluate/ # Scoring, batch QA evaluation
|
|
90
|
+
├── utils/ # Logger, retry, schema
|
|
91
|
+
/bin/cli.js # CLI entrypoint
|
|
92
|
+
/__tests__/ # Unit, integration, snapshot tests
|
|
93
|
+
/public/ # Evaluation dashboard (React)
|
|
94
|
+
.github/workflows/ci.yml # CI config
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Evaluation Dashboard
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
node server.js
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Visit: [http://localhost:3000](http://localhost:3000) → Visualizes metrics, BLEU/ROUGE, pass rate.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
Apache-2.0
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 👤 Author
|
|
116
|
+
|
|
117
|
+
Ali Kahwaji — [@DevilsDev](https://github.com/DevilsDev)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"prompt": "What is a vector database?",
|
|
4
|
-
"expected": "A vector database is a system optimized for storing and retrieving data represented as vectors, often used in similarity search."
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
"prompt": "Explain what chunking means in RAG.",
|
|
8
|
-
"expected": "Chunking is the process of splitting documents into smaller, manageable pieces for embedding and retrieval in a RAG pipeline."
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"prompt": "What is the role of embedding in a RAG pipeline?",
|
|
12
|
-
"expected": "Embeddings convert text into numerical vector form so they can be compared in a vector database during retrieval."
|
|
13
|
-
}
|
|
14
|
-
]
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"prompt": "What is a vector database?",
|
|
4
|
+
"expected": "A vector database is a system optimized for storing and retrieving data represented as vectors, often used in similarity search."
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"prompt": "Explain what chunking means in RAG.",
|
|
8
|
+
"expected": "Chunking is the process of splitting documents into smaller, manageable pieces for embedding and retrieval in a RAG pipeline."
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"prompt": "What is the role of embedding in a RAG pipeline?",
|
|
12
|
+
"expected": "Embeddings convert text into numerical vector form so they can be compared in a vector database during retrieval."
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
15
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
%PDF-1.4\n%âãÏÓ\n1 0 obj\n<<>>\nendobj\nxref\n0 2\n0000000000 65535 f\n0000000010 00000 n\ntrailer\n<<>>\nstartxref\n9\n%%EOF
|
|
@@ -1,44 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 0.1.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
if (fs.existsSync(CONFIG_PATH)) fs.unlinkSync(CONFIG_PATH);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('executes CLI ingest using config fallback', () => {
|
|
36
|
-
const result = execSync(`node ${CLI_PATH} ingest ./sample.pdf`, { encoding: 'utf-8' });
|
|
37
|
-
expect(result).toContain('Ingestion complete');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('executes CLI query using config fallback', () => {
|
|
41
|
-
const output = execSync(`node ${CLI_PATH} query "What is a vector?"`, { encoding: 'utf-8' });
|
|
42
|
-
expect(output).toContain('Answer:');
|
|
43
|
-
});
|
|
44
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Version: 0.1.3
|
|
3
|
+
* Description: Integration test for CLI with config fallback
|
|
4
|
+
* Author: Ali Kahwaji
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { execSync } from 'child_process';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
|
|
10
|
+
const CLI_PATH = path.resolve('bin/cli.js');
|
|
11
|
+
|
|
12
|
+
describe('CLI integration with .ragrc.json config fallback', () => {
|
|
13
|
+
test('executes CLI ingest using config fallback', () => {
|
|
14
|
+
const result = execSync(
|
|
15
|
+
`node ${CLI_PATH} ingest ./__tests__/fixtures/sample.pdf --loader pdf --embedder openai --retriever pinecone`,
|
|
16
|
+
{ encoding: 'utf-8' }
|
|
17
|
+
);
|
|
18
|
+
expect(result).toContain('Ingestion complete');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('executes CLI query using config fallback', () => {
|
|
22
|
+
const result = execSync(
|
|
23
|
+
`node ${CLI_PATH} query "What is this test about?" --embedder openai --retriever pinecone --llm openai-gpt-4`,
|
|
24
|
+
{ encoding: 'utf-8' }
|
|
25
|
+
);
|
|
26
|
+
// Adjust expectation to check for a known part of the generated answer
|
|
27
|
+
expect(result).toContain('Generated answer using: Chunk about pine trees');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 0.1.0
|
|
3
|
-
* Path: /__tests__/integration/config/load-config.test.js
|
|
4
|
-
* Description: Integration tests for loading and validating .ragrc.json config
|
|
5
|
-
* Author: Ali Kahwaji
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import fs from 'fs';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
import { loadRagConfig } from '../../../src/config/load-config.js';
|
|
11
|
-
|
|
12
|
-
const FIXTURE_PATH = path.resolve(process.cwd(), '.ragrc.json');
|
|
13
|
-
|
|
14
|
-
const validConfig = {
|
|
15
|
-
loader: 'pdf',
|
|
16
|
-
embedder: 'openai',
|
|
17
|
-
retriever: 'pinecone',
|
|
18
|
-
llm: 'openai-gpt-4',
|
|
19
|
-
chunk: {
|
|
20
|
-
strategy: 'semantic',
|
|
21
|
-
size: 500
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const invalidConfig = {
|
|
26
|
-
loader: 'pdf',
|
|
27
|
-
chunk: { size: 'large' } // Missing required keys + invalid type
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
describe('loadRagConfig()', () => {
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
if (fs.existsSync(FIXTURE_PATH)) {
|
|
33
|
-
fs.unlinkSync(FIXTURE_PATH);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('loads a valid .ragrc.json config file successfully', () => {
|
|
38
|
-
fs.writeFileSync(FIXTURE_PATH, JSON.stringify(validConfig, null, 2));
|
|
39
|
-
const result = loadRagConfig();
|
|
40
|
-
expect(result).toMatchObject(validConfig);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('throws validation error for invalid .ragrc.json config', () => {
|
|
44
|
-
fs.writeFileSync(FIXTURE_PATH, JSON.stringify(invalidConfig, null, 2));
|
|
45
|
-
expect(() => loadRagConfig()).toThrow(/Invalid config/);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('throws error if config file does not exist', () => {
|
|
49
|
-
expect(() => loadRagConfig()).toThrow(/Config file not found/);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Version: 0.1.0
|
|
3
|
+
* Path: /__tests__/integration/config/load-config.test.js
|
|
4
|
+
* Description: Integration tests for loading and validating .ragrc.json config
|
|
5
|
+
* Author: Ali Kahwaji
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { loadRagConfig } from '../../../src/config/load-config.js';
|
|
11
|
+
|
|
12
|
+
const FIXTURE_PATH = path.resolve(process.cwd(), '.ragrc.json');
|
|
13
|
+
|
|
14
|
+
const validConfig = {
|
|
15
|
+
loader: 'pdf',
|
|
16
|
+
embedder: 'openai',
|
|
17
|
+
retriever: 'pinecone',
|
|
18
|
+
llm: 'openai-gpt-4',
|
|
19
|
+
chunk: {
|
|
20
|
+
strategy: 'semantic',
|
|
21
|
+
size: 500
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const invalidConfig = {
|
|
26
|
+
loader: 'pdf',
|
|
27
|
+
chunk: { size: 'large' } // Missing required keys + invalid type
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('loadRagConfig()', () => {
|
|
31
|
+
afterEach(() => {
|
|
32
|
+
if (fs.existsSync(FIXTURE_PATH)) {
|
|
33
|
+
fs.unlinkSync(FIXTURE_PATH);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('loads a valid .ragrc.json config file successfully', () => {
|
|
38
|
+
fs.writeFileSync(FIXTURE_PATH, JSON.stringify(validConfig, null, 2));
|
|
39
|
+
const result = loadRagConfig();
|
|
40
|
+
expect(result).toMatchObject(validConfig);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('throws validation error for invalid .ragrc.json config', () => {
|
|
44
|
+
fs.writeFileSync(FIXTURE_PATH, JSON.stringify(invalidConfig, null, 2));
|
|
45
|
+
expect(() => loadRagConfig()).toThrow(/Invalid config/);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('throws error if config file does not exist', () => {
|
|
49
|
+
expect(() => loadRagConfig()).toThrow(/Config file not found/);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 0.1.0
|
|
3
|
-
* Path: /__tests__/unit/core/plugin-registry.test.js
|
|
4
|
-
* Description: Unit tests for the PluginRegistry class
|
|
5
|
-
* Author: Ali Kahwaji
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { PluginRegistry } from '../../../src/core/plugin-registry.js';
|
|
9
|
-
|
|
10
|
-
describe('PluginRegistry', () => {
|
|
11
|
-
let registry;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
registry = new PluginRegistry();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('registers and retrieves a plugin successfully', () => {
|
|
18
|
-
const mockPlugin = { name: 'test-loader' };
|
|
19
|
-
registry.register('loader', 'test', mockPlugin);
|
|
20
|
-
const result = registry.get('loader', 'test');
|
|
21
|
-
expect(result).toBe(mockPlugin);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('overwrites existing plugin under the same name', () => {
|
|
25
|
-
const firstPlugin = { name: 'first' };
|
|
26
|
-
const secondPlugin = { name: 'second' };
|
|
27
|
-
registry.register('embedder', 'dup', firstPlugin);
|
|
28
|
-
registry.register('embedder', 'dup', secondPlugin);
|
|
29
|
-
const result = registry.get('embedder', 'dup');
|
|
30
|
-
expect(result).toBe(secondPlugin);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('throws error for unknown plugin type on registration', () => {
|
|
34
|
-
expect(() => registry.register('unknown-type', 'x', {})).toThrow(/Unknown plugin type/);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('throws error when retrieving a nonexistent plugin', () => {
|
|
38
|
-
expect(() => registry.get('retriever', 'missing')).toThrow(/Plugin not found/);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('lists all registered plugin names for a type', () => {
|
|
42
|
-
registry.register('llm', 'gpt-4', {});
|
|
43
|
-
registry.register('llm', 'gpt-3.5', {});
|
|
44
|
-
const list = registry.list('llm');
|
|
45
|
-
expect(list).toContain('gpt-4');
|
|
46
|
-
expect(list).toContain('gpt-3.5');
|
|
47
|
-
expect(list.length).toBe(2);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('throws error when listing plugins for invalid type', () => {
|
|
51
|
-
expect(() => registry.list('invalid')).toThrow(/Unknown plugin type/);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Version: 0.1.0
|
|
3
|
+
* Path: /__tests__/unit/core/plugin-registry.test.js
|
|
4
|
+
* Description: Unit tests for the PluginRegistry class
|
|
5
|
+
* Author: Ali Kahwaji
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { PluginRegistry } from '../../../src/core/plugin-registry.js';
|
|
9
|
+
|
|
10
|
+
describe('PluginRegistry', () => {
|
|
11
|
+
let registry;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
registry = new PluginRegistry();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('registers and retrieves a plugin successfully', () => {
|
|
18
|
+
const mockPlugin = { name: 'test-loader' };
|
|
19
|
+
registry.register('loader', 'test', mockPlugin);
|
|
20
|
+
const result = registry.get('loader', 'test');
|
|
21
|
+
expect(result).toBe(mockPlugin);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('overwrites existing plugin under the same name', () => {
|
|
25
|
+
const firstPlugin = { name: 'first' };
|
|
26
|
+
const secondPlugin = { name: 'second' };
|
|
27
|
+
registry.register('embedder', 'dup', firstPlugin);
|
|
28
|
+
registry.register('embedder', 'dup', secondPlugin);
|
|
29
|
+
const result = registry.get('embedder', 'dup');
|
|
30
|
+
expect(result).toBe(secondPlugin);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('throws error for unknown plugin type on registration', () => {
|
|
34
|
+
expect(() => registry.register('unknown-type', 'x', {})).toThrow(/Unknown plugin type/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('throws error when retrieving a nonexistent plugin', () => {
|
|
38
|
+
expect(() => registry.get('retriever', 'missing')).toThrow(/Plugin not found/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('lists all registered plugin names for a type', () => {
|
|
42
|
+
registry.register('llm', 'gpt-4', {});
|
|
43
|
+
registry.register('llm', 'gpt-3.5', {});
|
|
44
|
+
const list = registry.list('llm');
|
|
45
|
+
expect(list).toContain('gpt-4');
|
|
46
|
+
expect(list).toContain('gpt-3.5');
|
|
47
|
+
expect(list.length).toBe(2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('throws error when listing plugins for invalid type', () => {
|
|
51
|
+
expect(() => registry.list('invalid')).toThrow(/Unknown plugin type/);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Version: 0.1.0
|
|
3
|
-
* Path: /__tests__/unit/reranker/llm-reranker.test.js
|
|
4
|
-
* Description: Unit tests for LLM-based context reranker
|
|
5
|
-
* Author: Ali Kahwaji
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { LLMReranker } from '../../../src/reranker/llm-reranker.js';
|
|
9
|
-
|
|
10
|
-
describe('LLMReranker', () => {
|
|
11
|
-
const mockDocs = [
|
|
12
|
-
{ text: 'context about math' },
|
|
13
|
-
{ text: 'context about vectors' },
|
|
14
|
-
{ text: 'context about nothing' }
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
test('returns reranked documents based on mock LLM JSON output', async () => {
|
|
18
|
-
const mockLLM = {
|
|
19
|
-
async generate() {
|
|
20
|
-
return '[1, 0, 2]';
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const reranker = new LLMReranker({ llm: mockLLM });
|
|
24
|
-
const result = await reranker.rerank('What are vectors?', mockDocs);
|
|
25
|
-
expect(result.map(d => d.text)).toEqual([
|
|
26
|
-
'context about vectors',
|
|
27
|
-
'context about math',
|
|
28
|
-
'context about nothing'
|
|
29
|
-
]);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('gracefully falls back if LLM returns invalid JSON', async () => {
|
|
33
|
-
const mockLLM = {
|
|
34
|
-
async generate() {
|
|
35
|
-
return 'this is not JSON';
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const reranker = new LLMReranker({ llm: mockLLM });
|
|
39
|
-
const result = await reranker.rerank('Explain.', mockDocs);
|
|
40
|
-
expect(result.length).toBe(0);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Version: 0.1.0
|
|
3
|
+
* Path: /__tests__/unit/reranker/llm-reranker.test.js
|
|
4
|
+
* Description: Unit tests for LLM-based context reranker
|
|
5
|
+
* Author: Ali Kahwaji
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { LLMReranker } from '../../../src/reranker/llm-reranker.js';
|
|
9
|
+
|
|
10
|
+
describe('LLMReranker', () => {
|
|
11
|
+
const mockDocs = [
|
|
12
|
+
{ text: 'context about math' },
|
|
13
|
+
{ text: 'context about vectors' },
|
|
14
|
+
{ text: 'context about nothing' }
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
test('returns reranked documents based on mock LLM JSON output', async () => {
|
|
18
|
+
const mockLLM = {
|
|
19
|
+
async generate() {
|
|
20
|
+
return '[1, 0, 2]';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const reranker = new LLMReranker({ llm: mockLLM });
|
|
24
|
+
const result = await reranker.rerank('What are vectors?', mockDocs);
|
|
25
|
+
expect(result.map(d => d.text)).toEqual([
|
|
26
|
+
'context about vectors',
|
|
27
|
+
'context about math',
|
|
28
|
+
'context about nothing'
|
|
29
|
+
]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('gracefully falls back if LLM returns invalid JSON', async () => {
|
|
33
|
+
const mockLLM = {
|
|
34
|
+
async generate() {
|
|
35
|
+
return 'this is not JSON';
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const reranker = new LLMReranker({ llm: mockLLM });
|
|
39
|
+
const result = await reranker.rerank('Explain.', mockDocs);
|
|
40
|
+
expect(result.length).toBe(0);
|
|
41
|
+
});
|
|
42
|
+
});
|