@retrivora-ai/rag-engine 0.1.3 → 0.1.4

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.
Files changed (73) hide show
  1. package/dist/ChromaDBProvider-QNI7UCX4.mjs +8 -0
  2. package/dist/DocumentChunker-BQ5kQD7B.d.ts +155 -0
  3. package/dist/DocumentChunker-D9-fObJp.d.mts +155 -0
  4. package/dist/LLMFactory-XC55FTD2.mjs +7 -0
  5. package/dist/MilvusProvider-OO6QGZDZ.mjs +8 -0
  6. package/dist/MongoDBProvider-WWVJG3WT.mjs +8 -0
  7. package/dist/PineconeProvider-NJ675H7U.mjs +8 -0
  8. package/dist/{RAGPipeline-BmkIv1HD.d.mts → Pipeline-Bo6CUCox.d.mts} +76 -159
  9. package/dist/{RAGPipeline-BmkIv1HD.d.ts → Pipeline-Bo6CUCox.d.ts} +76 -159
  10. package/dist/PostgreSQLProvider-ISNMD3BE.mjs +8 -0
  11. package/dist/QdrantProvider-LJWOIGES.mjs +8 -0
  12. package/dist/RedisProvider-ASONNYBI.mjs +8 -0
  13. package/dist/WeaviateProvider-PSDCUGC7.mjs +8 -0
  14. package/dist/chunk-6FODXNUF.mjs +91 -0
  15. package/dist/chunk-7NXI6ZWX.mjs +89 -0
  16. package/dist/chunk-AALIF3AL.mjs +91 -0
  17. package/dist/chunk-AIAB2IEE.mjs +394 -0
  18. package/dist/chunk-FGGSVVSY.mjs +162 -0
  19. package/dist/chunk-GD3QJFNN.mjs +424 -0
  20. package/dist/chunk-HUGLYKD6.mjs +84 -0
  21. package/dist/chunk-I4E63NIC.mjs +24 -0
  22. package/dist/chunk-QEYVWVT5.mjs +102 -0
  23. package/dist/chunk-S5DRHETN.mjs +110 -0
  24. package/dist/chunk-V75V7BT2.mjs +117 -0
  25. package/dist/chunk-VOIWNO5O.mjs +11 -0
  26. package/dist/chunk-VPNRDXIA.mjs +74 -0
  27. package/dist/handlers/index.d.mts +9 -33
  28. package/dist/handlers/index.d.ts +9 -33
  29. package/dist/handlers/index.js +1477 -962
  30. package/dist/handlers/index.mjs +4 -2
  31. package/dist/index.d.mts +3 -3
  32. package/dist/index.d.ts +3 -3
  33. package/dist/index.js +1646 -19
  34. package/dist/index.mjs +14 -2
  35. package/dist/server.d.mts +93 -56
  36. package/dist/server.d.ts +93 -56
  37. package/dist/server.js +1531 -1099
  38. package/dist/server.mjs +56 -131
  39. package/package.json +1 -1
  40. package/src/app/page.tsx +1 -1
  41. package/src/components/MessageBubble.tsx +1 -1
  42. package/src/components/SourceCard.tsx +1 -1
  43. package/src/config/RagConfig.ts +1 -1
  44. package/src/config/serverConfig.ts +2 -2
  45. package/src/core/ConfigResolver.ts +69 -0
  46. package/src/core/Pipeline.ts +109 -0
  47. package/src/core/ProviderRegistry.ts +71 -0
  48. package/src/core/VectorPlugin.ts +51 -0
  49. package/src/handlers/index.ts +21 -100
  50. package/src/hooks/useRagChat.ts +1 -1
  51. package/src/index.ts +8 -6
  52. package/src/providers/vectordb/BaseVectorProvider.ts +61 -0
  53. package/src/providers/vectordb/ChromaDBProvider.ts +94 -0
  54. package/src/providers/vectordb/MilvusProvider.ts +100 -0
  55. package/src/providers/vectordb/MongoDBProvider.ts +118 -0
  56. package/src/{vectordb/adapters/PineconeAdapter.ts → providers/vectordb/PineconeProvider.ts} +21 -56
  57. package/src/{vectordb/adapters/PgVectorAdapter.ts → providers/vectordb/PostgreSQLProvider.ts} +23 -58
  58. package/src/providers/vectordb/QdrantProvider.ts +95 -0
  59. package/src/providers/vectordb/RedisProvider.ts +84 -0
  60. package/src/providers/vectordb/WeaviateProvider.ts +124 -0
  61. package/src/server.ts +16 -8
  62. package/src/test-refactor.ts +59 -0
  63. package/src/types/index.ts +13 -0
  64. package/src/utils/templateUtils.ts +6 -6
  65. package/dist/DocumentChunker-BUrIrcPk.d.mts +0 -43
  66. package/dist/DocumentChunker-BUrIrcPk.d.ts +0 -43
  67. package/dist/chunk-NVOMLHXW.mjs +0 -1259
  68. package/dist/chunk-ZPXLQR5Q.mjs +0 -67
  69. package/src/rag/RAGPipeline.ts +0 -200
  70. package/src/vectordb/IVectorDB.ts +0 -75
  71. package/src/vectordb/VectorDBFactory.ts +0 -41
  72. package/src/vectordb/adapters/MongoDbAdapter.ts +0 -175
  73. package/src/vectordb/adapters/UniversalVectorDBAdapter.ts +0 -177
@@ -1,120 +1,9 @@
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
1
  /**
113
2
  * Master configuration interface for Retrivora AI.
114
3
  * Each consuming project provides one RagConfig object to drive
115
4
  * vector DB selection, LLM selection, embedding, and UI branding.
116
5
  */
117
- type VectorDBProvider = 'pinecone' | 'pgvector' | 'mongodb' | 'rest' | 'universal_rest' | 'custom';
6
+ type VectorDBProvider = 'pinecone' | 'pgvector' | 'postgresql' | 'mongodb' | 'milvus' | 'qdrant' | 'chromadb' | 'redis' | 'weaviate' | 'rest' | 'universal_rest' | 'custom';
118
7
  interface VectorDBConfig {
119
8
  /** Which vector database to use */
120
9
  provider: VectorDBProvider;
@@ -232,67 +121,95 @@ interface RagConfig {
232
121
  }
233
122
 
234
123
  /**
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.
124
+ * Generic LLM Provider interface.
125
+ * Covers both chat completion and embedding generation so a single
126
+ * provider can handle both responsibilities when appropriate.
243
127
  */
128
+ interface ChatMessage {
129
+ role: 'user' | 'assistant' | 'system';
130
+ content: string;
131
+ }
132
+ interface ChatOptions {
133
+ /** Override max tokens for this specific call */
134
+ maxTokens?: number;
135
+ /** Override temperature for this specific call */
136
+ temperature?: number;
137
+ /** Stop sequences */
138
+ stop?: string[];
139
+ }
140
+ interface EmbedOptions {
141
+ /** Override model for this specific embed call */
142
+ model?: string;
143
+ }
144
+ interface ILLMProvider {
145
+ /**
146
+ * Send a chat completion request.
147
+ * @param messages – the full conversation history
148
+ * @param context – retrieved RAG context to inject
149
+ * @param options – optional per-call overrides
150
+ * @returns – the assistant's reply text
151
+ */
152
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
153
+ /**
154
+ * Generate an embedding vector for the given text.
155
+ * @param text – text to embed
156
+ * @param options – optional overrides
157
+ * @returns – float array (the embedding)
158
+ */
159
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
160
+ /**
161
+ * Generate embedding vectors for multiple texts in a single batch.
162
+ * @param texts – array of texts to embed
163
+ * @param options – optional overrides
164
+ * @returns – array of float arrays
165
+ */
166
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
167
+ /**
168
+ * Check if the provider endpoint is reachable.
169
+ */
170
+ ping(): Promise<boolean>;
171
+ }
172
+
173
+ interface VectorMatch {
174
+ id: string;
175
+ score: number;
176
+ content: string;
177
+ metadata?: Record<string, unknown>;
178
+ }
179
+ interface UpsertDocument {
180
+ id: string;
181
+ vector: number[];
182
+ content: string;
183
+ metadata?: Record<string, unknown>;
184
+ }
244
185
 
245
186
  interface IngestDocument {
246
- /** Unique document ID (used as chunk ID prefix) */
247
187
  docId: string;
248
- /** Full text content of the document */
249
188
  content: string;
250
- /** Optional metadata stored alongside each chunk */
251
189
  metadata?: Record<string, unknown>;
252
190
  }
253
191
  interface ChatResponse {
254
- /** The LLM's answer */
255
192
  reply: string;
256
- /** Retrieved source chunks used to generate the answer */
257
193
  sources: VectorMatch[];
258
194
  }
259
- declare class RAGPipeline {
260
- private readonly vectorDB;
261
- private readonly llmProvider;
262
- private readonly embeddingProvider;
263
- private readonly chunker;
264
- private readonly config;
195
+ /**
196
+ * Pipeline — orchestrates the RAG flow: Embed → Search → Augment → Generate.
197
+ */
198
+ declare class Pipeline {
199
+ private vectorDB;
200
+ private llmProvider;
201
+ private embeddingProvider;
202
+ private chunker;
203
+ private config;
265
204
  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<{
205
+ constructor(config: RagConfig);
206
+ initialize(): Promise<void>;
207
+ ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
278
208
  docId: string;
279
209
  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
- */
210
+ }>>;
289
211
  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>;
212
+ health(): Promise<Record<string, boolean>>;
296
213
  }
297
214
 
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 };
215
+ export { type ChatMessage as C, type EmbedOptions as E, type ILLMProvider as I, type LLMConfig as L, Pipeline as P, 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 IngestDocument as d, type RagConfig as e, type UpsertDocument as f, type VectorDBConfig as g };
@@ -0,0 +1,8 @@
1
+ import {
2
+ PostgreSQLProvider
3
+ } from "./chunk-S5DRHETN.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ PostgreSQLProvider
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ QdrantProvider
3
+ } from "./chunk-6FODXNUF.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ QdrantProvider
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ RedisProvider
3
+ } from "./chunk-VPNRDXIA.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ RedisProvider
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ WeaviateProvider
3
+ } from "./chunk-V75V7BT2.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ WeaviateProvider
8
+ };
@@ -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
+ };
@@ -0,0 +1,89 @@
1
+ import {
2
+ BaseVectorProvider
3
+ } from "./chunk-VOIWNO5O.mjs";
4
+ import {
5
+ __spreadValues
6
+ } from "./chunk-I4E63NIC.mjs";
7
+
8
+ // src/providers/vectordb/MilvusProvider.ts
9
+ import axios from "axios";
10
+ var MilvusProvider = class extends BaseVectorProvider {
11
+ constructor(config) {
12
+ super(config);
13
+ const opts = config.options;
14
+ const baseUrl = opts.baseUrl || opts.uri;
15
+ if (!baseUrl) throw new Error("[MilvusProvider] baseUrl/uri is required");
16
+ this.http = axios.create({
17
+ baseURL: baseUrl,
18
+ headers: __spreadValues(__spreadValues({
19
+ "Content-Type": "application/json"
20
+ }, opts.headers || {}), opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {})
21
+ });
22
+ }
23
+ async initialize() {
24
+ await this.ping();
25
+ }
26
+ async upsert(doc, namespace) {
27
+ const payload = {
28
+ collectionName: this.indexName,
29
+ data: [__spreadValues({
30
+ vector: doc.vector,
31
+ content: doc.content,
32
+ metadata: doc.metadata || {}
33
+ }, namespace ? { namespace } : {})]
34
+ };
35
+ await this.http.post("/v1/vector/upsert", payload);
36
+ }
37
+ async batchUpsert(docs, namespace) {
38
+ const payload = {
39
+ collectionName: this.indexName,
40
+ data: docs.map((doc) => __spreadValues({
41
+ vector: doc.vector,
42
+ content: doc.content,
43
+ metadata: doc.metadata || {}
44
+ }, namespace ? { namespace } : {}))
45
+ };
46
+ await this.http.post("/v1/vector/upsert", payload);
47
+ }
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
+ async query(vector, topK, namespace, _filter) {
50
+ const payload = {
51
+ collectionName: this.indexName,
52
+ vector,
53
+ limit: topK,
54
+ filter: namespace ? `namespace == "${namespace}"` : void 0,
55
+ outputFields: ["content", "metadata"]
56
+ };
57
+ const { data } = await this.http.post("/v1/vector/search", payload);
58
+ return (data.data || []).map((res) => ({
59
+ id: String(res["id"]),
60
+ score: res["distance"],
61
+ content: res["content"],
62
+ metadata: res["metadata"]
63
+ }));
64
+ }
65
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
+ async delete(id, _namespace) {
67
+ await this.http.post("/v1/vector/delete", {
68
+ collectionName: this.indexName,
69
+ id
70
+ });
71
+ }
72
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
73
+ async deleteNamespace(_namespace) {
74
+ }
75
+ async ping() {
76
+ try {
77
+ await this.http.get("/v1/health");
78
+ return true;
79
+ } catch (e) {
80
+ return false;
81
+ }
82
+ }
83
+ async disconnect() {
84
+ }
85
+ };
86
+
87
+ export {
88
+ MilvusProvider
89
+ };
@@ -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/PineconeProvider.ts
9
+ import { Pinecone } from "@pinecone-database/pinecone";
10
+ var PineconeProvider = class extends BaseVectorProvider {
11
+ constructor(config) {
12
+ super(config);
13
+ const opts = config.options;
14
+ if (!opts.apiKey) throw new Error("[PineconeProvider] options.apiKey is required");
15
+ this.apiKey = opts.apiKey;
16
+ }
17
+ async initialize() {
18
+ var _a, _b;
19
+ this.client = new Pinecone({ apiKey: this.apiKey });
20
+ const indexes = await this.client.listIndexes();
21
+ const names = (_b = (_a = indexes.indexes) == null ? void 0 : _a.map((i) => i.name)) != null ? _b : [];
22
+ if (!names.includes(this.indexName)) {
23
+ throw new Error(`[PineconeProvider] Index "${this.indexName}" not found.`);
24
+ }
25
+ }
26
+ index(namespace) {
27
+ const idx = this.client.index(this.indexName);
28
+ return namespace ? idx.namespace(namespace) : idx.namespace("");
29
+ }
30
+ async upsert(doc, namespace) {
31
+ var _a;
32
+ await this.index(namespace).upsert({
33
+ records: [{
34
+ id: doc.id,
35
+ values: doc.vector,
36
+ metadata: __spreadValues({ content: doc.content }, (_a = doc.metadata) != null ? _a : {})
37
+ }]
38
+ });
39
+ }
40
+ async batchUpsert(docs, namespace) {
41
+ const BATCH = 100;
42
+ for (let i = 0; i < docs.length; i += BATCH) {
43
+ const records = docs.slice(i, i + BATCH).map((d) => {
44
+ var _a;
45
+ return {
46
+ id: d.id,
47
+ values: d.vector,
48
+ metadata: __spreadValues({ content: d.content }, (_a = d.metadata) != null ? _a : {})
49
+ };
50
+ });
51
+ await this.index(namespace).upsert({ records });
52
+ }
53
+ }
54
+ async query(vector, topK, namespace, filter) {
55
+ var _a;
56
+ const result = await this.index(namespace).query(__spreadValues({
57
+ vector,
58
+ topK,
59
+ includeMetadata: true
60
+ }, filter ? { filter } : {}));
61
+ return ((_a = result.matches) != null ? _a : []).map((m) => {
62
+ var _a2, _b;
63
+ return {
64
+ id: m.id,
65
+ score: (_a2 = m.score) != null ? _a2 : 0,
66
+ content: ((_b = m.metadata) == null ? void 0 : _b.content) || "",
67
+ metadata: m.metadata
68
+ };
69
+ });
70
+ }
71
+ async delete(id, namespace) {
72
+ await this.index(namespace).deleteOne({ id });
73
+ }
74
+ async deleteNamespace(namespace) {
75
+ await this.client.index(this.indexName).namespace(namespace).deleteAll();
76
+ }
77
+ async ping() {
78
+ try {
79
+ await this.client.listIndexes();
80
+ return true;
81
+ } catch (e) {
82
+ return false;
83
+ }
84
+ }
85
+ async disconnect() {
86
+ }
87
+ };
88
+
89
+ export {
90
+ PineconeProvider
91
+ };