@retrivora-ai/rag-engine 0.2.9 → 0.3.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.
@@ -47,7 +47,7 @@ interface VectorDBConfig {
47
47
  *
48
48
  * For multi-table PostgreSQL search, the following options are also supported:
49
49
  * - tables?: string[] | string
50
- * - searchFields?: string[] // optional override for which columns receive exact-match boosts
50
+ * - searchFields?: string[] | string // optional override for which columns receive exact-match boosts
51
51
  */
52
52
  options: Record<string, unknown>;
53
53
  }
@@ -47,7 +47,7 @@ interface VectorDBConfig {
47
47
  *
48
48
  * For multi-table PostgreSQL search, the following options are also supported:
49
49
  * - tables?: string[] | string
50
- * - searchFields?: string[] // optional override for which columns receive exact-match boosts
50
+ * - searchFields?: string[] | string // optional override for which columns receive exact-match boosts
51
51
  */
52
52
  options: Record<string, unknown>;
53
53
  }
@@ -316,6 +316,20 @@ var ConfigValidator = class {
316
316
  severity: "error"
317
317
  });
318
318
  }
319
+ if (opts.tables && typeof opts.tables !== "string" && !Array.isArray(opts.tables)) {
320
+ errors.push({
321
+ field: "vectorDb.options.tables",
322
+ message: "PostgreSQL tables must be a string or a string array",
323
+ severity: "error"
324
+ });
325
+ }
326
+ if (opts.searchFields && typeof opts.searchFields !== "string" && !Array.isArray(opts.searchFields)) {
327
+ errors.push({
328
+ field: "vectorDb.options.searchFields",
329
+ message: "PostgreSQL searchFields must be a string or a string array",
330
+ severity: "error"
331
+ });
332
+ }
319
333
  return errors;
320
334
  }
321
335
  /**
@@ -1560,7 +1574,7 @@ function isLikelyPromptPhrase(value) {
1560
1574
  return /^(what|which|who|where|when|why|how)\b/i.test(value.trim());
1561
1575
  }
1562
1576
  function extractQueryFieldHints(question) {
1563
- var _a, _b, _c;
1577
+ var _a, _b, _c, _d;
1564
1578
  if (!question.trim()) return [];
1565
1579
  const hints = /* @__PURE__ */ new Map();
1566
1580
  const addHint = (value, field) => {
@@ -1582,9 +1596,38 @@ function extractQueryFieldHints(question) {
1582
1596
  /\b(?:who|what)\s+(?:is|are|was|were)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
1583
1597
  /\b(?:about|for|regarding)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi
1584
1598
  ];
1599
+ const personCompanyPatterns = [
1600
+ /\bcompany(?:\s+name)?\s+(?:of|for)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
1601
+ /\b(?:which|what)\s+company\s+does\s+["']?([^"'\n?.!,]{2,120})["']?\s+work(?:\s+for|\s+at)?(?=[?.!,]|$)/gi,
1602
+ /\bwhere\s+does\s+["']?([^"'\n?.!,]{2,120})["']?\s+work(?:\s+for|\s+at)?(?=[?.!,]|$)/gi
1603
+ ];
1604
+ for (const pattern of personCompanyPatterns) {
1605
+ for (const match of question.matchAll(pattern)) {
1606
+ const name = match[1];
1607
+ if (name) addHint(name, "name");
1608
+ }
1609
+ }
1610
+ const universalPatterns = [
1611
+ { regex: /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/gi, field: "email", group: 1 },
1612
+ { regex: /(\+?\d[\d\-\.\s\(\)]{6,}\d)/g, field: "phone", group: 1 },
1613
+ { regex: /(\b\d{4}-\d{2}-\d{2}\b|\b\d{1,2}\/\d{1,2}\/\d{2,4}\b)/g, field: "date", group: 1 },
1614
+ { regex: /(\$\s?\d{1,3}(?:,\d{3})*(?:\.\d+)?)/g, field: "amount", group: 1 },
1615
+ { regex: /\b(ID|id|identifier)[: ]\s*([A-Za-z0-9\-]{3,})\b/gi, field: "id", group: 2 },
1616
+ // Generic quoted phrase / proper-noun sequences as keywords (already partially handled above)
1617
+ { regex: /"([^"]{2,120})"/g, group: 1 },
1618
+ { regex: /'([^']{2,120})'/g, group: 1 }
1619
+ ];
1620
+ for (const p of universalPatterns) {
1621
+ for (const match of question.matchAll(p.regex)) {
1622
+ const val = p.group ? (_a = match[p.group]) != null ? _a : match[0] : match[0];
1623
+ if (!val) continue;
1624
+ if (p.field) addHint(val, p.field);
1625
+ else addHint(val);
1626
+ }
1627
+ }
1585
1628
  for (const pattern of naturalQuestionPatterns) {
1586
1629
  for (const match of question.matchAll(pattern)) {
1587
- const value = (_a = match[2]) != null ? _a : match[1];
1630
+ const value = (_b = match[2]) != null ? _b : match[1];
1588
1631
  if (value) addHint(value);
1589
1632
  }
1590
1633
  }
@@ -1597,8 +1640,8 @@ function extractQueryFieldHints(question) {
1597
1640
  ];
1598
1641
  for (const pattern of fieldValuePatterns) {
1599
1642
  for (const match of question.matchAll(pattern)) {
1600
- const field = normalizeHintValue((_b = match[1]) != null ? _b : "");
1601
- const value = (_c = match[2]) != null ? _c : "";
1643
+ const field = normalizeHintValue((_c = match[1]) != null ? _c : "");
1644
+ const value = (_d = match[2]) != null ? _d : "";
1602
1645
  if (field && !isLikelyPromptPhrase(field)) {
1603
1646
  addHint(value, field);
1604
1647
  } else {
@@ -1606,7 +1649,7 @@ function extractQueryFieldHints(question) {
1606
1649
  }
1607
1650
  }
1608
1651
  }
1609
- for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){1,3}\b/g)) {
1652
+ for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,3}\b/g)) {
1610
1653
  addHint(match[0]);
1611
1654
  }
1612
1655
  return [...hints.values()];
@@ -1717,7 +1760,7 @@ var Pipeline = class {
1717
1760
  const queryVector = await this.embeddingProvider.embed(question, { taskType: "query" });
1718
1761
  const fieldHints = extractQueryFieldHints(question);
1719
1762
  const filter = buildQueryFilter(question, fieldHints);
1720
- filter.__fieldHints = fieldHints;
1763
+ filter.__entityHints = fieldHints;
1721
1764
  const rawMatches = await this.vectorDB.query(queryVector, topK, ns, filter);
1722
1765
  const sources = rawMatches.filter((m) => m.score >= scoreThreshold);
1723
1766
  const context = sources.length ? sources.map((m, i) => `[Source ${i + 1}]
@@ -1,3 +1,3 @@
1
- import '../RagConfig--ibz0b3W.mjs';
2
- export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-w8qIEFvi.mjs';
1
+ import '../RagConfig-D3Inaf9N.mjs';
2
+ export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-Ymwm-_OR.mjs';
3
3
  import 'next/server';
@@ -1,3 +1,3 @@
1
- import '../RagConfig--ibz0b3W.js';
2
- export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-Dr1HN0se.js';
1
+ import '../RagConfig-D3Inaf9N.js';
2
+ export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-BhNJQ2SS.js';
3
3
  import 'next/server';
@@ -1484,6 +1484,20 @@ var ConfigValidator = class {
1484
1484
  severity: "error"
1485
1485
  });
1486
1486
  }
1487
+ if (opts.tables && typeof opts.tables !== "string" && !Array.isArray(opts.tables)) {
1488
+ errors.push({
1489
+ field: "vectorDb.options.tables",
1490
+ message: "PostgreSQL tables must be a string or a string array",
1491
+ severity: "error"
1492
+ });
1493
+ }
1494
+ if (opts.searchFields && typeof opts.searchFields !== "string" && !Array.isArray(opts.searchFields)) {
1495
+ errors.push({
1496
+ field: "vectorDb.options.searchFields",
1497
+ message: "PostgreSQL searchFields must be a string or a string array",
1498
+ severity: "error"
1499
+ });
1500
+ }
1487
1501
  return errors;
1488
1502
  }
1489
1503
  /**
@@ -2684,7 +2698,7 @@ function isLikelyPromptPhrase(value) {
2684
2698
  return /^(what|which|who|where|when|why|how)\b/i.test(value.trim());
2685
2699
  }
2686
2700
  function extractQueryFieldHints(question) {
2687
- var _a, _b, _c;
2701
+ var _a, _b, _c, _d;
2688
2702
  if (!question.trim()) return [];
2689
2703
  const hints = /* @__PURE__ */ new Map();
2690
2704
  const addHint = (value, field) => {
@@ -2706,9 +2720,38 @@ function extractQueryFieldHints(question) {
2706
2720
  /\b(?:who|what)\s+(?:is|are|was|were)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
2707
2721
  /\b(?:about|for|regarding)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi
2708
2722
  ];
2723
+ const personCompanyPatterns = [
2724
+ /\bcompany(?:\s+name)?\s+(?:of|for)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
2725
+ /\b(?:which|what)\s+company\s+does\s+["']?([^"'\n?.!,]{2,120})["']?\s+work(?:\s+for|\s+at)?(?=[?.!,]|$)/gi,
2726
+ /\bwhere\s+does\s+["']?([^"'\n?.!,]{2,120})["']?\s+work(?:\s+for|\s+at)?(?=[?.!,]|$)/gi
2727
+ ];
2728
+ for (const pattern of personCompanyPatterns) {
2729
+ for (const match of question.matchAll(pattern)) {
2730
+ const name = match[1];
2731
+ if (name) addHint(name, "name");
2732
+ }
2733
+ }
2734
+ const universalPatterns = [
2735
+ { regex: /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/gi, field: "email", group: 1 },
2736
+ { regex: /(\+?\d[\d\-\.\s\(\)]{6,}\d)/g, field: "phone", group: 1 },
2737
+ { regex: /(\b\d{4}-\d{2}-\d{2}\b|\b\d{1,2}\/\d{1,2}\/\d{2,4}\b)/g, field: "date", group: 1 },
2738
+ { regex: /(\$\s?\d{1,3}(?:,\d{3})*(?:\.\d+)?)/g, field: "amount", group: 1 },
2739
+ { regex: /\b(ID|id|identifier)[: ]\s*([A-Za-z0-9\-]{3,})\b/gi, field: "id", group: 2 },
2740
+ // Generic quoted phrase / proper-noun sequences as keywords (already partially handled above)
2741
+ { regex: /"([^"]{2,120})"/g, group: 1 },
2742
+ { regex: /'([^']{2,120})'/g, group: 1 }
2743
+ ];
2744
+ for (const p of universalPatterns) {
2745
+ for (const match of question.matchAll(p.regex)) {
2746
+ const val = p.group ? (_a = match[p.group]) != null ? _a : match[0] : match[0];
2747
+ if (!val) continue;
2748
+ if (p.field) addHint(val, p.field);
2749
+ else addHint(val);
2750
+ }
2751
+ }
2709
2752
  for (const pattern of naturalQuestionPatterns) {
2710
2753
  for (const match of question.matchAll(pattern)) {
2711
- const value = (_a = match[2]) != null ? _a : match[1];
2754
+ const value = (_b = match[2]) != null ? _b : match[1];
2712
2755
  if (value) addHint(value);
2713
2756
  }
2714
2757
  }
@@ -2721,8 +2764,8 @@ function extractQueryFieldHints(question) {
2721
2764
  ];
2722
2765
  for (const pattern of fieldValuePatterns) {
2723
2766
  for (const match of question.matchAll(pattern)) {
2724
- const field = normalizeHintValue((_b = match[1]) != null ? _b : "");
2725
- const value = (_c = match[2]) != null ? _c : "";
2767
+ const field = normalizeHintValue((_c = match[1]) != null ? _c : "");
2768
+ const value = (_d = match[2]) != null ? _d : "";
2726
2769
  if (field && !isLikelyPromptPhrase(field)) {
2727
2770
  addHint(value, field);
2728
2771
  } else {
@@ -2730,7 +2773,7 @@ function extractQueryFieldHints(question) {
2730
2773
  }
2731
2774
  }
2732
2775
  }
2733
- for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){1,3}\b/g)) {
2776
+ for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,3}\b/g)) {
2734
2777
  addHint(match[0]);
2735
2778
  }
2736
2779
  return [...hints.values()];
@@ -2841,7 +2884,7 @@ var Pipeline = class {
2841
2884
  const queryVector = await this.embeddingProvider.embed(question, { taskType: "query" });
2842
2885
  const fieldHints = extractQueryFieldHints(question);
2843
2886
  const filter = buildQueryFilter(question, fieldHints);
2844
- filter.__fieldHints = fieldHints;
2887
+ filter.__entityHints = fieldHints;
2845
2888
  const rawMatches = await this.vectorDB.query(queryVector, topK, ns, filter);
2846
2889
  const sources = rawMatches.filter((m) => m.score >= scoreThreshold);
2847
2890
  const context = sources.length ? sources.map((m, i) => `[Source ${i + 1}]
@@ -3,7 +3,7 @@ import {
3
3
  createHealthHandler,
4
4
  createIngestHandler,
5
5
  createUploadHandler
6
- } from "../chunk-5U2DHPIX.mjs";
6
+ } from "../chunk-GT72OIOD.mjs";
7
7
  import "../chunk-EDLTMSNY.mjs";
8
8
  import "../chunk-FWCSY2DS.mjs";
9
9
  export {
@@ -1,4 +1,4 @@
1
- import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig--ibz0b3W.js';
1
+ import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig-D3Inaf9N.js';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig--ibz0b3W.mjs';
1
+ import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig-D3Inaf9N.mjs';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  /**
package/dist/index.d.mts CHANGED
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1, { ReactNode } from 'react';
3
3
  import { C as ChatMessage } from './DocumentChunker-BICIjSuG.mjs';
4
4
  export { a as ChatOptions, b as Chunk, c as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-BICIjSuG.mjs';
5
- import { V as VectorMatch, U as UIConfig } from './RagConfig--ibz0b3W.mjs';
6
- export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig--ibz0b3W.mjs';
5
+ import { V as VectorMatch, U as UIConfig } from './RagConfig-D3Inaf9N.mjs';
6
+ export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig-D3Inaf9N.mjs';
7
7
 
8
8
  interface ChatWidgetProps {
9
9
  /** Position of the floating button. Defaults to bottom-right. */
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1, { ReactNode } from 'react';
3
3
  import { C as ChatMessage } from './DocumentChunker-BICIjSuG.js';
4
4
  export { a as ChatOptions, b as Chunk, c as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-BICIjSuG.js';
5
- import { V as VectorMatch, U as UIConfig } from './RagConfig--ibz0b3W.js';
6
- export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig--ibz0b3W.js';
5
+ import { V as VectorMatch, U as UIConfig } from './RagConfig-D3Inaf9N.js';
6
+ export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig-D3Inaf9N.js';
7
7
 
8
8
  interface ChatWidgetProps {
9
9
  /** Position of the floating button. Defaults to bottom-right. */
package/dist/server.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig--ibz0b3W.mjs';
2
- export { R as RAGConfig, U as UIConfig } from './RagConfig--ibz0b3W.mjs';
1
+ import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig-D3Inaf9N.mjs';
2
+ export { R as RAGConfig, U as UIConfig } from './RagConfig-D3Inaf9N.mjs';
3
3
  import { C as ChatMessage, I as ILLMProvider, a as ChatOptions, E as EmbedOptions } from './DocumentChunker-BICIjSuG.mjs';
4
4
  export { b as Chunk, c as ChunkOptions, D as DocumentChunker } from './DocumentChunker-BICIjSuG.mjs';
5
- import { H as HealthCheckResult } from './index-w8qIEFvi.mjs';
6
- export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-w8qIEFvi.mjs';
5
+ import { H as HealthCheckResult } from './index-Ymwm-_OR.mjs';
6
+ export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-Ymwm-_OR.mjs';
7
7
  import 'next/server';
8
8
 
9
9
  /**
@@ -706,7 +706,7 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
706
706
  private readonly dimensions;
707
707
  private readonly connectionString;
708
708
  private tables;
709
- private tableSearchConfig;
709
+ private searchFields;
710
710
  constructor(config: VectorDBConfig);
711
711
  initialize(): Promise<void>;
712
712
  /**
@@ -726,8 +726,6 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
726
726
  deleteNamespace(_namespace: string): Promise<void>;
727
727
  ping(): Promise<boolean>;
728
728
  disconnect(): Promise<void>;
729
- private loadTableSearchConfig;
730
- private parseConfiguredSearchFields;
731
729
  }
732
730
 
733
731
  /**
package/dist/server.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig--ibz0b3W.js';
2
- export { R as RAGConfig, U as UIConfig } from './RagConfig--ibz0b3W.js';
1
+ import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig-D3Inaf9N.js';
2
+ export { R as RAGConfig, U as UIConfig } from './RagConfig-D3Inaf9N.js';
3
3
  import { C as ChatMessage, I as ILLMProvider, a as ChatOptions, E as EmbedOptions } from './DocumentChunker-BICIjSuG.js';
4
4
  export { b as Chunk, c as ChunkOptions, D as DocumentChunker } from './DocumentChunker-BICIjSuG.js';
5
- import { H as HealthCheckResult } from './index-Dr1HN0se.js';
6
- export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-Dr1HN0se.js';
5
+ import { H as HealthCheckResult } from './index-BhNJQ2SS.js';
6
+ export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-BhNJQ2SS.js';
7
7
  import 'next/server';
8
8
 
9
9
  /**
@@ -706,7 +706,7 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
706
706
  private readonly dimensions;
707
707
  private readonly connectionString;
708
708
  private tables;
709
- private tableSearchConfig;
709
+ private searchFields;
710
710
  constructor(config: VectorDBConfig);
711
711
  initialize(): Promise<void>;
712
712
  /**
@@ -726,8 +726,6 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
726
726
  deleteNamespace(_namespace: string): Promise<void>;
727
727
  ping(): Promise<boolean>;
728
728
  disconnect(): Promise<void>;
729
- private loadTableSearchConfig;
730
- private parseConfiguredSearchFields;
731
729
  }
732
730
 
733
731
  /**