@retrivora-ai/rag-engine 0.4.5 → 1.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.
- package/README.md +32 -57
- package/dist/{ChromaDBProvider-GI7TB7GJ.mjs → ChromaDBProvider-APQVJ5F7.mjs} +2 -2
- package/dist/{DocumentChunker-3yElxTO3.d.mts → DocumentChunker-C-sCZPhi.d.mts} +6 -6
- package/dist/{DocumentChunker-3yElxTO3.d.ts → DocumentChunker-C-sCZPhi.d.ts} +6 -6
- package/dist/{MilvusProvider-WDVTFB7D.mjs → MilvusProvider-35US67MS.mjs} +2 -2
- package/dist/{MongoDBProvider-RE3Q5S5B.mjs → MongoDBProvider-COVYZDP6.mjs} +2 -2
- package/dist/{PineconeProvider-BE2JWSPD.mjs → PineconeProvider-AWFJQDZL.mjs} +2 -2
- package/dist/{PostgreSQLProvider-5HHTK4SU.mjs → PostgreSQLProvider-IEYRJ7XJ.mjs} +2 -2
- package/dist/{QdrantProvider-XVDVBNIG.mjs → QdrantProvider-M6TQYZRO.mjs} +2 -2
- package/dist/{RagConfig-BgRDL9Vy.d.mts → RagConfig-DRJO4hGU.d.mts} +12 -1
- package/dist/{RagConfig-BgRDL9Vy.d.ts → RagConfig-DRJO4hGU.d.ts} +12 -1
- package/dist/{RedisProvider-EK2R2PQH.mjs → RedisProvider-3G5PBLZ4.mjs} +2 -2
- package/dist/{SimpleGraphProvider-M6T7SE7D.mjs → SimpleGraphProvider-UK7DJW37.mjs} +1 -1
- package/dist/{UniversalVectorProvider-YIDRX6VT.mjs → UniversalVectorProvider-FYQ3B2PW.mjs} +3 -3
- package/dist/{WeaviateProvider-4CAPQ7UY.mjs → WeaviateProvider-ITHO36IL.mjs} +2 -2
- package/dist/{chunk-5KNBWQM6.mjs → chunk-4A47RCG2.mjs} +5 -1
- package/dist/{chunk-EDLTMSNY.mjs → chunk-67AJ6SMD.mjs} +1 -1
- package/dist/{chunk-PQKTC73Y.mjs → chunk-7SOSCZGS.mjs} +67 -6
- package/dist/{chunk-LJWWPTWE.mjs → chunk-FLOSGE6A.mjs} +76 -14
- package/dist/{chunk-H6RKMU7W.mjs → chunk-NXUCKY5L.mjs} +1 -1
- package/dist/{chunk-KTS3LLHY.mjs → chunk-OOQXNLXD.mjs} +5 -5
- package/dist/{chunk-PRC5CZIZ.mjs → chunk-P4HAQ7KB.mjs} +1184 -1359
- package/dist/chunk-QMIKLALV.mjs +57 -0
- package/dist/{chunk-3QWAK3RZ.mjs → chunk-TYHTZIDP.mjs} +6 -2
- package/dist/{chunk-GQT5LF4G.mjs → chunk-U6KHVZLF.mjs} +2 -2
- package/dist/{chunk-RK2UDJA2.mjs → chunk-WGSZNY3X.mjs} +1 -1
- package/dist/{chunk-XCNXPECE.mjs → chunk-ZNBKHNJ4.mjs} +55 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +1415 -1391
- package/dist/handlers/index.mjs +3 -3
- package/dist/index-CrGMwXfO.d.ts +112 -0
- package/dist/index-v669iV-k.d.mts +112 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/server.d.mts +104 -158
- package/dist/server.d.ts +104 -158
- package/dist/server.js +1414 -1390
- package/dist/server.mjs +12 -12
- package/package.json +5 -1
- package/src/config/RagConfig.ts +7 -0
- package/src/core/ConfigValidator.ts +66 -492
- package/src/core/LangChainAgent.ts +78 -0
- package/src/core/Pipeline.ts +210 -240
- package/src/core/ProviderHealthCheck.ts +35 -406
- package/src/core/ProviderInterfaces.ts +37 -0
- package/src/core/ProviderRegistry.ts +70 -55
- package/src/core/QueryProcessor.ts +173 -0
- package/src/llm/ILLMProvider.ts +10 -0
- package/src/llm/LLMFactory.ts +33 -13
- package/src/llm/providers/AnthropicProvider.ts +55 -15
- package/src/llm/providers/GeminiProvider.ts +51 -0
- package/src/llm/providers/OllamaProvider.ts +100 -15
- package/src/llm/providers/OpenAIProvider.ts +60 -11
- package/src/providers/vectordb/BaseVectorProvider.ts +11 -0
- package/src/providers/vectordb/MilvusProvider.ts +4 -0
- package/src/providers/vectordb/MongoDBProvider.ts +72 -8
- package/src/providers/vectordb/PineconeProvider.ts +60 -5
- package/src/providers/vectordb/PostgreSQLProvider.ts +84 -14
- package/src/providers/vectordb/QdrantProvider.ts +4 -0
- package/src/providers/vectordb/WeaviateProvider.ts +8 -4
- package/src/rag/DocumentChunker.ts +15 -19
- package/src/rag/LlamaIndexIngestor.ts +61 -0
- package/src/rag/Reranker.ts +20 -0
- package/src/server.ts +1 -1
- package/src/types/index.ts +9 -0
- package/dist/chunk-FWCSY2DS.mjs +0 -37
- package/dist/index-7qeLTPBL.d.mts +0 -114
- package/dist/index-DowY4_K0.d.ts +0 -114
package/README.md
CHANGED
|
@@ -10,44 +10,42 @@
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
## ✨ Features
|
|
13
|
+
## ✨ Features (v1.0.0)
|
|
14
14
|
|
|
15
15
|
| Category | Options |
|
|
16
16
|
|---|---|
|
|
17
|
-
| **Vector DBs** | Pinecone, pgVector (PostgreSQL), MongoDB Atlas, ChromaDB, Qdrant,
|
|
18
|
-
| **LLM Providers** | OpenAI, Anthropic Claude, Google Gemini, Ollama, LiteLLM,
|
|
17
|
+
| **Vector DBs** | Pinecone, pgVector (PostgreSQL), MongoDB Atlas, ChromaDB, Qdrant, Milvus, Weaviate, Redis |
|
|
18
|
+
| **LLM Providers** | OpenAI, Anthropic Claude, Google Gemini, Ollama, LiteLLM, Universal REST |
|
|
19
|
+
| **Integrations** | **LangChain** (Agentic orchestration), **LlamaIndex** (Semantic chunking) |
|
|
19
20
|
| **Document Ingestion** | Universal support for **PDF**, **DOCX**, **CSV**, **JSON**, **MD**, **TXT** |
|
|
20
|
-
| **
|
|
21
|
-
| **RAG** |
|
|
21
|
+
| **Architecture** | **Modular & Pluggable** registry-based system with static health checks & validators |
|
|
22
|
+
| **RAG Patterns** | Simple, Hybrid, Graph-based, and Agentic workflows |
|
|
22
23
|
|
|
23
24
|
---
|
|
24
25
|
|
|
25
26
|
## 🚀 How it Works
|
|
26
27
|
|
|
27
|
-
Retrivora AI acts as a universal bridge between your data and your users. It normalizes different AI providers and Vector databases into a single interface
|
|
28
|
+
Retrivora AI acts as a universal bridge between your data and your users. It normalizes different AI providers and Vector databases into a single interface using a **registry-based architecture**.
|
|
28
29
|
|
|
29
|
-
1. **Ingest**: Upload or send documents to the `/api/upload` endpoint. They are
|
|
30
|
-
2. **Retrieve**:
|
|
31
|
-
3. **Generate**:
|
|
30
|
+
1. **Ingest**: Upload or send documents to the `/api/upload` endpoint. They are parsed and chunked using **LlamaIndex** strategies if configured.
|
|
31
|
+
2. **Retrieve**: Queries are processed via the [QueryProcessor](file:///src/core/QueryProcessor.ts) to extract semantic hints and filter criteria.
|
|
32
|
+
3. **Generate**: Context is retrieved and processed through a [Pipeline](file:///src/core/Pipeline.ts) (or [LangChainAgent](file:///src/core/LangChainAgent.ts)) to produce grounded, streaming responses.
|
|
32
33
|
|
|
33
|
-
### 📦
|
|
34
|
-
|
|
35
|
-
To integrate Retrivora AI into your existing Next.js project, simply run:
|
|
34
|
+
### 📦 Installation
|
|
36
35
|
|
|
37
36
|
```bash
|
|
38
37
|
npm install @retrivora-ai/rag-engine
|
|
39
38
|
```
|
|
40
39
|
|
|
41
|
-
|
|
40
|
+
---
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```
|
|
42
|
+
## 🛠️ Pluggable Architecture
|
|
43
|
+
|
|
44
|
+
Starting with v1.0.0, the engine uses a modular registry for all providers. Every provider now exposes:
|
|
45
|
+
- **Static Validators**: `getValidator()` for deep configuration schema checks.
|
|
46
|
+
- **Static Health Checkers**: `getHealthChecker()` for real-time connectivity and capability validation.
|
|
47
|
+
|
|
48
|
+
This decoupling allows you to add custom providers without modifying the core engine logic.
|
|
51
49
|
|
|
52
50
|
---
|
|
53
51
|
|
|
@@ -55,8 +53,6 @@ npm run dev
|
|
|
55
53
|
|
|
56
54
|
### 1. Embed the ChatWidget
|
|
57
55
|
|
|
58
|
-
Wrap your application in the `ConfigProvider` and add the `ChatWidget`.
|
|
59
|
-
|
|
60
56
|
```tsx
|
|
61
57
|
import { ConfigProvider, ChatWidget } from '@retrivora-ai/rag-engine';
|
|
62
58
|
|
|
@@ -82,25 +78,28 @@ export default function Layout({ children }) {
|
|
|
82
78
|
|
|
83
79
|
### 2. Mount the API routes
|
|
84
80
|
|
|
85
|
-
Create standard Next.js route handlers and plug in the library's factories.
|
|
86
|
-
|
|
87
81
|
```ts
|
|
88
82
|
// src/app/api/chat/route.ts
|
|
89
83
|
import { createChatHandler, getRagConfig } from '@retrivora-ai/rag-engine/server';
|
|
90
84
|
export const POST = createChatHandler(getRagConfig());
|
|
91
85
|
|
|
92
|
-
// src/app/api/upload/route.ts
|
|
86
|
+
// src/app/api/upload/route.ts
|
|
93
87
|
import { createUploadHandler, getRagConfig } from '@retrivora-ai/rag-engine/server';
|
|
94
88
|
export const POST = createUploadHandler(getRagConfig());
|
|
95
89
|
```
|
|
96
90
|
|
|
97
|
-
### 3. Use
|
|
91
|
+
### 3. Use Pipeline programmatically
|
|
98
92
|
|
|
99
93
|
```ts
|
|
100
|
-
import {
|
|
94
|
+
import { Pipeline, getRagConfig } from '@retrivora-ai/rag-engine/server';
|
|
101
95
|
|
|
102
|
-
const
|
|
96
|
+
const config = getRagConfig();
|
|
97
|
+
const pipeline = new Pipeline(config);
|
|
98
|
+
|
|
99
|
+
// Ingest documents
|
|
103
100
|
await pipeline.ingest([{ docId: 'readme', content: 'Your document text here' }]);
|
|
101
|
+
|
|
102
|
+
// Ask questions
|
|
104
103
|
const { reply, sources } = await pipeline.ask('What is the refund policy?');
|
|
105
104
|
```
|
|
106
105
|
|
|
@@ -113,34 +112,10 @@ The library is entirely dynamic. You can switch between providers simply by upda
|
|
|
113
112
|
| Variable | Description |
|
|
114
113
|
|---|---|
|
|
115
114
|
| `RAG_PROJECT_ID` | Project namespace for data isolation |
|
|
116
|
-
| `VECTOR_DB_PROVIDER` | `pinecone`, `pgvector`, `mongodb`,
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `EMBEDDING_PROVIDER` | `openai`, `ollama`, or `rest` |
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## Architecture
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
User Query
|
|
128
|
-
|
|
|
129
|
-
v
|
|
130
|
-
[embed query] <-- EmbeddingProvider (OpenAI / Ollama / Custom)
|
|
131
|
-
|
|
|
132
|
-
v
|
|
133
|
-
[vector search] <-- IVectorDB (Pinecone / pgVector / MongoDB / Chroma / REST)
|
|
134
|
-
|
|
|
135
|
-
v
|
|
136
|
-
[build context]
|
|
137
|
-
|
|
|
138
|
-
v
|
|
139
|
-
[LLM chat] <-- ILLMProvider (OpenAI / Anthropic / Gemini / LiteLLM)
|
|
140
|
-
|
|
|
141
|
-
v
|
|
142
|
-
ChatResponse { reply, sources[] }
|
|
143
|
-
```
|
|
115
|
+
| `VECTOR_DB_PROVIDER` | `pinecone`, `pgvector`, `mongodb`, `milvus`, `qdrant`, `weaviate` |
|
|
116
|
+
| `LLM_PROVIDER` | `openai`, `anthropic`, `gemini`, `ollama` |
|
|
117
|
+
| `EMBEDDING_PROVIDER` | `openai`, `ollama`, `google-gemini` |
|
|
118
|
+
| `RAG_ARCHITECTURE` | `simple`, `hybrid`, `graph`, `agentic` |
|
|
144
119
|
|
|
145
120
|
---
|
|
146
121
|
|
|
@@ -30,6 +30,11 @@ interface ILLMProvider {
|
|
|
30
30
|
* @returns – the assistant's reply text
|
|
31
31
|
*/
|
|
32
32
|
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Send a streaming chat completion request.
|
|
35
|
+
* @returns – an async iterable of text chunks
|
|
36
|
+
*/
|
|
37
|
+
chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
|
|
33
38
|
/**
|
|
34
39
|
* Generate an embedding vector for the given text.
|
|
35
40
|
* @param text – text to embed
|
|
@@ -83,15 +88,10 @@ declare class DocumentChunker {
|
|
|
83
88
|
constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
|
|
84
89
|
/**
|
|
85
90
|
* Split a single text string into overlapping chunks using a recursive strategy.
|
|
91
|
+
* Preserves structural boundaries (Markdown headers) where possible.
|
|
86
92
|
*/
|
|
87
93
|
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
88
|
-
/**
|
|
89
|
-
* Recursively split text based on separators.
|
|
90
|
-
*/
|
|
91
94
|
private recursiveSplit;
|
|
92
|
-
/**
|
|
93
|
-
* Chunk multiple documents at once.
|
|
94
|
-
*/
|
|
95
95
|
chunkMany(documents: Array<{
|
|
96
96
|
content: string;
|
|
97
97
|
docId?: string | number;
|
|
@@ -30,6 +30,11 @@ interface ILLMProvider {
|
|
|
30
30
|
* @returns – the assistant's reply text
|
|
31
31
|
*/
|
|
32
32
|
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Send a streaming chat completion request.
|
|
35
|
+
* @returns – an async iterable of text chunks
|
|
36
|
+
*/
|
|
37
|
+
chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
|
|
33
38
|
/**
|
|
34
39
|
* Generate an embedding vector for the given text.
|
|
35
40
|
* @param text – text to embed
|
|
@@ -83,15 +88,10 @@ declare class DocumentChunker {
|
|
|
83
88
|
constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
|
|
84
89
|
/**
|
|
85
90
|
* Split a single text string into overlapping chunks using a recursive strategy.
|
|
91
|
+
* Preserves structural boundaries (Markdown headers) where possible.
|
|
86
92
|
*/
|
|
87
93
|
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
88
|
-
/**
|
|
89
|
-
* Recursively split text based on separators.
|
|
90
|
-
*/
|
|
91
94
|
private recursiveSplit;
|
|
92
|
-
/**
|
|
93
|
-
* Chunk multiple documents at once.
|
|
94
|
-
*/
|
|
95
95
|
chunkMany(documents: Array<{
|
|
96
96
|
content: string;
|
|
97
97
|
docId?: string | number;
|
|
@@ -35,6 +35,10 @@ interface GraphSearchResult {
|
|
|
35
35
|
nodes: GraphNode[];
|
|
36
36
|
edges: Edge[];
|
|
37
37
|
}
|
|
38
|
+
interface RetrievalResult {
|
|
39
|
+
sources: VectorMatch[];
|
|
40
|
+
graphData?: GraphSearchResult;
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* constants.ts — Centralized definitions of acceptable configuration values.
|
|
@@ -73,6 +77,9 @@ interface VectorDBConfig {
|
|
|
73
77
|
* - scorePath?: string (e.g. 'similarity')
|
|
74
78
|
* - contentPath?: string (e.g. 'text')
|
|
75
79
|
*
|
|
80
|
+
* For 'mongodb', the following options are also supported:
|
|
81
|
+
* - numCandidates?: number // controls search recall depth
|
|
82
|
+
*
|
|
76
83
|
* For multi-table PostgreSQL search, the following options are also supported:
|
|
77
84
|
* - tables?: string[] | string
|
|
78
85
|
* - searchFields?: string[] | string // optional override for which columns receive exact-match boosts
|
|
@@ -170,6 +177,10 @@ interface RAGConfig {
|
|
|
170
177
|
chunkOverlap?: number;
|
|
171
178
|
/** Characters used to split text, in order of priority */
|
|
172
179
|
separators?: string[];
|
|
180
|
+
/** Overall RAG architecture pattern */
|
|
181
|
+
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic';
|
|
182
|
+
/** Chunking strategy to use during ingestion */
|
|
183
|
+
chunkingStrategy?: 'recursive' | 'markdown' | 'semantic' | 'llamaindex';
|
|
173
184
|
/** Whether to use query transformation (e.g. HyDE) */
|
|
174
185
|
useQueryTransformation?: boolean;
|
|
175
186
|
/** Whether to use graph-based retrieval */
|
|
@@ -197,4 +208,4 @@ interface RagConfig {
|
|
|
197
208
|
graphDb?: GraphDBConfig;
|
|
198
209
|
}
|
|
199
210
|
|
|
200
|
-
export type { ChatResponse as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, EmbeddingProvider as a, LLMProvider as b, RagConfig as c, UpsertDocument as d, VectorDBConfig as e, VectorDBProvider as f,
|
|
211
|
+
export type { ChatResponse as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, EmbeddingProvider as a, LLMProvider as b, RagConfig as c, UpsertDocument as d, VectorDBConfig as e, VectorDBProvider as f, RetrievalResult as g, GraphNode as h, Edge as i, GraphSearchResult as j };
|
|
@@ -35,6 +35,10 @@ interface GraphSearchResult {
|
|
|
35
35
|
nodes: GraphNode[];
|
|
36
36
|
edges: Edge[];
|
|
37
37
|
}
|
|
38
|
+
interface RetrievalResult {
|
|
39
|
+
sources: VectorMatch[];
|
|
40
|
+
graphData?: GraphSearchResult;
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* constants.ts — Centralized definitions of acceptable configuration values.
|
|
@@ -73,6 +77,9 @@ interface VectorDBConfig {
|
|
|
73
77
|
* - scorePath?: string (e.g. 'similarity')
|
|
74
78
|
* - contentPath?: string (e.g. 'text')
|
|
75
79
|
*
|
|
80
|
+
* For 'mongodb', the following options are also supported:
|
|
81
|
+
* - numCandidates?: number // controls search recall depth
|
|
82
|
+
*
|
|
76
83
|
* For multi-table PostgreSQL search, the following options are also supported:
|
|
77
84
|
* - tables?: string[] | string
|
|
78
85
|
* - searchFields?: string[] | string // optional override for which columns receive exact-match boosts
|
|
@@ -170,6 +177,10 @@ interface RAGConfig {
|
|
|
170
177
|
chunkOverlap?: number;
|
|
171
178
|
/** Characters used to split text, in order of priority */
|
|
172
179
|
separators?: string[];
|
|
180
|
+
/** Overall RAG architecture pattern */
|
|
181
|
+
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic';
|
|
182
|
+
/** Chunking strategy to use during ingestion */
|
|
183
|
+
chunkingStrategy?: 'recursive' | 'markdown' | 'semantic' | 'llamaindex';
|
|
173
184
|
/** Whether to use query transformation (e.g. HyDE) */
|
|
174
185
|
useQueryTransformation?: boolean;
|
|
175
186
|
/** Whether to use graph-based retrieval */
|
|
@@ -197,4 +208,4 @@ interface RagConfig {
|
|
|
197
208
|
graphDb?: GraphDBConfig;
|
|
198
209
|
}
|
|
199
210
|
|
|
200
|
-
export type { ChatResponse as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, EmbeddingProvider as a, LLMProvider as b, RagConfig as c, UpsertDocument as d, VectorDBConfig as e, VectorDBProvider as f,
|
|
211
|
+
export type { ChatResponse as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, EmbeddingProvider as a, LLMProvider as b, RagConfig as c, UpsertDocument as d, VectorDBConfig as e, VectorDBProvider as f, RetrievalResult as g, GraphNode as h, Edge as i, GraphSearchResult as j };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UniversalVectorProvider
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-U6KHVZLF.mjs";
|
|
4
|
+
import "./chunk-67AJ6SMD.mjs";
|
|
5
5
|
import "./chunk-IMP6FUCY.mjs";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-QMIKLALV.mjs";
|
|
7
7
|
export {
|
|
8
8
|
UniversalVectorProvider
|
|
9
9
|
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-IMP6FUCY.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__spreadValues
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QMIKLALV.mjs";
|
|
7
7
|
|
|
8
8
|
// src/providers/vectordb/QdrantProvider.ts
|
|
9
9
|
import axios from "axios";
|
|
@@ -99,6 +99,10 @@ var QdrantProvider = class extends BaseVectorProvider {
|
|
|
99
99
|
vector,
|
|
100
100
|
limit: topK,
|
|
101
101
|
with_payload: true,
|
|
102
|
+
params: {
|
|
103
|
+
hnsw_ef: this.config.options.efSearch || Math.max(topK * 20, 128),
|
|
104
|
+
exact: false
|
|
105
|
+
},
|
|
102
106
|
filter: namespace ? {
|
|
103
107
|
must: [{ key: "namespace", match: { value: namespace } }]
|
|
104
108
|
} : void 0
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-IMP6FUCY.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__spreadValues
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-QMIKLALV.mjs";
|
|
7
7
|
|
|
8
8
|
// src/providers/vectordb/MongoDBProvider.ts
|
|
9
9
|
import { MongoClient } from "mongodb";
|
|
@@ -21,6 +21,71 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
21
21
|
this.contentKey = opts.contentKey || "content";
|
|
22
22
|
this.metadataKey = opts.metadataKey || "metadata";
|
|
23
23
|
}
|
|
24
|
+
static getValidator() {
|
|
25
|
+
return {
|
|
26
|
+
validate(config) {
|
|
27
|
+
const errors = [];
|
|
28
|
+
const opts = config.options || {};
|
|
29
|
+
if (!opts.uri) {
|
|
30
|
+
errors.push({
|
|
31
|
+
field: "vectorDb.options.uri",
|
|
32
|
+
message: "MongoDB connection URI is required",
|
|
33
|
+
suggestion: "Set MONGODB_URI environment variable",
|
|
34
|
+
severity: "error"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (!opts.database) {
|
|
38
|
+
errors.push({
|
|
39
|
+
field: "vectorDb.options.database",
|
|
40
|
+
message: "MongoDB database name is required",
|
|
41
|
+
severity: "error"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!opts.collection) {
|
|
45
|
+
errors.push({
|
|
46
|
+
field: "vectorDb.options.collection",
|
|
47
|
+
message: "MongoDB collection name is required",
|
|
48
|
+
severity: "error"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return errors;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
static getHealthChecker() {
|
|
56
|
+
return {
|
|
57
|
+
async check(config) {
|
|
58
|
+
const opts = config.options || {};
|
|
59
|
+
const timestamp = Date.now();
|
|
60
|
+
try {
|
|
61
|
+
const { MongoClient: MongoClient2 } = await import("mongodb");
|
|
62
|
+
const client = new MongoClient2(opts.uri);
|
|
63
|
+
await client.connect();
|
|
64
|
+
const db = client.db(opts.database);
|
|
65
|
+
await db.command({ ping: 1 });
|
|
66
|
+
const collections = await db.listCollections({ name: opts.collection }).toArray();
|
|
67
|
+
await client.close();
|
|
68
|
+
return {
|
|
69
|
+
healthy: true,
|
|
70
|
+
provider: "mongodb",
|
|
71
|
+
capabilities: {
|
|
72
|
+
database: opts.database,
|
|
73
|
+
collection: opts.collection,
|
|
74
|
+
exists: collections.length > 0
|
|
75
|
+
},
|
|
76
|
+
timestamp
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
healthy: false,
|
|
81
|
+
provider: "mongodb",
|
|
82
|
+
error: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
83
|
+
timestamp
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
24
89
|
async initialize() {
|
|
25
90
|
await this.client.connect();
|
|
26
91
|
this.db = this.client.db(this.dbName);
|
|
@@ -59,7 +124,7 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
59
124
|
index: this.config.indexName || "vector_index",
|
|
60
125
|
path: this.embeddingKey,
|
|
61
126
|
queryVector: vector,
|
|
62
|
-
numCandidates: Math.max(topK *
|
|
127
|
+
numCandidates: this.config.options.numCandidates || Math.max(topK * 20, 200),
|
|
63
128
|
limit: topK
|
|
64
129
|
}, Object.keys(publicFilter).length > 0 || namespace ? { filter: __spreadValues(__spreadValues({}, publicFilter), namespace ? { namespace } : {}) } : {})
|
|
65
130
|
},
|
|
@@ -87,10 +152,6 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
87
152
|
async deleteNamespace(namespace) {
|
|
88
153
|
await this.collection.deleteMany({ namespace });
|
|
89
154
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Sanitise and flatten filter for MongoDB.
|
|
92
|
-
* Strips internal engine fields and keywords.
|
|
93
|
-
*/
|
|
94
155
|
sanitizeFilter(filter) {
|
|
95
156
|
const sanitized = super.sanitizeFilter(filter);
|
|
96
157
|
const mongoFilter = {};
|
|
@@ -14,6 +14,61 @@ var PostgreSQLProvider = class extends BaseVectorProvider {
|
|
|
14
14
|
this.connectionString = opts.connectionString;
|
|
15
15
|
this.dimensions = (_a = opts.dimensions) != null ? _a : 1536;
|
|
16
16
|
}
|
|
17
|
+
static getValidator() {
|
|
18
|
+
return {
|
|
19
|
+
validate(config) {
|
|
20
|
+
const errors = [];
|
|
21
|
+
const opts = config.options || {};
|
|
22
|
+
if (!opts.connectionString) {
|
|
23
|
+
errors.push({
|
|
24
|
+
field: "vectorDb.options.connectionString",
|
|
25
|
+
message: "PostgreSQL connection string is required",
|
|
26
|
+
suggestion: "Set PGVECTOR_CONNECTION_STRING environment variable",
|
|
27
|
+
severity: "error"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (opts.tables && typeof opts.tables !== "string" && !Array.isArray(opts.tables)) {
|
|
31
|
+
errors.push({
|
|
32
|
+
field: "vectorDb.options.tables",
|
|
33
|
+
message: "PostgreSQL tables must be a string or a string array",
|
|
34
|
+
severity: "error"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return errors;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
static getHealthChecker() {
|
|
42
|
+
return {
|
|
43
|
+
async check(config) {
|
|
44
|
+
const opts = config.options || {};
|
|
45
|
+
const timestamp = Date.now();
|
|
46
|
+
try {
|
|
47
|
+
const { Client } = await import("pg");
|
|
48
|
+
const client = new Client({ connectionString: opts.connectionString });
|
|
49
|
+
await client.connect();
|
|
50
|
+
const result = await client.query(`
|
|
51
|
+
SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'vector');
|
|
52
|
+
`);
|
|
53
|
+
const hasVector = result.rows[0].exists;
|
|
54
|
+
await client.end();
|
|
55
|
+
return {
|
|
56
|
+
healthy: true,
|
|
57
|
+
provider: "postgresql",
|
|
58
|
+
capabilities: { pgvectorInstalled: hasVector },
|
|
59
|
+
timestamp
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
healthy: false,
|
|
64
|
+
provider: "postgresql",
|
|
65
|
+
error: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
66
|
+
timestamp
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
17
72
|
async initialize() {
|
|
18
73
|
this.pool = new Pool({ connectionString: this.connectionString });
|
|
19
74
|
const client = await this.pool.connect();
|
|
@@ -99,20 +154,27 @@ var PostgreSQLProvider = class extends BaseVectorProvider {
|
|
|
99
154
|
}).join(" AND ");
|
|
100
155
|
whereClause = whereClause ? `${whereClause} AND ${filterConditions}` : `WHERE ${filterConditions}`;
|
|
101
156
|
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
157
|
+
const client = await this.pool.connect();
|
|
158
|
+
try {
|
|
159
|
+
const efSearch = this.config.options.efSearch || Math.max(topK * 10, 40);
|
|
160
|
+
await client.query(`SET LOCAL hnsw.ef_search = ${efSearch}`);
|
|
161
|
+
const result = await client.query(
|
|
162
|
+
`SELECT id, content, metadata, 1 - (embedding <=> $1::vector) AS score
|
|
163
|
+
FROM ${this.tableName}
|
|
164
|
+
${whereClause}
|
|
165
|
+
ORDER BY embedding <=> $1::vector
|
|
166
|
+
LIMIT $2`,
|
|
167
|
+
params
|
|
168
|
+
);
|
|
169
|
+
return result.rows.map((row) => ({
|
|
170
|
+
id: String(row["id"]),
|
|
171
|
+
score: parseFloat(String(row["score"])),
|
|
172
|
+
content: String(row["content"]),
|
|
173
|
+
metadata: row["metadata"]
|
|
174
|
+
}));
|
|
175
|
+
} finally {
|
|
176
|
+
client.release();
|
|
177
|
+
}
|
|
116
178
|
}
|
|
117
179
|
async delete(id, namespace) {
|
|
118
180
|
const where = namespace ? "WHERE id = $1 AND namespace = $2" : "WHERE id = $1";
|