@absolutejs/rag 0.1.2 → 0.1.3

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/index.js CHANGED
@@ -31555,6 +31555,54 @@ var ragChat = (config) => {
31555
31555
  // src/presentation/htmxConfig.ts
31556
31556
  var createRAGHTMXConfig = (config) => config;
31557
31557
  var createRAGHTMXWorkflowRenderConfig = (config) => config;
31558
+ // src/retrieval/embeddingBudget.ts
31559
+ var embeddingCacheKey = async (text, model, kind) => {
31560
+ const payload = `${model ?? "default"}:${kind ?? "passage"}:${text}`;
31561
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(payload));
31562
+ return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
31563
+ };
31564
+ var QUOTA_PATTERN = /RESOURCE_EXHAUSTED|token limit|quota|insufficient_quota|billing hard limit/i;
31565
+ var isEmbeddingQuotaError = (error) => {
31566
+ const message = error instanceof Error ? error.message : typeof error === "string" ? error : "";
31567
+ return QUOTA_PATTERN.test(message);
31568
+ };
31569
+ var withEmbeddingBudget = (provider, options = {}) => {
31570
+ const base = typeof provider === "function" ? { embed: provider } : provider;
31571
+ const { cache, onQuotaExhausted } = options;
31572
+ let lastError = null;
31573
+ let quotaExhaustedAt = null;
31574
+ let reused = 0;
31575
+ let embedded = 0;
31576
+ return {
31577
+ ...base,
31578
+ embed: async (input) => {
31579
+ const key = cache ? await embeddingCacheKey(input.text, input.model, input.kind) : null;
31580
+ if (key && cache) {
31581
+ const hit = await cache.get(key);
31582
+ if (hit && hit.length > 0) {
31583
+ reused += 1;
31584
+ return hit;
31585
+ }
31586
+ }
31587
+ const vector = await base.embed(input).catch((error) => {
31588
+ lastError = error instanceof Error ? error.message : String(error);
31589
+ if (isEmbeddingQuotaError(error)) {
31590
+ const first = quotaExhaustedAt === null;
31591
+ quotaExhaustedAt = new Date;
31592
+ if (first)
31593
+ onQuotaExhausted?.(error);
31594
+ }
31595
+ throw error;
31596
+ });
31597
+ lastError = null;
31598
+ embedded += 1;
31599
+ if (key && cache)
31600
+ await cache.set(key, vector);
31601
+ return vector;
31602
+ },
31603
+ health: () => ({ embedded, lastError, quotaExhaustedAt, reused })
31604
+ };
31605
+ };
31558
31606
  // src/providers/rerankerProviders.ts
31559
31607
  var rowScore = (row) => row.relevance_score ?? row.relevanceScore ?? row.score ?? 0;
31560
31608
  var applyRanking = (candidates, rows, topK) => {
@@ -35995,6 +36043,7 @@ var createSyncRAGStore = (options = {}) => {
35995
36043
  };
35996
36044
  export {
35997
36045
  xaiEmbeddings,
36046
+ withEmbeddingBudget,
35998
36047
  validateRAGEmbeddingDimensions,
35999
36048
  updateRAGEvaluationSuiteCase,
36000
36049
  summarizeRAGSearchTraceStore,
@@ -36084,6 +36133,7 @@ export {
36084
36133
  loadRAGDocumentFile,
36085
36134
  loadRAGAnswerGroundingEvaluationHistory,
36086
36135
  loadRAGAnswerGroundingCaseDifficultyHistory,
36136
+ isEmbeddingQuotaError,
36087
36137
  inspectRAGSQLiteStoreMigrations,
36088
36138
  ingestRAGSource,
36089
36139
  ingestRAGDocuments,
@@ -36097,6 +36147,7 @@ export {
36097
36147
  evaluateRAGCollection,
36098
36148
  evaluateRAGAnswerGroundingCase,
36099
36149
  evaluateRAGAnswerGrounding,
36150
+ embeddingCacheKey,
36100
36151
  deepseekEmbeddings,
36101
36152
  createVoyageRAGReranker,
36102
36153
  createTextFileExtractor,
@@ -36286,5 +36337,5 @@ export {
36286
36337
  addRAGEvaluationSuiteCase
36287
36338
  };
36288
36339
 
36289
- //# debugId=CB9ED8A4182DD67364756E2164756E21
36340
+ //# debugId=E7024598E84C592764756E2164756E21
36290
36341
  //# sourceMappingURL=index.js.map