@retrivora-ai/rag-engine 0.1.8 → 0.1.10
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-2JZSBOQX.mjs → ChromaDBProvider-T7TK3ONZ.mjs} +2 -2
- package/dist/{MilvusProvider-CJDBCBVI.mjs → MilvusProvider-Y5FV5EAE.mjs} +2 -2
- package/dist/{MongoDBProvider-WWVJG3WT.mjs → MongoDBProvider-QHMGD2LZ.mjs} +2 -2
- package/dist/{PineconeProvider-E6L5Z2FO.mjs → PineconeProvider-A47MRRYJ.mjs} +2 -2
- package/dist/{PostgreSQLProvider-ZNXA67IM.mjs → PostgreSQLProvider-PJ5ER5Z4.mjs} +1 -1
- package/dist/{QdrantProvider-JITRNJQN.mjs → QdrantProvider-OLPJK7CY.mjs} +2 -2
- package/dist/{RedisProvider-3VKFQXXD.mjs → RedisProvider-ANEJ3BHR.mjs} +2 -2
- package/dist/{UniversalVectorProvider-E6L4U4OX.mjs → UniversalVectorProvider-QJIV2AJJ.mjs} +3 -3
- package/dist/{WeaviateProvider-MXIPP44J.mjs → WeaviateProvider-WIK2QN23.mjs} +2 -2
- package/dist/{chunk-YIYDJQJM.mjs → chunk-2VR5ZMXV.mjs} +11 -11
- package/dist/{chunk-QEYVWVT5.mjs → chunk-5HXNKSCR.mjs} +1 -1
- package/dist/{chunk-MFWJZVF3.mjs → chunk-BMHJTWSU.mjs} +1 -1
- package/dist/{chunk-UKDXCXW7.mjs → chunk-EDLTMSNY.mjs} +1 -1
- package/dist/{chunk-I4E63NIC.mjs → chunk-FWCSY2DS.mjs} +14 -1
- package/dist/{chunk-7BQI4A5J.mjs → chunk-HOMXEE3M.mjs} +1 -1
- package/dist/{chunk-TSX6DQXX.mjs → chunk-RUKZC3ON.mjs} +1 -1
- package/dist/{chunk-YST6KYBJ.mjs → chunk-VEJNRS4B.mjs} +1 -1
- package/dist/{chunk-XZPVJS2B.mjs → chunk-VKE5ZW7Y.mjs} +1 -1
- package/dist/{chunk-Y6HQZDCJ.mjs → chunk-VV2ML6TM.mjs} +2 -2
- package/dist/{chunk-26EMHLIN.mjs → chunk-W2PQR3UK.mjs} +1 -1
- package/dist/handlers/index.mjs +3 -3
- package/dist/index.js +67 -58
- package/dist/index.mjs +74 -47
- package/dist/server.d.mts +36 -1
- package/dist/server.d.ts +36 -1
- package/dist/server.js +127 -0
- package/dist/server.mjs +124 -11
- package/package.json +1 -1
- package/src/app/constants.tsx +220 -0
- package/src/app/page.tsx +193 -363
- package/src/app/types.ts +30 -0
- package/src/components/ChatWindow.tsx +3 -11
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +164 -0
- package/src/server.ts +1 -0
package/src/app/types.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface ArchitectureCardProps {
|
|
4
|
+
icon: React.ReactNode;
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
badge: string;
|
|
8
|
+
badgeColor: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface Snippet {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
code: string;
|
|
16
|
+
language: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PipelineStep {
|
|
20
|
+
step: string;
|
|
21
|
+
Icon: React.ElementType;
|
|
22
|
+
title: string;
|
|
23
|
+
desc: string;
|
|
24
|
+
colors: { from: string; to: string };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ProviderPill {
|
|
28
|
+
Icon: React.ElementType;
|
|
29
|
+
label: string;
|
|
30
|
+
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { MessageBubble } from './MessageBubble';
|
|
13
13
|
import { useConfig } from './ConfigProvider';
|
|
14
14
|
import { useRagChat } from '@/hooks/useRagChat';
|
|
15
|
+
import { BORDER_RADIUS_MAP, CHAT_SUGGESTIONS } from '@/app/constants';
|
|
15
16
|
|
|
16
17
|
interface ChatWindowProps {
|
|
17
18
|
/** Additional className for the wrapper div */
|
|
@@ -67,16 +68,7 @@ export function ChatWindow({ className = '', style, onClose, showClose = false }
|
|
|
67
68
|
|
|
68
69
|
const isEmpty = messages.length === 0;
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
none: 'rounded-none',
|
|
72
|
-
sm: 'rounded-sm',
|
|
73
|
-
md: 'rounded-md',
|
|
74
|
-
lg: 'rounded-lg',
|
|
75
|
-
xl: 'rounded-xl',
|
|
76
|
-
full: 'rounded-3xl',
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const currentRadius = borderRadiusMap[ui.borderRadius || 'xl'];
|
|
71
|
+
const currentRadius = BORDER_RADIUS_MAP[ui.borderRadius || 'xl'];
|
|
80
72
|
const isGlass = ui.visualStyle !== 'solid';
|
|
81
73
|
|
|
82
74
|
return (
|
|
@@ -161,7 +153,7 @@ export function ChatWindow({ className = '', style, onClose, showClose = false }
|
|
|
161
153
|
|
|
162
154
|
{/* Suggested prompts */}
|
|
163
155
|
<div className="flex flex-wrap gap-2 justify-center mt-2">
|
|
164
|
-
{
|
|
156
|
+
{CHAT_SUGGESTIONS.map(
|
|
165
157
|
(suggestion) => (
|
|
166
158
|
<button
|
|
167
159
|
key={suggestion}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Pool, PoolClient } from 'pg';
|
|
2
|
+
import { BaseVectorProvider } from './BaseVectorProvider';
|
|
3
|
+
import { VectorMatch, UpsertDocument } from '../../types';
|
|
4
|
+
import { VectorDBConfig } from '../../config/RagConfig';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* MultiTablePostgresProvider — PostgreSQL implementation that searches across
|
|
8
|
+
* multiple existing tables with pre-existing embeddings.
|
|
9
|
+
*
|
|
10
|
+
* Extends BaseVectorProvider so it can be registered with ProviderRegistry.
|
|
11
|
+
* Upsert operations are not supported — data is assumed to be managed externally
|
|
12
|
+
* or via custom ingestion scripts that write directly to each table.
|
|
13
|
+
*/
|
|
14
|
+
export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
15
|
+
private pool!: Pool;
|
|
16
|
+
private readonly dimensions: number;
|
|
17
|
+
private readonly connectionString: string;
|
|
18
|
+
private readonly tables: string[];
|
|
19
|
+
|
|
20
|
+
constructor(config: VectorDBConfig) {
|
|
21
|
+
super(config);
|
|
22
|
+
const opts = config.options || {};
|
|
23
|
+
if (!opts.connectionString) {
|
|
24
|
+
throw new Error('[MultiTablePostgresProvider] options.connectionString is required');
|
|
25
|
+
}
|
|
26
|
+
this.connectionString = opts.connectionString as string;
|
|
27
|
+
this.dimensions = (opts.dimensions as number) ?? 768;
|
|
28
|
+
|
|
29
|
+
// Tables can come from options.tables (custom key) or be derived from VECTOR_DB_TABLES env var
|
|
30
|
+
const rawTables: string | string[] =
|
|
31
|
+
(opts.tables as string | string[]) ??
|
|
32
|
+
process.env.VECTOR_DB_TABLES ??
|
|
33
|
+
'';
|
|
34
|
+
|
|
35
|
+
this.tables = typeof rawTables === 'string'
|
|
36
|
+
? rawTables.split(',').map((t) => t.trim()).filter(Boolean)
|
|
37
|
+
: rawTables;
|
|
38
|
+
|
|
39
|
+
if (this.tables.length === 0) {
|
|
40
|
+
console.warn(
|
|
41
|
+
'[MultiTablePostgresProvider] No tables configured. ' +
|
|
42
|
+
'Set VECTOR_DB_TABLES as a comma-separated list of table names or pass options.tables.'
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async initialize(): Promise<void> {
|
|
48
|
+
this.pool = new Pool({ connectionString: this.connectionString });
|
|
49
|
+
// Verify connectivity
|
|
50
|
+
const client: PoolClient = await this.pool.connect();
|
|
51
|
+
client.release();
|
|
52
|
+
console.log(
|
|
53
|
+
`[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(', ')}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Upsert is not supported for MultiTablePostgresProvider as it's designed for
|
|
59
|
+
* searching across pre-existing tables with varying schemas.
|
|
60
|
+
*/
|
|
61
|
+
async upsert(_doc: UpsertDocument, _namespace?: string): Promise<void> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
62
|
+
throw new Error(
|
|
63
|
+
'[MultiTablePostgresProvider] upsert() is not supported in multi-table mode. ' +
|
|
64
|
+
'Please use the standard PostgreSQLProvider for single-table managed indices.'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Batch upsert is not supported for MultiTablePostgresProvider.
|
|
70
|
+
*/
|
|
71
|
+
async batchUpsert(_docs: UpsertDocument[], _namespace?: string): Promise<void> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
72
|
+
throw new Error(
|
|
73
|
+
'[MultiTablePostgresProvider] batchUpsert() is not supported in multi-table mode.'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Query all configured tables and merge results, sorted by cosine similarity score.
|
|
79
|
+
*/
|
|
80
|
+
async query(
|
|
81
|
+
vector: number[],
|
|
82
|
+
topK: number,
|
|
83
|
+
_namespace?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
84
|
+
_filter?: Record<string, unknown> // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
85
|
+
): Promise<VectorMatch[]> {
|
|
86
|
+
if (!this.pool) {
|
|
87
|
+
throw new Error('[MultiTablePostgresProvider] Provider not initialized. Call initialize() first.');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log(`[MultiTablePostgresProvider] Querying ${this.tables.length} table(s) with vector dim=${vector.length}`);
|
|
91
|
+
|
|
92
|
+
const vectorLiteral = `[${vector.join(',')}]`;
|
|
93
|
+
const allResults: VectorMatch[] = [];
|
|
94
|
+
|
|
95
|
+
for (const table of this.tables) {
|
|
96
|
+
try {
|
|
97
|
+
const result = await this.pool.query(
|
|
98
|
+
`SELECT *, 1 - (embedding <=> $1::vector) AS score
|
|
99
|
+
FROM "${table}"
|
|
100
|
+
ORDER BY embedding <=> $1::vector
|
|
101
|
+
LIMIT $2`,
|
|
102
|
+
[vectorLiteral, topK]
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
for (const row of result.rows) {
|
|
106
|
+
const { score, id, ...rest } = row as Record<string, unknown>;
|
|
107
|
+
// Remove embedding from rest to avoid including it in content
|
|
108
|
+
delete rest.embedding;
|
|
109
|
+
|
|
110
|
+
// Build a human-readable content string from ALL available columns.
|
|
111
|
+
// This ensures the LLM sees the name, website, description, etc. together.
|
|
112
|
+
const content = Object.entries(rest)
|
|
113
|
+
.filter(([k, v]) => v !== null && typeof v !== 'object' && k !== 'id')
|
|
114
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
115
|
+
.join('\n');
|
|
116
|
+
|
|
117
|
+
allResults.push({
|
|
118
|
+
id: `${table}-${id}`,
|
|
119
|
+
score: parseFloat(String(score)),
|
|
120
|
+
content,
|
|
121
|
+
metadata: { ...rest, source_table: table },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.error(
|
|
126
|
+
`[MultiTablePostgresProvider] Error querying table "${table}":`,
|
|
127
|
+
(err as Error).message
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Merge and rank by score descending
|
|
133
|
+
const sortedResults = allResults.sort((a, b) => b.score - a.score);
|
|
134
|
+
|
|
135
|
+
if (sortedResults.length > 0) {
|
|
136
|
+
console.log(`[MultiTablePostgresProvider] Top match from "${sortedResults[0].metadata?.source_table ?? 'unknown'}" with score ${sortedResults[0].score.toFixed(4)}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return sortedResults.slice(0, Math.max(topK, 15));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async delete(_id: string | number, _namespace?: string): Promise<void> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
143
|
+
console.warn('[MultiTablePostgresProvider] delete() is a no-op for multi-table mode.');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async deleteNamespace(_namespace: string): Promise<void> { // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
147
|
+
console.warn('[MultiTablePostgresProvider] deleteNamespace() is a no-op for multi-table mode.');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async ping(): Promise<boolean> {
|
|
151
|
+
try {
|
|
152
|
+
await this.pool.query('SELECT 1');
|
|
153
|
+
return true;
|
|
154
|
+
} catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async disconnect(): Promise<void> {
|
|
160
|
+
if (this.pool) {
|
|
161
|
+
await this.pool.end();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -37,6 +37,7 @@ export { DocumentParser } from './utils/DocumentParser';
|
|
|
37
37
|
export { BaseVectorProvider } from './providers/vectordb/BaseVectorProvider';
|
|
38
38
|
export { PineconeProvider } from './providers/vectordb/PineconeProvider';
|
|
39
39
|
export { PostgreSQLProvider } from './providers/vectordb/PostgreSQLProvider';
|
|
40
|
+
export { MultiTablePostgresProvider } from './providers/vectordb/MultiTablePostgresProvider';
|
|
40
41
|
export { MongoDBProvider } from './providers/vectordb/MongoDBProvider';
|
|
41
42
|
export { MilvusProvider } from './providers/vectordb/MilvusProvider';
|
|
42
43
|
export { QdrantProvider } from './providers/vectordb/QdrantProvider';
|