@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,177 +0,0 @@
1
- import axios, { AxiosInstance } from 'axios';
2
- import { IVectorDB, VectorMatch, UpsertDocument } from '../IVectorDB';
3
- import { VectorDBConfig } from '../../config/RagConfig';
4
- import { resolvePath, buildPayload } from '../../utils/templateUtils';
5
- import { VECTOR_PROFILES } from '../../config/UniversalProfiles';
6
-
7
- interface UniversalVectorDBOptions {
8
- baseUrl?: string;
9
- headers?: Record<string, string>;
10
- queryPath?: string;
11
- upsertPath?: string;
12
- deletePath?: string;
13
- deleteNamespacePath?: string;
14
- pingPath?: string;
15
- queryPayloadTemplate?: string;
16
- upsertPayloadTemplate?: string;
17
- batchUpsertPayloadTemplate?: string;
18
- responseExtractPath?: string;
19
- idPath?: string;
20
- scorePath?: string;
21
- contentPath?: string;
22
- metadataPath?: string;
23
- timeout?: number;
24
- }
25
-
26
- export class UniversalVectorDBAdapter implements IVectorDB {
27
- private readonly http: AxiosInstance;
28
- private readonly indexName: string;
29
- private readonly opts: UniversalVectorDBOptions;
30
-
31
- constructor(config: VectorDBConfig) {
32
- this.indexName = config.indexName;
33
-
34
- // Merge profile defaults if specified
35
- const options = (config.options as Record<string, unknown>) ?? {};
36
- let profile: Record<string, unknown> = {};
37
-
38
- if (typeof options.profile === 'string') {
39
- profile = (VECTOR_PROFILES as Record<string, Record<string, unknown>>)[options.profile] || {};
40
- } else if (typeof options.profile === 'object' && options.profile !== null) {
41
- profile = options.profile as Record<string, unknown>;
42
- }
43
-
44
- this.opts = { ...profile, ...(config.options ?? {}) } as UniversalVectorDBOptions;
45
-
46
- if (!this.opts.baseUrl) {
47
- throw new Error('[UniversalVectorDBAdapter] options.baseUrl is required');
48
- }
49
-
50
- this.http = axios.create({
51
- baseURL: this.opts.baseUrl,
52
- headers: {
53
- 'Content-Type': 'application/json',
54
- ...(this.opts.headers || {}),
55
- },
56
- timeout: this.opts.timeout ?? 30_000,
57
- });
58
- }
59
-
60
- async initialize(): Promise<void> {
61
- if (this.opts.pingPath) {
62
- const ok = await this.ping();
63
- if (!ok) {
64
- throw new Error(`[UniversalVectorDBAdapter] Could not reach health endpoint: ${this.opts.pingPath}`);
65
- }
66
- }
67
- }
68
-
69
- async upsert(doc: UpsertDocument, namespace?: string): Promise<void> {
70
- const path = this.opts.upsertPath ?? '/upsert';
71
-
72
- if (this.opts.upsertPayloadTemplate) {
73
- const payload = buildPayload(this.opts.upsertPayloadTemplate, {
74
- id: doc.id,
75
- vector: doc.vector,
76
- content: doc.content,
77
- metadata: doc.metadata ?? {},
78
- namespace: namespace ?? '',
79
- index: this.indexName,
80
- });
81
- await this.http.post(path, payload);
82
- } else {
83
- // Fallback to standard generic shape
84
- await this.http.post(path, {
85
- index: this.indexName,
86
- namespace,
87
- ...doc,
88
- });
89
- }
90
- }
91
-
92
- async batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void> {
93
- const path = this.opts.upsertPath ?? '/upsert';
94
-
95
- // For batch upsert with templating, if the user provided batchUpsertPayloadTemplate
96
- if (this.opts.batchUpsertPayloadTemplate) {
97
- const payload = buildPayload(this.opts.batchUpsertPayloadTemplate, {
98
- vectors: docs,
99
- namespace: namespace ?? '',
100
- index: this.indexName,
101
- });
102
- await this.http.post(path, payload);
103
- } else {
104
- // Fallback to standard loop or generic shape
105
- await Promise.all(docs.map((doc) => this.upsert(doc, namespace)));
106
- }
107
- }
108
-
109
- async query(
110
- vector: number[],
111
- topK: number,
112
- namespace?: string,
113
- filter?: Record<string, unknown>
114
- ): Promise<VectorMatch[]> {
115
- const path = this.opts.queryPath ?? '/query';
116
-
117
- let payload: unknown;
118
- if (this.opts.queryPayloadTemplate) {
119
- payload = buildPayload(this.opts.queryPayloadTemplate, {
120
- vector,
121
- topK,
122
- namespace: namespace ?? '',
123
- index: this.indexName,
124
- filter: filter ?? {},
125
- });
126
- } else {
127
- payload = { index: this.indexName, namespace, vector, topK, filter };
128
- }
129
-
130
- const { data } = await this.http.post(path, payload);
131
-
132
- const extractPath = this.opts.responseExtractPath ?? 'matches';
133
- const matchesRaw = resolvePath(data, extractPath);
134
-
135
- if (!Array.isArray(matchesRaw)) {
136
- throw new Error(`[UniversalVectorDBAdapter] Expected an array at responseExtractPath '${extractPath}', but got ${typeof matchesRaw}`);
137
- }
138
-
139
- const idPath = this.opts.idPath ?? 'id';
140
- const scorePath = this.opts.scorePath ?? 'score';
141
- const contentPath = this.opts.contentPath ?? 'content';
142
- const metadataPath = this.opts.metadataPath ?? 'metadata';
143
-
144
- return matchesRaw.map((match) => ({
145
- id: String(resolvePath(match, idPath) || ''),
146
- score: Number(resolvePath(match, scorePath) || 0),
147
- content: String(resolvePath(match, contentPath) || ''),
148
- metadata: (resolvePath(match, metadataPath) as Record<string, unknown> | undefined) || {},
149
- }));
150
- }
151
-
152
- async delete(id: string, namespace?: string): Promise<void> {
153
- const path = this.opts.deletePath ?? '/delete';
154
- await this.http.post(path, { index: this.indexName, namespace, id });
155
- }
156
-
157
- async deleteNamespace(namespace: string): Promise<void> {
158
- const path = this.opts.deleteNamespacePath ?? '/delete-namespace';
159
- await this.http.post(path, { index: this.indexName, namespace });
160
- }
161
-
162
- async ping(): Promise<boolean> {
163
- try {
164
- if (this.opts.pingPath) {
165
- await this.http.get(this.opts.pingPath);
166
- }
167
- return true;
168
- } catch (err) {
169
- console.error('[UniversalVectorDBAdapter] Ping failed:', err);
170
- return false;
171
- }
172
- }
173
-
174
- async disconnect(): Promise<void> {
175
- // Axios based adapter is stateless per request.
176
- }
177
- }