@retrivora-ai/rag-engine 0.1.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/.env.example +77 -0
- package/README.md +149 -0
- package/dist/DocumentChunker-BUrIrcPk.d.mts +43 -0
- package/dist/DocumentChunker-BUrIrcPk.d.ts +43 -0
- package/dist/RAGPipeline-BmkIv1HD.d.mts +298 -0
- package/dist/RAGPipeline-BmkIv1HD.d.ts +298 -0
- package/dist/chunk-NCG2JKXB.mjs +1254 -0
- package/dist/chunk-ZPXLQR5Q.mjs +67 -0
- package/dist/handlers/index.d.mts +68 -0
- package/dist/handlers/index.d.ts +68 -0
- package/dist/handlers/index.js +1319 -0
- package/dist/handlers/index.mjs +13 -0
- package/dist/index.d.mts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +612 -0
- package/dist/index.mjs +551 -0
- package/dist/server.d.mts +211 -0
- package/dist/server.d.ts +211 -0
- package/dist/server.js +1457 -0
- package/dist/server.mjs +148 -0
- package/package.json +90 -0
- package/src/app/api/chat/route.ts +4 -0
- package/src/app/api/health/route.ts +4 -0
- package/src/app/api/ingest/route.ts +26 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +163 -0
- package/src/app/layout.tsx +35 -0
- package/src/app/page.tsx +506 -0
- package/src/components/ChatWidget.tsx +91 -0
- package/src/components/ChatWindow.tsx +248 -0
- package/src/components/ConfigProvider.tsx +56 -0
- package/src/components/MessageBubble.tsx +99 -0
- package/src/components/SourceCard.tsx +66 -0
- package/src/components/ThemeProvider.tsx +8 -0
- package/src/components/ThemeToggle.tsx +29 -0
- package/src/config/RagConfig.ts +159 -0
- package/src/config/UniversalProfiles.ts +83 -0
- package/src/config/serverConfig.ts +142 -0
- package/src/handlers/index.ts +202 -0
- package/src/hooks/useHydrated.ts +13 -0
- package/src/hooks/useRagChat.ts +167 -0
- package/src/hooks/useStoredMessages.ts +53 -0
- package/src/index.ts +27 -0
- package/src/llm/ILLMProvider.ts +60 -0
- package/src/llm/LLMFactory.ts +54 -0
- package/src/llm/providers/AnthropicProvider.ts +87 -0
- package/src/llm/providers/OllamaProvider.ts +102 -0
- package/src/llm/providers/OpenAIProvider.ts +92 -0
- package/src/llm/providers/UniversalLLMAdapter.ts +154 -0
- package/src/rag/DocumentChunker.ts +105 -0
- package/src/rag/RAGPipeline.ts +196 -0
- package/src/server.ts +30 -0
- package/src/types/pdf-parse.d.ts +13 -0
- package/src/utils/DocumentParser.ts +75 -0
- package/src/utils/templateUtils.ts +78 -0
- package/src/vectordb/IVectorDB.ts +75 -0
- package/src/vectordb/VectorDBFactory.ts +41 -0
- package/src/vectordb/adapters/MongoDbAdapter.ts +175 -0
- package/src/vectordb/adapters/PgVectorAdapter.ts +159 -0
- package/src/vectordb/adapters/PineconeAdapter.ts +115 -0
- package/src/vectordb/adapters/UniversalVectorDBAdapter.ts +177 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { f as RagConfig, h as VectorDBConfig, d as IVectorDB, g as UpsertDocument, V as VectorMatch, L as LLMConfig, c as EmbeddingConfig, I as ILLMProvider, C as ChatMessage, a as ChatOptions, E as EmbedOptions } from './RAGPipeline-BmkIv1HD.mjs';
|
|
2
|
+
export { b as ChatResponse, e as IngestDocument, R as RAGConfig, i as RAGPipeline, U as UIConfig } from './RAGPipeline-BmkIv1HD.mjs';
|
|
3
|
+
export { C as Chunk, a as ChunkOptions, D as DocumentChunker } from './DocumentChunker-BUrIrcPk.mjs';
|
|
4
|
+
export { createChatHandler, createHealthHandler, createIngestHandler, createUploadHandler } from './handlers/index.mjs';
|
|
5
|
+
import 'next/server';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* serverConfig.ts — reads RagConfig from environment variables at runtime.
|
|
9
|
+
*
|
|
10
|
+
* This keeps secrets server-side and never exposes them to the browser.
|
|
11
|
+
* Consumer projects set these env vars in their .env.local file.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
declare function getRagConfig(env?: Record<string, string | undefined>): RagConfig;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* VectorDBFactory — instantiates the correct IVectorDB adapter
|
|
18
|
+
* based on the VectorDBConfig.provider value.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* const db = VectorDBFactory.create(config.vectorDb);
|
|
22
|
+
* await db.initialize();
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
declare class VectorDBFactory {
|
|
26
|
+
static create(config: VectorDBConfig): IVectorDB;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pinecone Vector DB Adapter
|
|
31
|
+
*
|
|
32
|
+
* Required options in VectorDBConfig.options:
|
|
33
|
+
* - apiKey: string – Pinecone API key
|
|
34
|
+
* - environment?: string – Pinecone environment (legacy, optional for new projects)
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
declare class PineconeAdapter implements IVectorDB {
|
|
38
|
+
private client;
|
|
39
|
+
private readonly indexName;
|
|
40
|
+
private readonly apiKey;
|
|
41
|
+
constructor(config: VectorDBConfig);
|
|
42
|
+
initialize(): Promise<void>;
|
|
43
|
+
private index;
|
|
44
|
+
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
45
|
+
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
46
|
+
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
47
|
+
delete(id: string, namespace?: string): Promise<void>;
|
|
48
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
49
|
+
ping(): Promise<boolean>;
|
|
50
|
+
disconnect(): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* pgVector Adapter
|
|
55
|
+
*
|
|
56
|
+
* Stores embeddings in a PostgreSQL table using the pgvector extension.
|
|
57
|
+
* Required options in VectorDBConfig.options:
|
|
58
|
+
* - connectionString: string – PostgreSQL connection string
|
|
59
|
+
* - dimensions?: number – vector dimensions (default 1536 for OpenAI ada-002)
|
|
60
|
+
*
|
|
61
|
+
* The adapter auto-creates the table and index on initialize().
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
declare class PgVectorAdapter implements IVectorDB {
|
|
65
|
+
private pool;
|
|
66
|
+
private readonly tableName;
|
|
67
|
+
private readonly dimensions;
|
|
68
|
+
private readonly connectionString;
|
|
69
|
+
constructor(config: VectorDBConfig);
|
|
70
|
+
initialize(): Promise<void>;
|
|
71
|
+
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
72
|
+
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
73
|
+
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
74
|
+
delete(id: string, namespace?: string): Promise<void>;
|
|
75
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
76
|
+
ping(): Promise<boolean>;
|
|
77
|
+
disconnect(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* MongoDB Adapter for Atlas Vector Search.
|
|
82
|
+
*
|
|
83
|
+
* Requirements:
|
|
84
|
+
* 1. A MongoDB Atlas cluster (v6.0.11+, v7.0.2+).
|
|
85
|
+
* 2. A Vector Search Index created on the collection.
|
|
86
|
+
*
|
|
87
|
+
* Config Options:
|
|
88
|
+
* - uri: string (Required)
|
|
89
|
+
* - database: string (Required)
|
|
90
|
+
* - collection: string (Required)
|
|
91
|
+
* - indexName: string (Default: 'vector_index')
|
|
92
|
+
* - embeddingKey: string (Default: 'embedding')
|
|
93
|
+
* - contentKey: string (Default: 'content')
|
|
94
|
+
* - metadataKey: string (Default: 'metadata')
|
|
95
|
+
*/
|
|
96
|
+
declare class MongoDbAdapter implements IVectorDB {
|
|
97
|
+
private client;
|
|
98
|
+
private db?;
|
|
99
|
+
private collection?;
|
|
100
|
+
private uri;
|
|
101
|
+
private dbName;
|
|
102
|
+
private collectionName;
|
|
103
|
+
private indexName;
|
|
104
|
+
private embeddingKey;
|
|
105
|
+
private contentKey;
|
|
106
|
+
private metadataKey;
|
|
107
|
+
constructor(options: Record<string, unknown>);
|
|
108
|
+
initialize(): Promise<void>;
|
|
109
|
+
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
110
|
+
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
111
|
+
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
112
|
+
delete(id: string, namespace?: string): Promise<void>;
|
|
113
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
114
|
+
ping(): Promise<boolean>;
|
|
115
|
+
disconnect(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* LLMFactory — instantiates the correct ILLMProvider based on llmConfig.provider.
|
|
120
|
+
*
|
|
121
|
+
* Also accepts an optional EmbeddingConfig so providers that support embedding
|
|
122
|
+
* can be initialised with separate embedding credentials.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
declare class LLMFactory {
|
|
126
|
+
static create(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a dedicated embedding-only provider.
|
|
129
|
+
* Useful when the LLM provider (e.g. Anthropic) doesn't support embeddings.
|
|
130
|
+
*/
|
|
131
|
+
static createEmbeddingProvider(embeddingConfig: EmbeddingConfig): ILLMProvider;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* OpenAI LLM Provider
|
|
136
|
+
*
|
|
137
|
+
* Handles both chat completion (GPT-4o, GPT-4-turbo, etc.) and
|
|
138
|
+
* embedding (text-embedding-ada-002, text-embedding-3-small/large).
|
|
139
|
+
*
|
|
140
|
+
* Required LLMConfig fields:
|
|
141
|
+
* - apiKey: string – OpenAI API key
|
|
142
|
+
* - model: string – e.g. "gpt-4o"
|
|
143
|
+
*
|
|
144
|
+
* Required EmbeddingConfig fields (when used for embedding):
|
|
145
|
+
* - apiKey: string – same or separate key
|
|
146
|
+
* - model: string – e.g. "text-embedding-3-small"
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
declare class OpenAIProvider implements ILLMProvider {
|
|
150
|
+
private readonly client;
|
|
151
|
+
private readonly llmConfig;
|
|
152
|
+
private readonly embeddingConfig?;
|
|
153
|
+
constructor(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig);
|
|
154
|
+
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
155
|
+
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
156
|
+
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
157
|
+
ping(): Promise<boolean>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Anthropic (Claude) LLM Provider
|
|
162
|
+
*
|
|
163
|
+
* Handles chat completion via Anthropic's Messages API.
|
|
164
|
+
* Note: Anthropic does NOT provide embedding models — use OpenAIProvider
|
|
165
|
+
* or OllamaProvider for embedding when pairing with this provider.
|
|
166
|
+
*
|
|
167
|
+
* Required LLMConfig fields:
|
|
168
|
+
* - apiKey: string – Anthropic API key
|
|
169
|
+
* - model: string – e.g. "claude-3-5-sonnet-20241022"
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
declare class AnthropicProvider implements ILLMProvider {
|
|
173
|
+
private readonly client;
|
|
174
|
+
private readonly llmConfig;
|
|
175
|
+
private readonly embeddingConfig?;
|
|
176
|
+
constructor(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig);
|
|
177
|
+
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Anthropic does not offer an embedding API.
|
|
180
|
+
* This method throws with a clear error so developers know to configure
|
|
181
|
+
* a separate embedding provider (OpenAI or Ollama).
|
|
182
|
+
*/
|
|
183
|
+
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
184
|
+
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
185
|
+
ping(): Promise<boolean>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Ollama LLM Provider (local / self-hosted)
|
|
190
|
+
*
|
|
191
|
+
* Communicates with an Ollama server via its REST API.
|
|
192
|
+
* Supports both chat completion and embedding (requires a model with embed support,
|
|
193
|
+
* e.g. "nomic-embed-text", "mxbai-embed-large").
|
|
194
|
+
*
|
|
195
|
+
* Required LLMConfig fields:
|
|
196
|
+
* - model: string – e.g. "llama3", "mistral", "gemma2"
|
|
197
|
+
* - baseUrl?: string – Ollama server URL (default "http://localhost:11434")
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
declare class OllamaProvider implements ILLMProvider {
|
|
201
|
+
private readonly http;
|
|
202
|
+
private readonly llmConfig;
|
|
203
|
+
private readonly embeddingConfig?;
|
|
204
|
+
constructor(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig);
|
|
205
|
+
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
206
|
+
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
207
|
+
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
208
|
+
ping(): Promise<boolean>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { AnthropicProvider, ChatMessage, ChatOptions, EmbedOptions, EmbeddingConfig, ILLMProvider, IVectorDB, LLMConfig, LLMFactory, MongoDbAdapter, OllamaProvider, OpenAIProvider, PgVectorAdapter, PineconeAdapter, RagConfig, UpsertDocument, VectorDBConfig, VectorDBFactory, VectorMatch, getRagConfig };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { f as RagConfig, h as VectorDBConfig, d as IVectorDB, g as UpsertDocument, V as VectorMatch, L as LLMConfig, c as EmbeddingConfig, I as ILLMProvider, C as ChatMessage, a as ChatOptions, E as EmbedOptions } from './RAGPipeline-BmkIv1HD.js';
|
|
2
|
+
export { b as ChatResponse, e as IngestDocument, R as RAGConfig, i as RAGPipeline, U as UIConfig } from './RAGPipeline-BmkIv1HD.js';
|
|
3
|
+
export { C as Chunk, a as ChunkOptions, D as DocumentChunker } from './DocumentChunker-BUrIrcPk.js';
|
|
4
|
+
export { createChatHandler, createHealthHandler, createIngestHandler, createUploadHandler } from './handlers/index.js';
|
|
5
|
+
import 'next/server';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* serverConfig.ts — reads RagConfig from environment variables at runtime.
|
|
9
|
+
*
|
|
10
|
+
* This keeps secrets server-side and never exposes them to the browser.
|
|
11
|
+
* Consumer projects set these env vars in their .env.local file.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
declare function getRagConfig(env?: Record<string, string | undefined>): RagConfig;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* VectorDBFactory — instantiates the correct IVectorDB adapter
|
|
18
|
+
* based on the VectorDBConfig.provider value.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* const db = VectorDBFactory.create(config.vectorDb);
|
|
22
|
+
* await db.initialize();
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
declare class VectorDBFactory {
|
|
26
|
+
static create(config: VectorDBConfig): IVectorDB;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Pinecone Vector DB Adapter
|
|
31
|
+
*
|
|
32
|
+
* Required options in VectorDBConfig.options:
|
|
33
|
+
* - apiKey: string – Pinecone API key
|
|
34
|
+
* - environment?: string – Pinecone environment (legacy, optional for new projects)
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
declare class PineconeAdapter implements IVectorDB {
|
|
38
|
+
private client;
|
|
39
|
+
private readonly indexName;
|
|
40
|
+
private readonly apiKey;
|
|
41
|
+
constructor(config: VectorDBConfig);
|
|
42
|
+
initialize(): Promise<void>;
|
|
43
|
+
private index;
|
|
44
|
+
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
45
|
+
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
46
|
+
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
47
|
+
delete(id: string, namespace?: string): Promise<void>;
|
|
48
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
49
|
+
ping(): Promise<boolean>;
|
|
50
|
+
disconnect(): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* pgVector Adapter
|
|
55
|
+
*
|
|
56
|
+
* Stores embeddings in a PostgreSQL table using the pgvector extension.
|
|
57
|
+
* Required options in VectorDBConfig.options:
|
|
58
|
+
* - connectionString: string – PostgreSQL connection string
|
|
59
|
+
* - dimensions?: number – vector dimensions (default 1536 for OpenAI ada-002)
|
|
60
|
+
*
|
|
61
|
+
* The adapter auto-creates the table and index on initialize().
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
declare class PgVectorAdapter implements IVectorDB {
|
|
65
|
+
private pool;
|
|
66
|
+
private readonly tableName;
|
|
67
|
+
private readonly dimensions;
|
|
68
|
+
private readonly connectionString;
|
|
69
|
+
constructor(config: VectorDBConfig);
|
|
70
|
+
initialize(): Promise<void>;
|
|
71
|
+
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
72
|
+
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
73
|
+
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
74
|
+
delete(id: string, namespace?: string): Promise<void>;
|
|
75
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
76
|
+
ping(): Promise<boolean>;
|
|
77
|
+
disconnect(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* MongoDB Adapter for Atlas Vector Search.
|
|
82
|
+
*
|
|
83
|
+
* Requirements:
|
|
84
|
+
* 1. A MongoDB Atlas cluster (v6.0.11+, v7.0.2+).
|
|
85
|
+
* 2. A Vector Search Index created on the collection.
|
|
86
|
+
*
|
|
87
|
+
* Config Options:
|
|
88
|
+
* - uri: string (Required)
|
|
89
|
+
* - database: string (Required)
|
|
90
|
+
* - collection: string (Required)
|
|
91
|
+
* - indexName: string (Default: 'vector_index')
|
|
92
|
+
* - embeddingKey: string (Default: 'embedding')
|
|
93
|
+
* - contentKey: string (Default: 'content')
|
|
94
|
+
* - metadataKey: string (Default: 'metadata')
|
|
95
|
+
*/
|
|
96
|
+
declare class MongoDbAdapter implements IVectorDB {
|
|
97
|
+
private client;
|
|
98
|
+
private db?;
|
|
99
|
+
private collection?;
|
|
100
|
+
private uri;
|
|
101
|
+
private dbName;
|
|
102
|
+
private collectionName;
|
|
103
|
+
private indexName;
|
|
104
|
+
private embeddingKey;
|
|
105
|
+
private contentKey;
|
|
106
|
+
private metadataKey;
|
|
107
|
+
constructor(options: Record<string, unknown>);
|
|
108
|
+
initialize(): Promise<void>;
|
|
109
|
+
upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
|
|
110
|
+
batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
|
|
111
|
+
query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
|
|
112
|
+
delete(id: string, namespace?: string): Promise<void>;
|
|
113
|
+
deleteNamespace(namespace: string): Promise<void>;
|
|
114
|
+
ping(): Promise<boolean>;
|
|
115
|
+
disconnect(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* LLMFactory — instantiates the correct ILLMProvider based on llmConfig.provider.
|
|
120
|
+
*
|
|
121
|
+
* Also accepts an optional EmbeddingConfig so providers that support embedding
|
|
122
|
+
* can be initialised with separate embedding credentials.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
declare class LLMFactory {
|
|
126
|
+
static create(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a dedicated embedding-only provider.
|
|
129
|
+
* Useful when the LLM provider (e.g. Anthropic) doesn't support embeddings.
|
|
130
|
+
*/
|
|
131
|
+
static createEmbeddingProvider(embeddingConfig: EmbeddingConfig): ILLMProvider;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* OpenAI LLM Provider
|
|
136
|
+
*
|
|
137
|
+
* Handles both chat completion (GPT-4o, GPT-4-turbo, etc.) and
|
|
138
|
+
* embedding (text-embedding-ada-002, text-embedding-3-small/large).
|
|
139
|
+
*
|
|
140
|
+
* Required LLMConfig fields:
|
|
141
|
+
* - apiKey: string – OpenAI API key
|
|
142
|
+
* - model: string – e.g. "gpt-4o"
|
|
143
|
+
*
|
|
144
|
+
* Required EmbeddingConfig fields (when used for embedding):
|
|
145
|
+
* - apiKey: string – same or separate key
|
|
146
|
+
* - model: string – e.g. "text-embedding-3-small"
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
declare class OpenAIProvider implements ILLMProvider {
|
|
150
|
+
private readonly client;
|
|
151
|
+
private readonly llmConfig;
|
|
152
|
+
private readonly embeddingConfig?;
|
|
153
|
+
constructor(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig);
|
|
154
|
+
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
155
|
+
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
156
|
+
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
157
|
+
ping(): Promise<boolean>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Anthropic (Claude) LLM Provider
|
|
162
|
+
*
|
|
163
|
+
* Handles chat completion via Anthropic's Messages API.
|
|
164
|
+
* Note: Anthropic does NOT provide embedding models — use OpenAIProvider
|
|
165
|
+
* or OllamaProvider for embedding when pairing with this provider.
|
|
166
|
+
*
|
|
167
|
+
* Required LLMConfig fields:
|
|
168
|
+
* - apiKey: string – Anthropic API key
|
|
169
|
+
* - model: string – e.g. "claude-3-5-sonnet-20241022"
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
declare class AnthropicProvider implements ILLMProvider {
|
|
173
|
+
private readonly client;
|
|
174
|
+
private readonly llmConfig;
|
|
175
|
+
private readonly embeddingConfig?;
|
|
176
|
+
constructor(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig);
|
|
177
|
+
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
178
|
+
/**
|
|
179
|
+
* Anthropic does not offer an embedding API.
|
|
180
|
+
* This method throws with a clear error so developers know to configure
|
|
181
|
+
* a separate embedding provider (OpenAI or Ollama).
|
|
182
|
+
*/
|
|
183
|
+
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
184
|
+
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
185
|
+
ping(): Promise<boolean>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Ollama LLM Provider (local / self-hosted)
|
|
190
|
+
*
|
|
191
|
+
* Communicates with an Ollama server via its REST API.
|
|
192
|
+
* Supports both chat completion and embedding (requires a model with embed support,
|
|
193
|
+
* e.g. "nomic-embed-text", "mxbai-embed-large").
|
|
194
|
+
*
|
|
195
|
+
* Required LLMConfig fields:
|
|
196
|
+
* - model: string – e.g. "llama3", "mistral", "gemma2"
|
|
197
|
+
* - baseUrl?: string – Ollama server URL (default "http://localhost:11434")
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
declare class OllamaProvider implements ILLMProvider {
|
|
201
|
+
private readonly http;
|
|
202
|
+
private readonly llmConfig;
|
|
203
|
+
private readonly embeddingConfig?;
|
|
204
|
+
constructor(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig);
|
|
205
|
+
chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
|
|
206
|
+
embed(text: string, options?: EmbedOptions): Promise<number[]>;
|
|
207
|
+
batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
|
|
208
|
+
ping(): Promise<boolean>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { AnthropicProvider, ChatMessage, ChatOptions, EmbedOptions, EmbeddingConfig, ILLMProvider, IVectorDB, LLMConfig, LLMFactory, MongoDbAdapter, OllamaProvider, OpenAIProvider, PgVectorAdapter, PineconeAdapter, RagConfig, UpsertDocument, VectorDBConfig, VectorDBFactory, VectorMatch, getRagConfig };
|