@absolutejs/rag 0.5.0 → 0.6.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.
- package/dist/index.js +47 -1
- package/dist/index.js.map +5 -4
- package/dist/src/index.d.ts +2 -0
- package/dist/src/retrieval/corpus.d.ts +69 -0
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -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,69 @@
|
|
|
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
|
+
/** Embed + upsert these chunks. Returns how many were written. */
|
|
50
|
+
embed: (docs: RAGCorpusDocument[], owner: Owner) => Promise<number> | number;
|
|
51
|
+
/** Delete these chunk ids from the vector store. */
|
|
52
|
+
remove: (chunkIds: string[], owner: Owner) => Promise<void> | void;
|
|
53
|
+
};
|
|
54
|
+
export type RAGCorpusResult = {
|
|
55
|
+
embedded: number;
|
|
56
|
+
removed: number;
|
|
57
|
+
unchanged: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Bring an owner's embedded corpus in line with what they should have.
|
|
61
|
+
*
|
|
62
|
+
* Ordering is deliberate. Deletions run FIRST and their records are forgotten
|
|
63
|
+
* only after the vectors are gone: a crash mid-pass then leaves a record whose
|
|
64
|
+
* vector may already be deleted, which a later pass simply deletes again
|
|
65
|
+
* (harmless), rather than a vector whose record is gone — which nothing could
|
|
66
|
+
* ever find. Embedding records its digests after the write for the same reason,
|
|
67
|
+
* so an interrupted run never claims to have embedded something it did not.
|
|
68
|
+
*/
|
|
69
|
+
export declare const reconcileRAGCorpus: <Owner = string>(store: RAGCorpusStore<Owner>, owner: Owner, desired: RAGCorpusDocument[], apply: RAGCorpusApply<Owner>) => Promise<RAGCorpusResult>;
|