@retrivora-ai/rag-engine 0.1.9 → 0.2.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/dist/server.d.mts CHANGED
@@ -705,7 +705,7 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
705
705
  private pool;
706
706
  private readonly dimensions;
707
707
  private readonly connectionString;
708
- private readonly tables;
708
+ private tables;
709
709
  constructor(config: VectorDBConfig);
710
710
  initialize(): Promise<void>;
711
711
  /**
package/dist/server.d.ts CHANGED
@@ -705,7 +705,7 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
705
705
  private pool;
706
706
  private readonly dimensions;
707
707
  private readonly connectionString;
708
- private readonly tables;
708
+ private tables;
709
709
  constructor(config: VectorDBConfig);
710
710
  initialize(): Promise<void>;
711
711
  /**
package/dist/server.js CHANGED
@@ -3699,10 +3699,34 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
3699
3699
  async initialize() {
3700
3700
  this.pool = new import_pg2.Pool({ connectionString: this.connectionString });
3701
3701
  const client = await this.pool.connect();
3702
- client.release();
3703
- console.log(
3704
- `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(", ")}`
3705
- );
3702
+ try {
3703
+ const res = await client.query(`
3704
+ SELECT table_name
3705
+ FROM information_schema.columns
3706
+ WHERE column_name = 'embedding'
3707
+ AND table_schema = 'public'
3708
+ `);
3709
+ const discoveredTables = res.rows.map((r) => r.table_name);
3710
+ if (this.tables.length === 0) {
3711
+ this.tables = discoveredTables;
3712
+ } else {
3713
+ const staticTables = [...this.tables];
3714
+ this.tables = staticTables.filter((t) => discoveredTables.includes(t));
3715
+ if (this.tables.length < staticTables.length) {
3716
+ const missing = staticTables.filter((t) => !discoveredTables.includes(t));
3717
+ console.warn(`[MultiTablePostgresProvider] Some configured tables were skipped (missing 'embedding' column): ${missing.join(", ")}`);
3718
+ }
3719
+ }
3720
+ if (this.tables.length === 0) {
3721
+ console.warn('[MultiTablePostgresProvider] No tables with "embedding" columns found in the database.');
3722
+ } else {
3723
+ console.log(
3724
+ `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(", ")}`
3725
+ );
3726
+ }
3727
+ } finally {
3728
+ client.release();
3729
+ }
3706
3730
  }
3707
3731
  /**
3708
3732
  * Upsert is not supported for MultiTablePostgresProvider as it's designed for
@@ -3744,7 +3768,9 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
3744
3768
  for (const row of result.rows) {
3745
3769
  const _a = row, { score, id } = _a, rest = __objRest(_a, ["score", "id"]);
3746
3770
  delete rest.embedding;
3747
- const content = Object.entries(rest).filter(([k, v]) => v !== null && typeof v !== "object" && k !== "id").map(([k, v]) => `${k}: ${v}`).join("\n");
3771
+ const type = table.replace(/s$/, "").toUpperCase();
3772
+ const content = `[TYPE: ${type}]
3773
+ ` + Object.entries(rest).filter(([k, v]) => v !== null && typeof v !== "object" && k !== "id").map(([k, v]) => `${k}: ${v}`).join("\n");
3748
3774
  allResults.push({
3749
3775
  id: `${table}-${id}`,
3750
3776
  score: parseFloat(String(score)),
@@ -3763,7 +3789,7 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
3763
3789
  if (sortedResults.length > 0) {
3764
3790
  console.log(`[MultiTablePostgresProvider] Top match from "${(_c = (_b = sortedResults[0].metadata) == null ? void 0 : _b.source_table) != null ? _c : "unknown"}" with score ${sortedResults[0].score.toFixed(4)}`);
3765
3791
  }
3766
- return sortedResults.slice(0, topK);
3792
+ return sortedResults.slice(0, Math.max(topK, 15));
3767
3793
  }
3768
3794
  async delete(_id, _namespace) {
3769
3795
  console.warn("[MultiTablePostgresProvider] delete() is a no-op for multi-table mode.");
package/dist/server.mjs CHANGED
@@ -356,10 +356,34 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
356
356
  async initialize() {
357
357
  this.pool = new Pool({ connectionString: this.connectionString });
358
358
  const client = await this.pool.connect();
359
- client.release();
360
- console.log(
361
- `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(", ")}`
362
- );
359
+ try {
360
+ const res = await client.query(`
361
+ SELECT table_name
362
+ FROM information_schema.columns
363
+ WHERE column_name = 'embedding'
364
+ AND table_schema = 'public'
365
+ `);
366
+ const discoveredTables = res.rows.map((r) => r.table_name);
367
+ if (this.tables.length === 0) {
368
+ this.tables = discoveredTables;
369
+ } else {
370
+ const staticTables = [...this.tables];
371
+ this.tables = staticTables.filter((t) => discoveredTables.includes(t));
372
+ if (this.tables.length < staticTables.length) {
373
+ const missing = staticTables.filter((t) => !discoveredTables.includes(t));
374
+ console.warn(`[MultiTablePostgresProvider] Some configured tables were skipped (missing 'embedding' column): ${missing.join(", ")}`);
375
+ }
376
+ }
377
+ if (this.tables.length === 0) {
378
+ console.warn('[MultiTablePostgresProvider] No tables with "embedding" columns found in the database.');
379
+ } else {
380
+ console.log(
381
+ `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(", ")}`
382
+ );
383
+ }
384
+ } finally {
385
+ client.release();
386
+ }
363
387
  }
364
388
  /**
365
389
  * Upsert is not supported for MultiTablePostgresProvider as it's designed for
@@ -401,7 +425,9 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
401
425
  for (const row of result.rows) {
402
426
  const _a = row, { score, id } = _a, rest = __objRest(_a, ["score", "id"]);
403
427
  delete rest.embedding;
404
- const content = Object.entries(rest).filter(([k, v]) => v !== null && typeof v !== "object" && k !== "id").map(([k, v]) => `${k}: ${v}`).join("\n");
428
+ const type = table.replace(/s$/, "").toUpperCase();
429
+ const content = `[TYPE: ${type}]
430
+ ` + Object.entries(rest).filter(([k, v]) => v !== null && typeof v !== "object" && k !== "id").map(([k, v]) => `${k}: ${v}`).join("\n");
405
431
  allResults.push({
406
432
  id: `${table}-${id}`,
407
433
  score: parseFloat(String(score)),
@@ -420,7 +446,7 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
420
446
  if (sortedResults.length > 0) {
421
447
  console.log(`[MultiTablePostgresProvider] Top match from "${(_c = (_b = sortedResults[0].metadata) == null ? void 0 : _b.source_table) != null ? _c : "unknown"}" with score ${sortedResults[0].score.toFixed(4)}`);
422
448
  }
423
- return sortedResults.slice(0, topK);
449
+ return sortedResults.slice(0, Math.max(topK, 15));
424
450
  }
425
451
  async delete(_id, _namespace) {
426
452
  console.warn("[MultiTablePostgresProvider] delete() is a no-op for multi-table mode.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
5
5
  "author": "Abhinav Alkuchi",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
15
15
  private pool!: Pool;
16
16
  private readonly dimensions: number;
17
17
  private readonly connectionString: string;
18
- private readonly tables: string[];
18
+ private tables: string[];
19
19
 
20
20
  constructor(config: VectorDBConfig) {
21
21
  super(config);
@@ -31,7 +31,7 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
31
31
  (opts.tables as string | string[]) ??
32
32
  process.env.VECTOR_DB_TABLES ??
33
33
  '';
34
-
34
+
35
35
  this.tables = typeof rawTables === 'string'
36
36
  ? rawTables.split(',').map((t) => t.trim()).filter(Boolean)
37
37
  : rawTables;
@@ -46,12 +46,43 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
46
46
 
47
47
  async initialize(): Promise<void> {
48
48
  this.pool = new Pool({ connectionString: this.connectionString });
49
- // Verify connectivity
49
+
50
+ // Dynamically discover all tables that have an 'embedding' column
50
51
  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
- );
52
+ try {
53
+ const res = await client.query(`
54
+ SELECT table_name
55
+ FROM information_schema.columns
56
+ WHERE column_name = 'embedding'
57
+ AND table_schema = 'public'
58
+ `);
59
+
60
+ const discoveredTables = res.rows.map(r => r.table_name);
61
+
62
+ if (this.tables.length === 0) {
63
+ // No static tables configured, use everything discovered
64
+ this.tables = discoveredTables;
65
+ } else {
66
+ // Filter configured tables to ensure they actually exist with embeddings
67
+ const staticTables = [...this.tables];
68
+ this.tables = staticTables.filter(t => discoveredTables.includes(t));
69
+
70
+ if (this.tables.length < staticTables.length) {
71
+ const missing = staticTables.filter(t => !discoveredTables.includes(t));
72
+ console.warn(`[MultiTablePostgresProvider] Some configured tables were skipped (missing 'embedding' column): ${missing.join(', ')}`);
73
+ }
74
+ }
75
+
76
+ if (this.tables.length === 0) {
77
+ console.warn('[MultiTablePostgresProvider] No tables with "embedding" columns found in the database.');
78
+ } else {
79
+ console.log(
80
+ `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(', ')}`
81
+ );
82
+ }
83
+ } finally {
84
+ client.release();
85
+ }
55
86
  }
56
87
 
57
88
  /**
@@ -108,11 +139,13 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
108
139
  delete rest.embedding;
109
140
 
110
141
  // 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');
142
+ // Prepend the entity type (derived from table name) to prevent cross-table confusion.
143
+ const type = table.replace(/s$/, '').toUpperCase();
144
+ const content = `[TYPE: ${type}]\n` +
145
+ Object.entries(rest)
146
+ .filter(([k, v]) => v !== null && typeof v !== 'object' && k !== 'id')
147
+ .map(([k, v]) => `${k}: ${v}`)
148
+ .join('\n');
116
149
 
117
150
  allResults.push({
118
151
  id: `${table}-${id}`,
@@ -131,12 +164,12 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
131
164
 
132
165
  // Merge and rank by score descending
133
166
  const sortedResults = allResults.sort((a, b) => b.score - a.score);
134
-
167
+
135
168
  if (sortedResults.length > 0) {
136
169
  console.log(`[MultiTablePostgresProvider] Top match from "${sortedResults[0].metadata?.source_table ?? 'unknown'}" with score ${sortedResults[0].score.toFixed(4)}`);
137
170
  }
138
171
 
139
- return sortedResults.slice(0, topK);
172
+ return sortedResults.slice(0, Math.max(topK, 15));
140
173
  }
141
174
 
142
175
  async delete(_id: string | number, _namespace?: string): Promise<void> { // eslint-disable-line @typescript-eslint/no-unused-vars