@retrivora-ai/rag-engine 0.1.10 → 0.2.1

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
@@ -3738,13 +3762,15 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
3738
3762
  `SELECT *, 1 - (embedding <=> $1::vector) AS score
3739
3763
  FROM "${table}"
3740
3764
  ORDER BY embedding <=> $1::vector
3741
- LIMIT $2`,
3742
- [vectorLiteral, topK]
3765
+ LIMIT 50`,
3766
+ [vectorLiteral]
3743
3767
  );
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)),
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
@@ -395,13 +419,15 @@ var MultiTablePostgresProvider = class extends BaseVectorProvider {
395
419
  `SELECT *, 1 - (embedding <=> $1::vector) AS score
396
420
  FROM "${table}"
397
421
  ORDER BY embedding <=> $1::vector
398
- LIMIT $2`,
399
- [vectorLiteral, topK]
422
+ LIMIT 50`,
423
+ [vectorLiteral]
400
424
  );
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)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "0.1.10",
3
+ "version": "0.2.1",
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);
@@ -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
  /**
@@ -98,8 +129,8 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
98
129
  `SELECT *, 1 - (embedding <=> $1::vector) AS score
99
130
  FROM "${table}"
100
131
  ORDER BY embedding <=> $1::vector
101
- LIMIT $2`,
102
- [vectorLiteral, topK]
132
+ LIMIT 50`,
133
+ [vectorLiteral]
103
134
  );
104
135
 
105
136
  for (const row of result.rows) {
@@ -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}`,