@absolutejs/rag 0.6.2 → 0.7.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.
@@ -1,7 +1,7 @@
1
1
  export { ragChat, ragChat as ragPlugin } from "./chat/chat";
2
2
  export { createRAGHTMXConfig, createRAGHTMXWorkflowRenderConfig, } from "./presentation/htmxConfig";
3
3
  export { createRAGEmbeddingProvider, resolveRAGEmbeddingProvider, validateRAGEmbeddingDimensions, } from "./retrieval/embedding";
4
- export { embeddingCacheKey, isEmbeddingQuotaError, withEmbeddingBudget, type RAGBudgetedEmbedding, type RAGEmbeddingCache, type RAGEmbeddingHealth, type WithEmbeddingBudgetOptions, } from "./retrieval/embeddingBudget";
4
+ export { classifyEmbeddingError, createRAGEmbeddingError, embeddingCacheKey, isEmbeddingQuotaError, isRetryableEmbeddingError, withEmbeddingBudget, type RAGBudgetedEmbedding, type RAGEmbeddingCache, type RAGEmbeddingHealth, type RAGEmbeddingError, type RAGEmbeddingErrorKind, type WithEmbeddingBudgetOptions, } from "./retrieval/embeddingBudget";
5
5
  export { applyRAGReranking, createHeuristicRAGReranker, createRAGReranker, resolveRAGReranker, } from "./retrieval/reranking";
6
6
  export { createCohereRAGReranker, createJinaRAGReranker, createVoyageRAGReranker, } from "./providers/rerankerProviders";
7
7
  export { applyRAGQueryTransform, createHeuristicRAGQueryTransform, createRAGQueryTransform, resolveRAGQueryTransform, } from "./retrieval/queryTransforms";
@@ -40,9 +40,8 @@ export declare const corpusTextHash: (text: string) => Promise<string>;
40
40
  * Diff desired against stored. Pure — no embedding, no deletion, no I/O beyond
41
41
  * the store's `list`, so a host can show the cost of a pass before paying it.
42
42
  *
43
- * A duplicate chunkId in `desired` is a host bug that would otherwise embed the
44
- * same id twice and leave whichever landed last; the first occurrence wins and
45
- * the rest are dropped.
43
+ * Identical duplicate chunk ids are collapsed. Conflicting text for the same
44
+ * id is rejected because silently choosing either value corrupts reconciliation.
46
45
  */
47
46
  export declare const planRAGCorpus: <Owner = string>(store: RAGCorpusStore<Owner>, owner: Owner, desired: RAGCorpusDocument[]) => Promise<RAGCorpusPlan>;
48
47
  export type RAGCorpusApply<Owner = string> = {
@@ -8,10 +8,24 @@ export type RAGEmbeddingCache = {
8
8
  };
9
9
  /** Stable cache key for a piece of text under one model + input type. A
10
10
  * passage and a query embed differently, so they must not share an entry. */
11
- export declare const embeddingCacheKey: (text: string, model?: string, kind?: string) => Promise<string>;
11
+ export declare const embeddingCacheKey: (text: string, model?: string, kind?: string, identity?: string) => Promise<string>;
12
+ export type RAGEmbeddingErrorKind = "allowance" | "rate_limit" | "input" | "transient" | "unknown";
13
+ export type RAGEmbeddingError = Error & {
14
+ embeddingErrorKind: RAGEmbeddingErrorKind;
15
+ retryAfterMs?: number;
16
+ status?: number;
17
+ };
18
+ export declare const createRAGEmbeddingError: (input: {
19
+ message: string;
20
+ kind?: RAGEmbeddingErrorKind;
21
+ retryAfterMs?: number;
22
+ status?: number;
23
+ }) => RAGEmbeddingError;
24
+ export declare const classifyEmbeddingError: (error: unknown) => RAGEmbeddingErrorKind;
12
25
  /** Whether a provider error means "you are out of embedding allowance",
13
26
  * as opposed to a transient failure worth retrying. */
14
27
  export declare const isEmbeddingQuotaError: (error: unknown) => boolean;
28
+ export declare const isRetryableEmbeddingError: (error: unknown) => boolean;
15
29
  export type RAGEmbeddingHealth = {
16
30
  /** Last error message seen, cleared by the next success. */
17
31
  lastError: string | null;
@@ -21,6 +35,12 @@ export type RAGEmbeddingHealth = {
21
35
  reused: number;
22
36
  /** Embeddings actually paid for since process start. */
23
37
  embedded: number;
38
+ attempted: number;
39
+ failed: number;
40
+ inFlight: number;
41
+ cacheFailures: number;
42
+ rateLimitedAt: Date | null;
43
+ recoveredAt: Date | null;
24
44
  };
25
45
  export type RAGBudgetedEmbedding = RAGEmbeddingProvider & {
26
46
  health: () => RAGEmbeddingHealth;
@@ -30,6 +50,11 @@ export type WithEmbeddingBudgetOptions = {
30
50
  /** Notified the first time the allowance is reported spent — wire this to
31
51
  * an alert, because a degraded index is otherwise invisible. */
32
52
  onQuotaExhausted?: (error: unknown) => void;
53
+ onCacheError?: (error: unknown, operation: "get" | "set") => void;
54
+ /** Additional provider/revision identity included in every cache key. */
55
+ cacheNamespace?: string;
56
+ /** Admission hook for host-owned token budgets. Throw to reject the call. */
57
+ beforeEmbed?: (input: Parameters<RAGEmbeddingFunction>[0]) => Promise<void> | void;
33
58
  };
34
59
  /** Wrap an embedding function so repeated text is not re-embedded and quota
35
60
  * exhaustion is observable instead of silent. */
@@ -296,6 +296,8 @@ export type RAGEmbeddingProvider = {
296
296
  embed: RAGEmbeddingFunction;
297
297
  dimensions?: number;
298
298
  defaultModel?: string;
299
+ /** Stable provider/model revision identity used by embedding caches. */
300
+ cacheNamespace?: string;
299
301
  };
300
302
  export type RAGEmbeddingProviderLike = RAGEmbeddingFunction | RAGEmbeddingProvider;
301
303
  export type RAGContentFormat = "text" | "markdown" | "html" | "jsonl" | "tsv" | "csv" | "xml" | "yaml";
@@ -605,6 +607,9 @@ export type RAGHybridSearchOptions = {
605
607
  };
606
608
  export type RAGUpsertInput = {
607
609
  chunks: RAGDocumentChunk[];
610
+ signal?: AbortSignal;
611
+ embeddingConcurrency?: number;
612
+ upsertBatchSize?: number;
608
613
  };
609
614
  export type RAGDocumentIngestInput = {
610
615
  documents: RAGIngestDocument[];
@@ -4243,6 +4248,9 @@ export type RAGIngestSourceInput = {
4243
4248
  * set is removed even if the new ingest produces fewer chunks.
4244
4249
  */
4245
4250
  previousChunkCount?: number;
4251
+ signal?: AbortSignal;
4252
+ embeddingConcurrency?: number;
4253
+ upsertBatchSize?: number;
4246
4254
  };
4247
4255
  export type RAGIngestSourceResult = {
4248
4256
  sourceId: string;
@@ -35,4 +35,5 @@ export type CreateRAGEmbeddingProviderOptions = {
35
35
  embed: RAGEmbeddingFunction;
36
36
  dimensions?: number;
37
37
  defaultModel?: string;
38
+ cacheNamespace?: string;
38
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/rag",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "homepage": "https://github.com/absolutejs/rag",
5
5
  "bugs": {
6
6
  "url": "https://github.com/absolutejs/rag/issues"