@retrivora-ai/rag-engine 0.1.3 → 0.1.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/dist/ChromaDBProvider-QNI7UCX4.mjs +8 -0
- package/dist/DocumentChunker-cfaMidtA.d.mts +93 -0
- package/dist/DocumentChunker-cfaMidtA.d.ts +93 -0
- package/dist/LLMFactory-JFOY2V4X.mjs +8 -0
- package/dist/MilvusProvider-OO6QGZDZ.mjs +8 -0
- package/dist/MongoDBProvider-WWVJG3WT.mjs +8 -0
- package/dist/PineconeProvider-NJ675H7U.mjs +8 -0
- package/dist/PostgreSQLProvider-ISNMD3BE.mjs +8 -0
- package/dist/QdrantProvider-LJWOIGES.mjs +8 -0
- package/dist/RagConfig-DG_0f8ka.d.mts +145 -0
- package/dist/RagConfig-DG_0f8ka.d.ts +145 -0
- package/dist/RedisProvider-ASONNYBI.mjs +8 -0
- package/dist/WeaviateProvider-PSDCUGC7.mjs +8 -0
- package/dist/chunk-6FODXNUF.mjs +91 -0
- package/dist/chunk-7NXI6ZWX.mjs +89 -0
- package/dist/chunk-AALIF3AL.mjs +91 -0
- package/dist/chunk-BP4U4TT5.mjs +548 -0
- package/dist/chunk-HUGLYKD6.mjs +84 -0
- package/dist/chunk-I4E63NIC.mjs +24 -0
- package/dist/chunk-JI6VD5TJ.mjs +387 -0
- package/dist/chunk-QEYVWVT5.mjs +102 -0
- package/dist/chunk-S5DRHETN.mjs +110 -0
- package/dist/{chunk-ZPXLQR5Q.mjs → chunk-UKDXCXW7.mjs} +5 -23
- package/dist/chunk-V75V7BT2.mjs +117 -0
- package/dist/chunk-VOIWNO5O.mjs +11 -0
- package/dist/chunk-VPNRDXIA.mjs +74 -0
- package/dist/handlers/index.d.mts +9 -33
- package/dist/handlers/index.d.ts +9 -33
- package/dist/handlers/index.js +1477 -962
- package/dist/handlers/index.mjs +4 -2
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/index.mjs +4 -2
- package/dist/server.d.mts +220 -53
- package/dist/server.d.ts +220 -53
- package/dist/server.js +1531 -1099
- package/dist/server.mjs +55 -131
- package/package.json +19 -2
- package/src/app/page.tsx +1 -1
- package/src/components/MessageBubble.tsx +1 -1
- package/src/components/SourceCard.tsx +1 -1
- package/src/config/RagConfig.ts +1 -1
- package/src/config/serverConfig.ts +2 -2
- package/src/core/ConfigResolver.ts +69 -0
- package/src/core/Pipeline.ts +101 -0
- package/src/core/ProviderRegistry.ts +71 -0
- package/src/core/VectorPlugin.ts +52 -0
- package/src/handlers/index.ts +21 -100
- package/src/hooks/useRagChat.ts +1 -1
- package/src/index.ts +2 -6
- package/src/providers/vectordb/BaseVectorProvider.ts +61 -0
- package/src/providers/vectordb/ChromaDBProvider.ts +94 -0
- package/src/providers/vectordb/MilvusProvider.ts +100 -0
- package/src/providers/vectordb/MongoDBProvider.ts +118 -0
- package/src/{vectordb/adapters/PineconeAdapter.ts → providers/vectordb/PineconeProvider.ts} +21 -56
- package/src/{vectordb/adapters/PgVectorAdapter.ts → providers/vectordb/PostgreSQLProvider.ts} +23 -58
- package/src/providers/vectordb/QdrantProvider.ts +95 -0
- package/src/providers/vectordb/RedisProvider.ts +84 -0
- package/src/providers/vectordb/WeaviateProvider.ts +124 -0
- package/src/server.ts +16 -8
- package/src/test-refactor.ts +59 -0
- package/src/types/index.ts +24 -0
- package/src/utils/templateUtils.ts +6 -6
- package/dist/DocumentChunker-BUrIrcPk.d.mts +0 -43
- package/dist/DocumentChunker-BUrIrcPk.d.ts +0 -43
- package/dist/RAGPipeline-BmkIv1HD.d.mts +0 -298
- package/dist/RAGPipeline-BmkIv1HD.d.ts +0 -298
- package/dist/chunk-NVOMLHXW.mjs +0 -1259
- package/src/rag/RAGPipeline.ts +0 -200
- package/src/vectordb/IVectorDB.ts +0 -75
- package/src/vectordb/VectorDBFactory.ts +0 -41
- package/src/vectordb/adapters/MongoDbAdapter.ts +0 -175
- package/src/vectordb/adapters/UniversalVectorDBAdapter.ts +0 -177
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { VectorPlugin } from './core/VectorPlugin';
|
|
2
|
+
|
|
3
|
+
async function testRefactor() {
|
|
4
|
+
console.log('🚀 Starting VectorPlugin Refactor Test...\n');
|
|
5
|
+
|
|
6
|
+
// Test 1: Initialization with Empty Config (should use env defaults or fallbacks)
|
|
7
|
+
console.log('--- Test 1: Default Config ---');
|
|
8
|
+
try {
|
|
9
|
+
const pluginDefault = new VectorPlugin();
|
|
10
|
+
const config = pluginDefault.getConfig();
|
|
11
|
+
console.log('✅ Resolved Project ID:', config.projectId);
|
|
12
|
+
console.log('✅ Resolved Vector DB Provider:', config.vectorDb.provider);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error('❌ Test 1 Failed:', (err as Error).message);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Test 2: Overriding Config from Host
|
|
18
|
+
console.log('\n--- Test 2: Host Override Config ---');
|
|
19
|
+
try {
|
|
20
|
+
const pluginOverride = new VectorPlugin({
|
|
21
|
+
projectId: 'host-override-test',
|
|
22
|
+
vectorDb: {
|
|
23
|
+
provider: 'milvus',
|
|
24
|
+
indexName: 'milvus-index',
|
|
25
|
+
options: { uri: 'http://localhost:19530' }
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const config = pluginOverride.getConfig();
|
|
29
|
+
console.log('✅ Resolved Project ID (Overridden):', config.projectId);
|
|
30
|
+
console.log('✅ Resolved Vector DB Provider (Overridden):', config.vectorDb.provider);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error('❌ Test 2 Failed:', (err as Error).message);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Test 3: Provider Registry Loading
|
|
36
|
+
console.log('\n--- Test 3: Provider Registry Loading ---');
|
|
37
|
+
try {
|
|
38
|
+
const { ProviderRegistry } = await import('./core/ProviderRegistry');
|
|
39
|
+
const milvusProvider = await ProviderRegistry.createVectorProvider({
|
|
40
|
+
provider: 'milvus',
|
|
41
|
+
indexName: 'test',
|
|
42
|
+
options: { uri: 'http://localhost' }
|
|
43
|
+
});
|
|
44
|
+
console.log('✅ Milvus Provider Instantiated:', milvusProvider.constructor.name);
|
|
45
|
+
|
|
46
|
+
const redisProvider = await ProviderRegistry.createVectorProvider({
|
|
47
|
+
provider: 'redis',
|
|
48
|
+
indexName: 'test',
|
|
49
|
+
options: { baseUrl: 'http://localhost', apiKey: 'test' }
|
|
50
|
+
});
|
|
51
|
+
console.log('✅ Redis Provider Instantiated:', redisProvider.constructor.name);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error('❌ Test 3 Failed:', (err as Error).message);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log('\n✨ Refactor Test Completed.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
testRefactor().catch(console.error);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface VectorMatch {
|
|
2
|
+
id: string;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface UpsertDocument {
|
|
9
|
+
id: string;
|
|
10
|
+
vector: number[];
|
|
11
|
+
content: string;
|
|
12
|
+
metadata?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IngestDocument {
|
|
16
|
+
docId: string;
|
|
17
|
+
content: string;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ChatResponse {
|
|
22
|
+
reply: string;
|
|
23
|
+
sources: VectorMatch[];
|
|
24
|
+
}
|
|
@@ -58,19 +58,19 @@ export function buildPayload(template: string, vars: Record<string, unknown>): u
|
|
|
58
58
|
/**
|
|
59
59
|
* Merges two objects, ignoring undefined, null, or empty string values in the override.
|
|
60
60
|
*/
|
|
61
|
-
export function mergeDefined<T extends
|
|
62
|
-
base: T,
|
|
61
|
+
export function mergeDefined<T extends object>(
|
|
62
|
+
base: T | undefined | null,
|
|
63
63
|
override?: Partial<T>
|
|
64
64
|
): T {
|
|
65
|
+
const merged = { ...(base || {}) } as T;
|
|
66
|
+
|
|
65
67
|
if (!override) {
|
|
66
|
-
return
|
|
68
|
+
return merged;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
const merged = { ...base };
|
|
70
|
-
|
|
71
71
|
for (const [key, value] of Object.entries(override)) {
|
|
72
72
|
if (value !== undefined && value !== null && value !== '') {
|
|
73
|
-
merged
|
|
73
|
+
(merged as Record<string, unknown>)[key] = value;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DocumentChunker — splits long text into overlapping chunks
|
|
3
|
-
* suitable for vector embedding and retrieval.
|
|
4
|
-
*
|
|
5
|
-
* Strategy: sentence-aware sliding window
|
|
6
|
-
* 1. Split on sentence boundaries
|
|
7
|
-
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
8
|
-
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
9
|
-
*/
|
|
10
|
-
interface Chunk {
|
|
11
|
-
id: string;
|
|
12
|
-
content: string;
|
|
13
|
-
metadata?: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
interface ChunkOptions {
|
|
16
|
-
/** Target chunk size in characters (default 1000) */
|
|
17
|
-
chunkSize?: number;
|
|
18
|
-
/** Overlap between consecutive chunks in characters (default 200) */
|
|
19
|
-
chunkOverlap?: number;
|
|
20
|
-
/** Source document identifier used as ID prefix */
|
|
21
|
-
docId?: string;
|
|
22
|
-
/** Extra metadata to attach to every chunk */
|
|
23
|
-
metadata?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
declare class DocumentChunker {
|
|
26
|
-
private readonly chunkSize;
|
|
27
|
-
private readonly chunkOverlap;
|
|
28
|
-
constructor(chunkSize?: number, chunkOverlap?: number);
|
|
29
|
-
/**
|
|
30
|
-
* Split a single text string into overlapping chunks.
|
|
31
|
-
*/
|
|
32
|
-
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
33
|
-
/**
|
|
34
|
-
* Chunk multiple documents at once.
|
|
35
|
-
*/
|
|
36
|
-
chunkMany(documents: Array<{
|
|
37
|
-
content: string;
|
|
38
|
-
docId?: string;
|
|
39
|
-
metadata?: Record<string, unknown>;
|
|
40
|
-
}>): Chunk[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { type Chunk as C, DocumentChunker as D, type ChunkOptions as a };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DocumentChunker — splits long text into overlapping chunks
|
|
3
|
-
* suitable for vector embedding and retrieval.
|
|
4
|
-
*
|
|
5
|
-
* Strategy: sentence-aware sliding window
|
|
6
|
-
* 1. Split on sentence boundaries
|
|
7
|
-
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
8
|
-
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
9
|
-
*/
|
|
10
|
-
interface Chunk {
|
|
11
|
-
id: string;
|
|
12
|
-
content: string;
|
|
13
|
-
metadata?: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
interface ChunkOptions {
|
|
16
|
-
/** Target chunk size in characters (default 1000) */
|
|
17
|
-
chunkSize?: number;
|
|
18
|
-
/** Overlap between consecutive chunks in characters (default 200) */
|
|
19
|
-
chunkOverlap?: number;
|
|
20
|
-
/** Source document identifier used as ID prefix */
|
|
21
|
-
docId?: string;
|
|
22
|
-
/** Extra metadata to attach to every chunk */
|
|
23
|
-
metadata?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
declare class DocumentChunker {
|
|
26
|
-
private readonly chunkSize;
|
|
27
|
-
private readonly chunkOverlap;
|
|
28
|
-
constructor(chunkSize?: number, chunkOverlap?: number);
|
|
29
|
-
/**
|
|
30
|
-
* Split a single text string into overlapping chunks.
|
|
31
|
-
*/
|
|
32
|
-
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
33
|
-
/**
|
|
34
|
-
* Chunk multiple documents at once.
|
|
35
|
-
*/
|
|
36
|
-
chunkMany(documents: Array<{
|
|
37
|
-
content: string;
|
|
38
|
-
docId?: string;
|
|
39
|
-
metadata?: Record<string, unknown>;
|
|
40
|
-
}>): Chunk[];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { type Chunk as C, DocumentChunker as D, type ChunkOptions as a };
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic LLM Provider interface.
|
|
3
|
-
* Covers both chat completion and embedding generation so a single
|
|
4
|
-
* provider can handle both responsibilities when appropriate.
|
|
5
|
-
*/
|
|
6
|
-
interface ChatMessage {
|
|
7
|
-
role: 'user' | 'assistant' | 'system';
|
|
8
|
-
content: string;
|
|
9
|
-
}
|
|
10
|
-
interface ChatOptions {
|
|
11
|
-
/** Override max tokens for this specific call */
|
|
12
|
-
maxTokens?: number;
|
|
13
|
-
/** Override temperature for this specific call */
|
|
14
|
-
temperature?: number;
|
|
15
|
-
/** Stop sequences */
|
|
16
|
-
stop?: string[];
|
|
17
|
-
}
|
|
18
|
-
interface EmbedOptions {
|
|
19
|
-
/** Override model for this specific embed call */
|
|
20
|
-
model?: string;
|
|
21
|
-
}
|
|
22
|
-
interface ILLMProvider {
|
|
23
|
-
/**
|
|
24
|
-
* Send a chat completion request.
|
|
25
|
-
* @param messages – the full conversation history
|
|
26
|
-
* @param context – retrieved RAG context to inject
|
|
27
|
-
* @param options – optional per-call overrides
|
|
28
|
-
* @returns – the assistant's reply text
|
|
29
|
-
*/
|
|
30
|
-
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
31
|
-
/**
|
|
32
|
-
* Generate an embedding vector for the given text.
|
|
33
|
-
* @param text – text to embed
|
|
34
|
-
* @param options – optional overrides
|
|
35
|
-
* @returns – float array (the embedding)
|
|
36
|
-
*/
|
|
37
|
-
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Generate embedding vectors for multiple texts in a single batch.
|
|
40
|
-
* @param texts – array of texts to embed
|
|
41
|
-
* @param options – optional overrides
|
|
42
|
-
* @returns – array of float arrays
|
|
43
|
-
*/
|
|
44
|
-
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
45
|
-
/**
|
|
46
|
-
* Check if the provider endpoint is reachable.
|
|
47
|
-
*/
|
|
48
|
-
ping(): Promise<boolean>;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Generic Vector Database interface.
|
|
53
|
-
* Any adapter (Pinecone, pgVector, REST, Chroma, Qdrant, …) must implement this.
|
|
54
|
-
*/
|
|
55
|
-
interface VectorMatch {
|
|
56
|
-
/** Unique identifier of the stored chunk */
|
|
57
|
-
id: string;
|
|
58
|
-
/** Cosine or dot-product similarity score (0–1) */
|
|
59
|
-
score: number;
|
|
60
|
-
/** The original text content of the chunk */
|
|
61
|
-
content: string;
|
|
62
|
-
/** Arbitrary metadata attached at upsert time */
|
|
63
|
-
metadata?: Record<string, unknown>;
|
|
64
|
-
}
|
|
65
|
-
interface UpsertDocument {
|
|
66
|
-
id: string;
|
|
67
|
-
vector: number[];
|
|
68
|
-
content: string;
|
|
69
|
-
metadata?: Record<string, unknown>;
|
|
70
|
-
}
|
|
71
|
-
interface IVectorDB {
|
|
72
|
-
/**
|
|
73
|
-
* Initialise the connection (create tables, verify index, etc.)
|
|
74
|
-
* Called once during RAGPipeline construction.
|
|
75
|
-
*/
|
|
76
|
-
initialize(): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
* Insert or update a single vector + content pair.
|
|
79
|
-
* @param namespace – optional project/tenant namespace
|
|
80
|
-
*/
|
|
81
|
-
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* Batch upsert for efficient ingestion of many documents.
|
|
84
|
-
*/
|
|
85
|
-
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Find the top-K most similar vectors to the query vector.
|
|
88
|
-
* @param vector – embedding of the user query
|
|
89
|
-
* @param topK – number of results to return
|
|
90
|
-
* @param namespace – optional project/tenant namespace
|
|
91
|
-
* @param filter – optional metadata filter (provider-specific shape)
|
|
92
|
-
*/
|
|
93
|
-
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
94
|
-
/**
|
|
95
|
-
* Delete a stored vector by ID.
|
|
96
|
-
*/
|
|
97
|
-
delete(id: string, namespace?: string): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Delete all vectors in a namespace (full data reset for a project).
|
|
100
|
-
*/
|
|
101
|
-
deleteNamespace(namespace: string): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Check if the underlying DB is reachable.
|
|
104
|
-
*/
|
|
105
|
-
ping(): Promise<boolean>;
|
|
106
|
-
/**
|
|
107
|
-
* Gracefully close the connection.
|
|
108
|
-
*/
|
|
109
|
-
disconnect(): Promise<void>;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Master configuration interface for Retrivora AI.
|
|
114
|
-
* Each consuming project provides one RagConfig object to drive
|
|
115
|
-
* vector DB selection, LLM selection, embedding, and UI branding.
|
|
116
|
-
*/
|
|
117
|
-
type VectorDBProvider = 'pinecone' | 'pgvector' | 'mongodb' | 'rest' | 'universal_rest' | 'custom';
|
|
118
|
-
interface VectorDBConfig {
|
|
119
|
-
/** Which vector database to use */
|
|
120
|
-
provider: VectorDBProvider;
|
|
121
|
-
/** The index / table name to query */
|
|
122
|
-
indexName: string;
|
|
123
|
-
/** Provider-specific options (API keys, connection strings, etc.)
|
|
124
|
-
*
|
|
125
|
-
* For 'universal_rest', the following options are supported:
|
|
126
|
-
* - baseUrl: string
|
|
127
|
-
* - headers?: Record<string, string>
|
|
128
|
-
* - queryPath?: string
|
|
129
|
-
* - upsertPath?: string
|
|
130
|
-
* - queryPayloadTemplate?: string (e.g. '{"vector": {{vector}}, "limit": {{topK}}}')
|
|
131
|
-
* - upsertPayloadTemplate?: string (e.g. '{"id": "{{id}}", "vector": {{vector}}}')
|
|
132
|
-
* - responseExtractPath?: string (e.g. 'data.results')
|
|
133
|
-
* - idPath?: string (e.g. '_id')
|
|
134
|
-
* - scorePath?: string (e.g. 'similarity')
|
|
135
|
-
* - contentPath?: string (e.g. 'text')
|
|
136
|
-
*/
|
|
137
|
-
options: Record<string, unknown>;
|
|
138
|
-
}
|
|
139
|
-
type LLMProvider = 'openai' | 'anthropic' | 'ollama' | 'rest' | 'universal_rest' | 'custom';
|
|
140
|
-
interface LLMConfig {
|
|
141
|
-
/** Which LLM provider to use */
|
|
142
|
-
provider: LLMProvider;
|
|
143
|
-
/** Model name, e.g. "gpt-4o", "claude-3-opus-20240229", "llama3" */
|
|
144
|
-
model: string;
|
|
145
|
-
/** API key for cloud providers */
|
|
146
|
-
apiKey?: string;
|
|
147
|
-
/** Base URL — required for Ollama or self-hosted endpoints */
|
|
148
|
-
baseUrl?: string;
|
|
149
|
-
/** Custom system prompt injected before every chat */
|
|
150
|
-
systemPrompt?: string;
|
|
151
|
-
/** Max tokens in the LLM response */
|
|
152
|
-
maxTokens?: number;
|
|
153
|
-
/** Sampling temperature (0–1) */
|
|
154
|
-
temperature?: number;
|
|
155
|
-
/** Provider-specific options
|
|
156
|
-
*
|
|
157
|
-
* For 'universal_rest', the following options are supported:
|
|
158
|
-
* - headers?: Record<string, string>
|
|
159
|
-
* - chatPath?: string
|
|
160
|
-
* - chatPayloadTemplate?: string (e.g. '{"prompt": "{{prompt}}", "max_tokens": {{maxTokens}}}')
|
|
161
|
-
* - responseExtractPath?: string (e.g. 'choices[0].text' or 'response')
|
|
162
|
-
*/
|
|
163
|
-
options?: Record<string, unknown>;
|
|
164
|
-
}
|
|
165
|
-
type EmbeddingProvider = 'openai' | 'ollama' | 'rest' | 'universal_rest' | 'custom';
|
|
166
|
-
interface EmbeddingConfig {
|
|
167
|
-
/** Which embedding provider to use */
|
|
168
|
-
provider: EmbeddingProvider;
|
|
169
|
-
/** Model name, e.g. "text-embedding-ada-002", "nomic-embed-text" */
|
|
170
|
-
model: string;
|
|
171
|
-
/** API key (if needed) */
|
|
172
|
-
apiKey?: string;
|
|
173
|
-
/** Base URL for custom / Ollama embedding endpoints */
|
|
174
|
-
baseUrl?: string;
|
|
175
|
-
/** Output vector dimension — must match the index dimension */
|
|
176
|
-
dimensions?: number;
|
|
177
|
-
/** Provider-specific options for custom adapters */
|
|
178
|
-
options?: Record<string, unknown>;
|
|
179
|
-
}
|
|
180
|
-
interface UIConfig {
|
|
181
|
-
/** Title shown in the chat header */
|
|
182
|
-
title?: string;
|
|
183
|
-
/** Subtitle / description below the title */
|
|
184
|
-
subtitle?: string;
|
|
185
|
-
/** Primary brand colour (CSS colour string) */
|
|
186
|
-
primaryColor?: string;
|
|
187
|
-
/** Accent colour for user message bubbles */
|
|
188
|
-
accentColor?: string;
|
|
189
|
-
/** URL to a logo image */
|
|
190
|
-
logoUrl?: string;
|
|
191
|
-
/** Input placeholder text */
|
|
192
|
-
placeholder?: string;
|
|
193
|
-
/** Show source cards after each answer */
|
|
194
|
-
showSources?: boolean;
|
|
195
|
-
/** Welcome message shown on first load */
|
|
196
|
-
welcomeMessage?: string;
|
|
197
|
-
/** Whether to show the floating chat widget. Defaults to true. */
|
|
198
|
-
showWidget?: boolean;
|
|
199
|
-
/** Custom 'Powered by' text shown in the header */
|
|
200
|
-
poweredBy?: string;
|
|
201
|
-
/** Visual style: 'glass' (default) or 'solid' */
|
|
202
|
-
visualStyle?: 'glass' | 'solid';
|
|
203
|
-
/** Border radius: 'none', 'sm', 'md', 'lg', 'xl', 'full' */
|
|
204
|
-
borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
205
|
-
}
|
|
206
|
-
interface RAGConfig {
|
|
207
|
-
/** Number of top-K chunks retrieved per query */
|
|
208
|
-
topK?: number;
|
|
209
|
-
/** Minimum similarity score to include a chunk (0–1) */
|
|
210
|
-
scoreThreshold?: number;
|
|
211
|
-
/** Target chunk size in tokens */
|
|
212
|
-
chunkSize?: number;
|
|
213
|
-
/** Overlap between adjacent chunks in tokens */
|
|
214
|
-
chunkOverlap?: number;
|
|
215
|
-
}
|
|
216
|
-
interface RagConfig {
|
|
217
|
-
/**
|
|
218
|
-
* Unique identifier for the consuming project.
|
|
219
|
-
* Used as the vector DB namespace to achieve multi-tenancy.
|
|
220
|
-
*/
|
|
221
|
-
projectId: string;
|
|
222
|
-
/** Vector database configuration */
|
|
223
|
-
vectorDb: VectorDBConfig;
|
|
224
|
-
/** LLM configuration */
|
|
225
|
-
llm: LLMConfig;
|
|
226
|
-
/** Embedding configuration */
|
|
227
|
-
embedding: EmbeddingConfig;
|
|
228
|
-
/** Optional UI branding overrides */
|
|
229
|
-
ui?: UIConfig;
|
|
230
|
-
/** Optional RAG pipeline tuning knobs */
|
|
231
|
-
rag?: RAGConfig;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* RAGPipeline — the central orchestrator for the RAG workflow.
|
|
236
|
-
*
|
|
237
|
-
* Responsibilities:
|
|
238
|
-
* 1. INGEST: chunk → embed → upsert into vector DB
|
|
239
|
-
* 2. ASK: embed query → retrieve top-K chunks → call LLM with context
|
|
240
|
-
*
|
|
241
|
-
* It is LLM-agnostic and vector-DB-agnostic; concrete implementations are
|
|
242
|
-
* injected via ILLMProvider and IVectorDB.
|
|
243
|
-
*/
|
|
244
|
-
|
|
245
|
-
interface IngestDocument {
|
|
246
|
-
/** Unique document ID (used as chunk ID prefix) */
|
|
247
|
-
docId: string;
|
|
248
|
-
/** Full text content of the document */
|
|
249
|
-
content: string;
|
|
250
|
-
/** Optional metadata stored alongside each chunk */
|
|
251
|
-
metadata?: Record<string, unknown>;
|
|
252
|
-
}
|
|
253
|
-
interface ChatResponse {
|
|
254
|
-
/** The LLM's answer */
|
|
255
|
-
reply: string;
|
|
256
|
-
/** Retrieved source chunks used to generate the answer */
|
|
257
|
-
sources: VectorMatch[];
|
|
258
|
-
}
|
|
259
|
-
declare class RAGPipeline {
|
|
260
|
-
private readonly vectorDB;
|
|
261
|
-
private readonly llmProvider;
|
|
262
|
-
private readonly embeddingProvider;
|
|
263
|
-
private readonly chunker;
|
|
264
|
-
private readonly config;
|
|
265
|
-
private initialised;
|
|
266
|
-
constructor(config: RagConfig, adapters?: {
|
|
267
|
-
vectorDB?: IVectorDB;
|
|
268
|
-
llmProvider?: ILLMProvider;
|
|
269
|
-
embeddingProvider?: ILLMProvider;
|
|
270
|
-
});
|
|
271
|
-
/** Lazily initialise the vector DB connection */
|
|
272
|
-
init(): Promise<void>;
|
|
273
|
-
/**
|
|
274
|
-
* Ingest one or more documents into the vector DB.
|
|
275
|
-
* Automatically chunks, embeds, and upserts each chunk.
|
|
276
|
-
*/
|
|
277
|
-
ingest(documents: IngestDocument[], namespace?: string): Promise<{
|
|
278
|
-
docId: string;
|
|
279
|
-
chunksIngested: number;
|
|
280
|
-
}[]>;
|
|
281
|
-
/**
|
|
282
|
-
* Run a full RAG query:
|
|
283
|
-
* 1. Embed the user question
|
|
284
|
-
* 2. Retrieve top-K relevant chunks from the vector DB
|
|
285
|
-
* 3. Filter by score threshold
|
|
286
|
-
* 4. Build context string
|
|
287
|
-
* 5. Call the LLM with chat history + context
|
|
288
|
-
*/
|
|
289
|
-
ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
|
|
290
|
-
health(): Promise<{
|
|
291
|
-
vectorDB: boolean;
|
|
292
|
-
llm: boolean;
|
|
293
|
-
}>;
|
|
294
|
-
deleteDocument(docId: string, namespace?: string): Promise<void>;
|
|
295
|
-
deleteProject(namespace?: string): Promise<void>;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export { type ChatMessage as C, type EmbedOptions as E, type ILLMProvider as I, type LLMConfig as L, type RAGConfig as R, type UIConfig as U, type VectorMatch as V, type ChatOptions as a, type ChatResponse as b, type EmbeddingConfig as c, type IVectorDB as d, type IngestDocument as e, type RagConfig as f, type UpsertDocument as g, type VectorDBConfig as h, RAGPipeline as i };
|