@cogitator-ai/rag 0.3.4 → 0.3.5
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/README.md +12 -6
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ pnpm add papaparse # CSV loading
|
|
|
13
13
|
pnpm add pdf-parse # PDF loading
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
`@cogitator-ai/memory` (optional peer) provides the embedding services, vector stores (`InMemoryEmbeddingAdapter`, `PostgresAdapter`, `QdrantAdapter`) and `HybridSearch` used below; any `EmbeddingService` / `EmbeddingAdapter` implementation works. Website docs: [RAG](https://cogitator.app/docs/rag), [Loaders](https://cogitator.app/docs/rag/loaders), [Chunking](https://cogitator.app/docs/rag/chunking), [Retrieval](https://cogitator.app/docs/rag/retrieval), [Reranking](https://cogitator.app/docs/rag/reranking).
|
|
17
|
+
|
|
16
18
|
## Features
|
|
17
19
|
|
|
18
20
|
- **7 Document Loaders** — Text, Markdown, JSON, CSV, HTML, PDF, Web pages
|
|
@@ -46,10 +48,10 @@ const pipeline = new RAGPipelineBuilder()
|
|
|
46
48
|
.build();
|
|
47
49
|
|
|
48
50
|
// ingest documents from a file or directory
|
|
49
|
-
await pipeline.ingest('./docs');
|
|
51
|
+
const { documents, chunks } = await pipeline.ingest('./docs');
|
|
50
52
|
|
|
51
|
-
// query the knowledge base
|
|
52
|
-
const results = await pipeline.query('How does authentication work?');
|
|
53
|
+
// query the knowledge base (options override the configured retrieval for this call)
|
|
54
|
+
const results = await pipeline.query('How does authentication work?', { topK: 3 });
|
|
53
55
|
|
|
54
56
|
for (const r of results) {
|
|
55
57
|
console.log(`[${r.score.toFixed(3)}] ${r.source}: ${r.content.slice(0, 100)}...`);
|
|
@@ -90,13 +92,17 @@ const intranet = new WebLoader({
|
|
|
90
92
|
Responses are decompressed (gzip, deflate, br), decoded using the declared charset, and limited to `maxResponseBytes` (50MB by default). Non-text content types are rejected.
|
|
91
93
|
|
|
92
94
|
```typescript
|
|
93
|
-
import { MarkdownLoader, WebLoader, CSVLoader } from '@cogitator-ai/rag';
|
|
95
|
+
import { MarkdownLoader, WebLoader, CSVLoader, PDFLoader, JSONLoader } from '@cogitator-ai/rag';
|
|
94
96
|
|
|
95
97
|
const md = new MarkdownLoader({ stripFrontmatter: true });
|
|
96
98
|
const web = new WebLoader({ selector: 'article' });
|
|
97
99
|
const csv = new CSVLoader({ contentColumn: 'body', metadataColumns: ['title'] });
|
|
100
|
+
const pdf = new PDFLoader({ splitPages: true }); // one document per page
|
|
101
|
+
const json = new JSONLoader({ contentField: 'text' });
|
|
98
102
|
```
|
|
99
103
|
|
|
104
|
+
A pipeline has one loader; use `withChunker()` / `withRetriever()` on the builder to replace the chunker or retriever the config would create.
|
|
105
|
+
|
|
100
106
|
---
|
|
101
107
|
|
|
102
108
|
## Chunking Strategies
|
|
@@ -347,7 +353,7 @@ const agent = new Agent({
|
|
|
347
353
|
});
|
|
348
354
|
```
|
|
349
355
|
|
|
350
|
-
`RAGTool` objects carry Zod parameter schemas and can be passed to `tool()` directly. `rag_search` falls back to the pipeline's configured `topK`/`threshold` when the model omits `limit`/`threshold`.
|
|
356
|
+
`RAGTool` objects carry Zod parameter schemas and can be passed to `tool()` directly; `createSearchTool(pipeline)` and `createIngestTool(pipeline, options)` build them one at a time. `rag_search` falls back to the pipeline's configured `topK`/`threshold` when the model omits `limit`/`threshold`.
|
|
351
357
|
|
|
352
358
|
**Security:** `rag_ingest` reads whatever source the model passes. When the tool is exposed to an LLM, restrict it with `allowedRoots` (paths are canonicalized, so `..` traversal and symlink escapes are rejected) and `allowUrls: false` if web ingestion is not needed. URL ingestion goes through the SSRF-protected `WebLoader` when the pipeline uses one.
|
|
353
359
|
|
|
@@ -366,7 +372,7 @@ console.log(stats.queriesProcessed);
|
|
|
366
372
|
|
|
367
373
|
## Examples
|
|
368
374
|
|
|
369
|
-
See [`examples/rag/`](
|
|
375
|
+
See [`examples/rag/`](https://github.com/cogitator-ai/Cogitator-AI/tree/main/examples/rag) for runnable examples:
|
|
370
376
|
|
|
371
377
|
- **01-basic-retrieval.ts** — Ingest documents and run semantic queries
|
|
372
378
|
- **02-chunking-strategies.ts** — Compare fixed, recursive, and semantic chunking
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/rag",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Retrieval Augmented Generation for Cogitator AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"node": ">=22.12.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@cogitator-ai/types": "0.
|
|
21
|
+
"@cogitator-ai/types": "0.29.0",
|
|
22
22
|
"nanoid": "^6.0.1",
|
|
23
23
|
"zod": "^4.6.5"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@cogitator-ai/memory": ">=0.
|
|
26
|
+
"@cogitator-ai/memory": ">=0.11.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@cogitator-ai/memory": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"pdf-parse": "^2.4.5"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@cogitator-ai/memory": "0.
|
|
39
|
+
"@cogitator-ai/memory": "0.11.0",
|
|
40
40
|
"@types/papaparse": "^5.3.15",
|
|
41
41
|
"typescript": "^6.0.3",
|
|
42
42
|
"vitest": "^5.0.3"
|