@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,93 @@
|
|
|
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
|
+
* DocumentChunker — splits long text into overlapping chunks
|
|
53
|
+
* suitable for vector embedding and retrieval.
|
|
54
|
+
*
|
|
55
|
+
* Strategy: sentence-aware sliding window
|
|
56
|
+
* 1. Split on sentence boundaries
|
|
57
|
+
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
58
|
+
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
59
|
+
*/
|
|
60
|
+
interface Chunk {
|
|
61
|
+
id: string;
|
|
62
|
+
content: string;
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
interface ChunkOptions {
|
|
66
|
+
/** Target chunk size in characters (default 1000) */
|
|
67
|
+
chunkSize?: number;
|
|
68
|
+
/** Overlap between consecutive chunks in characters (default 200) */
|
|
69
|
+
chunkOverlap?: number;
|
|
70
|
+
/** Source document identifier used as ID prefix */
|
|
71
|
+
docId?: string;
|
|
72
|
+
/** Extra metadata to attach to every chunk */
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
declare class DocumentChunker {
|
|
76
|
+
private readonly chunkSize;
|
|
77
|
+
private readonly chunkOverlap;
|
|
78
|
+
constructor(chunkSize?: number, chunkOverlap?: number);
|
|
79
|
+
/**
|
|
80
|
+
* Split a single text string into overlapping chunks.
|
|
81
|
+
*/
|
|
82
|
+
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
83
|
+
/**
|
|
84
|
+
* Chunk multiple documents at once.
|
|
85
|
+
*/
|
|
86
|
+
chunkMany(documents: Array<{
|
|
87
|
+
content: string;
|
|
88
|
+
docId?: string;
|
|
89
|
+
metadata?: Record<string, unknown>;
|
|
90
|
+
}>): Chunk[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type ChatMessage as C, DocumentChunker as D, type EmbedOptions as E, type ILLMProvider as I, type ChatOptions as a, type Chunk as b, type ChunkOptions as c };
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
* DocumentChunker — splits long text into overlapping chunks
|
|
53
|
+
* suitable for vector embedding and retrieval.
|
|
54
|
+
*
|
|
55
|
+
* Strategy: sentence-aware sliding window
|
|
56
|
+
* 1. Split on sentence boundaries
|
|
57
|
+
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
58
|
+
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
59
|
+
*/
|
|
60
|
+
interface Chunk {
|
|
61
|
+
id: string;
|
|
62
|
+
content: string;
|
|
63
|
+
metadata?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
interface ChunkOptions {
|
|
66
|
+
/** Target chunk size in characters (default 1000) */
|
|
67
|
+
chunkSize?: number;
|
|
68
|
+
/** Overlap between consecutive chunks in characters (default 200) */
|
|
69
|
+
chunkOverlap?: number;
|
|
70
|
+
/** Source document identifier used as ID prefix */
|
|
71
|
+
docId?: string;
|
|
72
|
+
/** Extra metadata to attach to every chunk */
|
|
73
|
+
metadata?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
declare class DocumentChunker {
|
|
76
|
+
private readonly chunkSize;
|
|
77
|
+
private readonly chunkOverlap;
|
|
78
|
+
constructor(chunkSize?: number, chunkOverlap?: number);
|
|
79
|
+
/**
|
|
80
|
+
* Split a single text string into overlapping chunks.
|
|
81
|
+
*/
|
|
82
|
+
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
83
|
+
/**
|
|
84
|
+
* Chunk multiple documents at once.
|
|
85
|
+
*/
|
|
86
|
+
chunkMany(documents: Array<{
|
|
87
|
+
content: string;
|
|
88
|
+
docId?: string;
|
|
89
|
+
metadata?: Record<string, unknown>;
|
|
90
|
+
}>): Chunk[];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type ChatMessage as C, DocumentChunker as D, type EmbedOptions as E, type ILLMProvider as I, type ChatOptions as a, type Chunk as b, type ChunkOptions as c };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
interface VectorMatch {
|
|
2
|
+
id: string;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface UpsertDocument {
|
|
8
|
+
id: string;
|
|
9
|
+
vector: number[];
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface IngestDocument {
|
|
14
|
+
docId: string;
|
|
15
|
+
content: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
interface ChatResponse {
|
|
19
|
+
reply: string;
|
|
20
|
+
sources: VectorMatch[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Master configuration interface for Retrivora AI.
|
|
25
|
+
* Each consuming project provides one RagConfig object to drive
|
|
26
|
+
* vector DB selection, LLM selection, embedding, and UI branding.
|
|
27
|
+
*/
|
|
28
|
+
type VectorDBProvider = 'pinecone' | 'pgvector' | 'postgresql' | 'mongodb' | 'milvus' | 'qdrant' | 'chromadb' | 'redis' | 'weaviate' | 'rest' | 'universal_rest' | 'custom';
|
|
29
|
+
interface VectorDBConfig {
|
|
30
|
+
/** Which vector database to use */
|
|
31
|
+
provider: VectorDBProvider;
|
|
32
|
+
/** The index / table name to query */
|
|
33
|
+
indexName: string;
|
|
34
|
+
/** Provider-specific options (API keys, connection strings, etc.)
|
|
35
|
+
*
|
|
36
|
+
* For 'universal_rest', the following options are supported:
|
|
37
|
+
* - baseUrl: string
|
|
38
|
+
* - headers?: Record<string, string>
|
|
39
|
+
* - queryPath?: string
|
|
40
|
+
* - upsertPath?: string
|
|
41
|
+
* - queryPayloadTemplate?: string (e.g. '{"vector": {{vector}}, "limit": {{topK}}}')
|
|
42
|
+
* - upsertPayloadTemplate?: string (e.g. '{"id": "{{id}}", "vector": {{vector}}}')
|
|
43
|
+
* - responseExtractPath?: string (e.g. 'data.results')
|
|
44
|
+
* - idPath?: string (e.g. '_id')
|
|
45
|
+
* - scorePath?: string (e.g. 'similarity')
|
|
46
|
+
* - contentPath?: string (e.g. 'text')
|
|
47
|
+
*/
|
|
48
|
+
options: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
type LLMProvider = 'openai' | 'anthropic' | 'ollama' | 'rest' | 'universal_rest' | 'custom';
|
|
51
|
+
interface LLMConfig {
|
|
52
|
+
/** Which LLM provider to use */
|
|
53
|
+
provider: LLMProvider;
|
|
54
|
+
/** Model name, e.g. "gpt-4o", "claude-3-opus-20240229", "llama3" */
|
|
55
|
+
model: string;
|
|
56
|
+
/** API key for cloud providers */
|
|
57
|
+
apiKey?: string;
|
|
58
|
+
/** Base URL — required for Ollama or self-hosted endpoints */
|
|
59
|
+
baseUrl?: string;
|
|
60
|
+
/** Custom system prompt injected before every chat */
|
|
61
|
+
systemPrompt?: string;
|
|
62
|
+
/** Max tokens in the LLM response */
|
|
63
|
+
maxTokens?: number;
|
|
64
|
+
/** Sampling temperature (0–1) */
|
|
65
|
+
temperature?: number;
|
|
66
|
+
/** Provider-specific options
|
|
67
|
+
*
|
|
68
|
+
* For 'universal_rest', the following options are supported:
|
|
69
|
+
* - headers?: Record<string, string>
|
|
70
|
+
* - chatPath?: string
|
|
71
|
+
* - chatPayloadTemplate?: string (e.g. '{"prompt": "{{prompt}}", "max_tokens": {{maxTokens}}}')
|
|
72
|
+
* - responseExtractPath?: string (e.g. 'choices[0].text' or 'response')
|
|
73
|
+
*/
|
|
74
|
+
options?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
type EmbeddingProvider = 'openai' | 'ollama' | 'rest' | 'universal_rest' | 'custom';
|
|
77
|
+
interface EmbeddingConfig {
|
|
78
|
+
/** Which embedding provider to use */
|
|
79
|
+
provider: EmbeddingProvider;
|
|
80
|
+
/** Model name, e.g. "text-embedding-ada-002", "nomic-embed-text" */
|
|
81
|
+
model: string;
|
|
82
|
+
/** API key (if needed) */
|
|
83
|
+
apiKey?: string;
|
|
84
|
+
/** Base URL for custom / Ollama embedding endpoints */
|
|
85
|
+
baseUrl?: string;
|
|
86
|
+
/** Output vector dimension — must match the index dimension */
|
|
87
|
+
dimensions?: number;
|
|
88
|
+
/** Provider-specific options for custom adapters */
|
|
89
|
+
options?: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
interface UIConfig {
|
|
92
|
+
/** Title shown in the chat header */
|
|
93
|
+
title?: string;
|
|
94
|
+
/** Subtitle / description below the title */
|
|
95
|
+
subtitle?: string;
|
|
96
|
+
/** Primary brand colour (CSS colour string) */
|
|
97
|
+
primaryColor?: string;
|
|
98
|
+
/** Accent colour for user message bubbles */
|
|
99
|
+
accentColor?: string;
|
|
100
|
+
/** URL to a logo image */
|
|
101
|
+
logoUrl?: string;
|
|
102
|
+
/** Input placeholder text */
|
|
103
|
+
placeholder?: string;
|
|
104
|
+
/** Show source cards after each answer */
|
|
105
|
+
showSources?: boolean;
|
|
106
|
+
/** Welcome message shown on first load */
|
|
107
|
+
welcomeMessage?: string;
|
|
108
|
+
/** Whether to show the floating chat widget. Defaults to true. */
|
|
109
|
+
showWidget?: boolean;
|
|
110
|
+
/** Custom 'Powered by' text shown in the header */
|
|
111
|
+
poweredBy?: string;
|
|
112
|
+
/** Visual style: 'glass' (default) or 'solid' */
|
|
113
|
+
visualStyle?: 'glass' | 'solid';
|
|
114
|
+
/** Border radius: 'none', 'sm', 'md', 'lg', 'xl', 'full' */
|
|
115
|
+
borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
116
|
+
}
|
|
117
|
+
interface RAGConfig {
|
|
118
|
+
/** Number of top-K chunks retrieved per query */
|
|
119
|
+
topK?: number;
|
|
120
|
+
/** Minimum similarity score to include a chunk (0–1) */
|
|
121
|
+
scoreThreshold?: number;
|
|
122
|
+
/** Target chunk size in tokens */
|
|
123
|
+
chunkSize?: number;
|
|
124
|
+
/** Overlap between adjacent chunks in tokens */
|
|
125
|
+
chunkOverlap?: number;
|
|
126
|
+
}
|
|
127
|
+
interface RagConfig {
|
|
128
|
+
/**
|
|
129
|
+
* Unique identifier for the consuming project.
|
|
130
|
+
* Used as the vector DB namespace to achieve multi-tenancy.
|
|
131
|
+
*/
|
|
132
|
+
projectId: string;
|
|
133
|
+
/** Vector database configuration */
|
|
134
|
+
vectorDb: VectorDBConfig;
|
|
135
|
+
/** LLM configuration */
|
|
136
|
+
llm: LLMConfig;
|
|
137
|
+
/** Embedding configuration */
|
|
138
|
+
embedding: EmbeddingConfig;
|
|
139
|
+
/** Optional UI branding overrides */
|
|
140
|
+
ui?: UIConfig;
|
|
141
|
+
/** Optional RAG pipeline tuning knobs */
|
|
142
|
+
rag?: RAGConfig;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type { ChatResponse as C, EmbeddingConfig as E, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, RagConfig as a, UpsertDocument as b, VectorDBConfig as c };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
interface VectorMatch {
|
|
2
|
+
id: string;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface UpsertDocument {
|
|
8
|
+
id: string;
|
|
9
|
+
vector: number[];
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface IngestDocument {
|
|
14
|
+
docId: string;
|
|
15
|
+
content: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
interface ChatResponse {
|
|
19
|
+
reply: string;
|
|
20
|
+
sources: VectorMatch[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Master configuration interface for Retrivora AI.
|
|
25
|
+
* Each consuming project provides one RagConfig object to drive
|
|
26
|
+
* vector DB selection, LLM selection, embedding, and UI branding.
|
|
27
|
+
*/
|
|
28
|
+
type VectorDBProvider = 'pinecone' | 'pgvector' | 'postgresql' | 'mongodb' | 'milvus' | 'qdrant' | 'chromadb' | 'redis' | 'weaviate' | 'rest' | 'universal_rest' | 'custom';
|
|
29
|
+
interface VectorDBConfig {
|
|
30
|
+
/** Which vector database to use */
|
|
31
|
+
provider: VectorDBProvider;
|
|
32
|
+
/** The index / table name to query */
|
|
33
|
+
indexName: string;
|
|
34
|
+
/** Provider-specific options (API keys, connection strings, etc.)
|
|
35
|
+
*
|
|
36
|
+
* For 'universal_rest', the following options are supported:
|
|
37
|
+
* - baseUrl: string
|
|
38
|
+
* - headers?: Record<string, string>
|
|
39
|
+
* - queryPath?: string
|
|
40
|
+
* - upsertPath?: string
|
|
41
|
+
* - queryPayloadTemplate?: string (e.g. '{"vector": {{vector}}, "limit": {{topK}}}')
|
|
42
|
+
* - upsertPayloadTemplate?: string (e.g. '{"id": "{{id}}", "vector": {{vector}}}')
|
|
43
|
+
* - responseExtractPath?: string (e.g. 'data.results')
|
|
44
|
+
* - idPath?: string (e.g. '_id')
|
|
45
|
+
* - scorePath?: string (e.g. 'similarity')
|
|
46
|
+
* - contentPath?: string (e.g. 'text')
|
|
47
|
+
*/
|
|
48
|
+
options: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
type LLMProvider = 'openai' | 'anthropic' | 'ollama' | 'rest' | 'universal_rest' | 'custom';
|
|
51
|
+
interface LLMConfig {
|
|
52
|
+
/** Which LLM provider to use */
|
|
53
|
+
provider: LLMProvider;
|
|
54
|
+
/** Model name, e.g. "gpt-4o", "claude-3-opus-20240229", "llama3" */
|
|
55
|
+
model: string;
|
|
56
|
+
/** API key for cloud providers */
|
|
57
|
+
apiKey?: string;
|
|
58
|
+
/** Base URL — required for Ollama or self-hosted endpoints */
|
|
59
|
+
baseUrl?: string;
|
|
60
|
+
/** Custom system prompt injected before every chat */
|
|
61
|
+
systemPrompt?: string;
|
|
62
|
+
/** Max tokens in the LLM response */
|
|
63
|
+
maxTokens?: number;
|
|
64
|
+
/** Sampling temperature (0–1) */
|
|
65
|
+
temperature?: number;
|
|
66
|
+
/** Provider-specific options
|
|
67
|
+
*
|
|
68
|
+
* For 'universal_rest', the following options are supported:
|
|
69
|
+
* - headers?: Record<string, string>
|
|
70
|
+
* - chatPath?: string
|
|
71
|
+
* - chatPayloadTemplate?: string (e.g. '{"prompt": "{{prompt}}", "max_tokens": {{maxTokens}}}')
|
|
72
|
+
* - responseExtractPath?: string (e.g. 'choices[0].text' or 'response')
|
|
73
|
+
*/
|
|
74
|
+
options?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
type EmbeddingProvider = 'openai' | 'ollama' | 'rest' | 'universal_rest' | 'custom';
|
|
77
|
+
interface EmbeddingConfig {
|
|
78
|
+
/** Which embedding provider to use */
|
|
79
|
+
provider: EmbeddingProvider;
|
|
80
|
+
/** Model name, e.g. "text-embedding-ada-002", "nomic-embed-text" */
|
|
81
|
+
model: string;
|
|
82
|
+
/** API key (if needed) */
|
|
83
|
+
apiKey?: string;
|
|
84
|
+
/** Base URL for custom / Ollama embedding endpoints */
|
|
85
|
+
baseUrl?: string;
|
|
86
|
+
/** Output vector dimension — must match the index dimension */
|
|
87
|
+
dimensions?: number;
|
|
88
|
+
/** Provider-specific options for custom adapters */
|
|
89
|
+
options?: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
interface UIConfig {
|
|
92
|
+
/** Title shown in the chat header */
|
|
93
|
+
title?: string;
|
|
94
|
+
/** Subtitle / description below the title */
|
|
95
|
+
subtitle?: string;
|
|
96
|
+
/** Primary brand colour (CSS colour string) */
|
|
97
|
+
primaryColor?: string;
|
|
98
|
+
/** Accent colour for user message bubbles */
|
|
99
|
+
accentColor?: string;
|
|
100
|
+
/** URL to a logo image */
|
|
101
|
+
logoUrl?: string;
|
|
102
|
+
/** Input placeholder text */
|
|
103
|
+
placeholder?: string;
|
|
104
|
+
/** Show source cards after each answer */
|
|
105
|
+
showSources?: boolean;
|
|
106
|
+
/** Welcome message shown on first load */
|
|
107
|
+
welcomeMessage?: string;
|
|
108
|
+
/** Whether to show the floating chat widget. Defaults to true. */
|
|
109
|
+
showWidget?: boolean;
|
|
110
|
+
/** Custom 'Powered by' text shown in the header */
|
|
111
|
+
poweredBy?: string;
|
|
112
|
+
/** Visual style: 'glass' (default) or 'solid' */
|
|
113
|
+
visualStyle?: 'glass' | 'solid';
|
|
114
|
+
/** Border radius: 'none', 'sm', 'md', 'lg', 'xl', 'full' */
|
|
115
|
+
borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
116
|
+
}
|
|
117
|
+
interface RAGConfig {
|
|
118
|
+
/** Number of top-K chunks retrieved per query */
|
|
119
|
+
topK?: number;
|
|
120
|
+
/** Minimum similarity score to include a chunk (0–1) */
|
|
121
|
+
scoreThreshold?: number;
|
|
122
|
+
/** Target chunk size in tokens */
|
|
123
|
+
chunkSize?: number;
|
|
124
|
+
/** Overlap between adjacent chunks in tokens */
|
|
125
|
+
chunkOverlap?: number;
|
|
126
|
+
}
|
|
127
|
+
interface RagConfig {
|
|
128
|
+
/**
|
|
129
|
+
* Unique identifier for the consuming project.
|
|
130
|
+
* Used as the vector DB namespace to achieve multi-tenancy.
|
|
131
|
+
*/
|
|
132
|
+
projectId: string;
|
|
133
|
+
/** Vector database configuration */
|
|
134
|
+
vectorDb: VectorDBConfig;
|
|
135
|
+
/** LLM configuration */
|
|
136
|
+
llm: LLMConfig;
|
|
137
|
+
/** Embedding configuration */
|
|
138
|
+
embedding: EmbeddingConfig;
|
|
139
|
+
/** Optional UI branding overrides */
|
|
140
|
+
ui?: UIConfig;
|
|
141
|
+
/** Optional RAG pipeline tuning knobs */
|
|
142
|
+
rag?: RAGConfig;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type { ChatResponse as C, EmbeddingConfig as E, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, RagConfig as a, UpsertDocument as b, VectorDBConfig as c };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseVectorProvider
|
|
3
|
+
} from "./chunk-VOIWNO5O.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "./chunk-I4E63NIC.mjs";
|
|
7
|
+
|
|
8
|
+
// src/providers/vectordb/QdrantProvider.ts
|
|
9
|
+
import axios from "axios";
|
|
10
|
+
var QdrantProvider = class extends BaseVectorProvider {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
super(config);
|
|
13
|
+
const opts = config.options;
|
|
14
|
+
const baseUrl = opts.baseUrl;
|
|
15
|
+
if (!baseUrl) throw new Error("[QdrantProvider] baseUrl is required");
|
|
16
|
+
this.http = axios.create({
|
|
17
|
+
baseURL: baseUrl,
|
|
18
|
+
headers: __spreadValues({
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
}, opts.apiKey ? { "api-key": opts.apiKey } : {})
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async initialize() {
|
|
24
|
+
await this.ping();
|
|
25
|
+
}
|
|
26
|
+
async upsert(doc, namespace) {
|
|
27
|
+
await this.batchUpsert([doc], namespace);
|
|
28
|
+
}
|
|
29
|
+
async batchUpsert(docs, namespace) {
|
|
30
|
+
const payload = {
|
|
31
|
+
points: docs.map((doc) => ({
|
|
32
|
+
id: doc.id,
|
|
33
|
+
vector: doc.vector,
|
|
34
|
+
payload: __spreadValues({
|
|
35
|
+
content: doc.content,
|
|
36
|
+
metadata: doc.metadata || {}
|
|
37
|
+
}, namespace ? { namespace } : {})
|
|
38
|
+
}))
|
|
39
|
+
};
|
|
40
|
+
await this.http.put(`/collections/${this.indexName}/points`, payload);
|
|
41
|
+
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
async query(vector, topK, namespace, _filter) {
|
|
44
|
+
const payload = {
|
|
45
|
+
vector,
|
|
46
|
+
limit: topK,
|
|
47
|
+
with_payload: true,
|
|
48
|
+
filter: namespace ? {
|
|
49
|
+
must: [{ key: "namespace", match: { value: namespace } }]
|
|
50
|
+
} : void 0
|
|
51
|
+
};
|
|
52
|
+
const { data } = await this.http.post(`/collections/${this.indexName}/points/search`, payload);
|
|
53
|
+
return (data.result || []).map((res) => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
return {
|
|
56
|
+
id: res["id"],
|
|
57
|
+
score: res["score"],
|
|
58
|
+
content: ((_a = res["payload"]) == null ? void 0 : _a.content) || "",
|
|
59
|
+
metadata: ((_b = res["payload"]) == null ? void 0 : _b.metadata) || {}
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
|
+
async delete(id, _namespace) {
|
|
65
|
+
await this.http.post(`/collections/${this.indexName}/points/delete`, {
|
|
66
|
+
points: [id]
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
+
async deleteNamespace(_namespace) {
|
|
71
|
+
await this.http.post(`/collections/${this.indexName}/points/delete`, {
|
|
72
|
+
filter: {
|
|
73
|
+
must: [{ key: "namespace", match: { value: _namespace } }]
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async ping() {
|
|
78
|
+
try {
|
|
79
|
+
await this.http.get("/healthz");
|
|
80
|
+
return true;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async disconnect() {
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
QdrantProvider
|
|
91
|
+
};
|