@absolutejs/rag 0.5.0 → 0.6.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.
@@ -30,3 +30,5 @@ export type { AIHTMXRenderConfig, RAGAnswerWorkflowState, RAGBackendCapabilities
30
30
  export type { RAGJobState, RAGJobStateStore, RAGPostgresNativeDiagnostics, RAGRetrievalComparisonCandidateInput, RAGRetrievalComparisonHistoryResponse, RAGRetrievalComparisonHistoryStore, RAGRetrievalComparisonRequest, RAGRetrievalComparisonResponse, RAGRetrievalComparisonRun, RAGSearchTraceGroupHistoryResponse, RAGSearchTraceHistoryResponse, RAGSearchTracePrunePreviewResponse, RAGSearchTracePruneHistoryResponse, RAGSearchTracePruneResponse, RAGSearchTracePruneInput, RAGSearchTracePrunePreview, RAGSearchTracePruneResult, RAGSearchTracePruneHistoryStore, RAGSearchTracePruneRun, RAGSearchTraceRetentionRuntime, RAGSearchTraceRetentionSchedule, RAGSearchTraceStats, RAGSearchTraceStatsResponse, } from "../types/engine";
31
31
  export type * from "@absolutejs/ai";
32
32
  export type * from "../types/engine";
33
+ export { corpusTextHash, planRAGCorpus, reconcileRAGCorpus, } from "./retrieval/corpus";
34
+ export type { RAGCorpusApply, RAGCorpusDocument, RAGCorpusPlan, RAGCorpusRecord, RAGCorpusResult, RAGCorpusStore, } from "./retrieval/corpus";
@@ -0,0 +1,81 @@
1
+ /** One embedded chunk, as the host has it recorded. */
2
+ export type RAGCorpusRecord = {
3
+ chunkId: string;
4
+ /** Hash of the exact text that was embedded, so a content change is
5
+ * detectable without storing the text twice. */
6
+ textHash: string;
7
+ };
8
+ /** One chunk the owner should have embedded right now. */
9
+ export type RAGCorpusDocument = {
10
+ chunkId: string;
11
+ text: string;
12
+ };
13
+ /**
14
+ * Host-owned persistence for what is embedded, scoped by owner.
15
+ *
16
+ * `Owner` is whatever identifies the subject in the host's model — a profile
17
+ * id, a tenant id, a workspace key.
18
+ */
19
+ export type RAGCorpusStore<Owner = string> = {
20
+ /** Every chunk currently recorded as embedded for this owner. */
21
+ list: (owner: Owner) => Promise<RAGCorpusRecord[]> | RAGCorpusRecord[];
22
+ /** Record chunks as embedded. Must be an upsert on chunkId. */
23
+ remember: (owner: Owner, records: RAGCorpusRecord[]) => Promise<void> | void;
24
+ /** Forget chunks. Called only AFTER their vectors are gone, so a crash
25
+ * in between leaves a re-deletable record rather than an orphan. */
26
+ forget: (owner: Owner, chunkIds: string[]) => Promise<void> | void;
27
+ };
28
+ /** What a reconcile would do, without doing it. */
29
+ export type RAGCorpusPlan = {
30
+ /** New or content-changed — these cost embedding tokens. */
31
+ embed: RAGCorpusDocument[];
32
+ /** Recorded for this owner but no longer desired — delete their vectors. */
33
+ remove: string[];
34
+ /** Already embedded with identical text; skipped, and free. */
35
+ unchanged: number;
36
+ };
37
+ /** SHA-256 of the text, as `RAGCorpusRecord.textHash`. */
38
+ export declare const corpusTextHash: (text: string) => Promise<string>;
39
+ /**
40
+ * Diff desired against stored. Pure — no embedding, no deletion, no I/O beyond
41
+ * the store's `list`, so a host can show the cost of a pass before paying it.
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.
46
+ */
47
+ export declare const planRAGCorpus: <Owner = string>(store: RAGCorpusStore<Owner>, owner: Owner, desired: RAGCorpusDocument[]) => Promise<RAGCorpusPlan>;
48
+ export type RAGCorpusApply<Owner = string> = {
49
+ /**
50
+ * Embed + upsert these chunks.
51
+ *
52
+ * Return a COUNT only when the whole plan was written — the count is then
53
+ * taken at its word and every planned chunk is recorded as embedded. If the
54
+ * pass can stop early (a budget ceiling, an abort signal, a partial failure
55
+ * it chooses to swallow), return the chunk ids actually written instead.
56
+ *
57
+ * Getting this wrong is silent and permanent: a chunk recorded as embedded
58
+ * that was not will match `unchanged` on every later pass, so it is never
59
+ * embedded again until its source text happens to change. Reporting ids is
60
+ * always safe; reporting a count is a promise the caller cannot verify.
61
+ */
62
+ embed: (docs: RAGCorpusDocument[], owner: Owner) => Promise<number | readonly string[]> | number | readonly string[];
63
+ /** Delete these chunk ids from the vector store. */
64
+ remove: (chunkIds: string[], owner: Owner) => Promise<void> | void;
65
+ };
66
+ export type RAGCorpusResult = {
67
+ embedded: number;
68
+ removed: number;
69
+ unchanged: number;
70
+ };
71
+ /**
72
+ * Bring an owner's embedded corpus in line with what they should have.
73
+ *
74
+ * Ordering is deliberate. Deletions run FIRST and their records are forgotten
75
+ * only after the vectors are gone: a crash mid-pass then leaves a record whose
76
+ * vector may already be deleted, which a later pass simply deletes again
77
+ * (harmless), rather than a vector whose record is gone — which nothing could
78
+ * ever find. Embedding records its digests after the write for the same reason,
79
+ * so an interrupted run never claims to have embedded something it did not.
80
+ */
81
+ export declare const reconcileRAGCorpus: <Owner = string>(store: RAGCorpusStore<Owner>, owner: Owner, desired: RAGCorpusDocument[], apply: RAGCorpusApply<Owner>) => Promise<RAGCorpusResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/rag",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "homepage": "https://github.com/absolutejs/rag",
5
5
  "bugs": {
6
6
  "url": "https://github.com/absolutejs/rag/issues"
@@ -236,4 +236,4 @@
236
236
  ]
237
237
  }
238
238
  }
239
- }
239
+ }