@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.
- package/dist/index.js +51 -1
- package/dist/index.js.map +5 -4
- package/dist/src/index.d.ts +2 -0
- package/dist/src/retrieval/corpus.d.ts +81 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -36099,6 +36099,53 @@ var createSyncRAGStore = (options = {}) => {
|
|
|
36099
36099
|
upsert
|
|
36100
36100
|
};
|
|
36101
36101
|
};
|
|
36102
|
+
// src/retrieval/corpus.ts
|
|
36103
|
+
var corpusTextHash = async (text) => {
|
|
36104
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text));
|
|
36105
|
+
return Array.from(new Uint8Array(digest)).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
36106
|
+
};
|
|
36107
|
+
var planRAGCorpus = async (store, owner, desired) => {
|
|
36108
|
+
const wanted = new Map;
|
|
36109
|
+
for (const doc of desired) {
|
|
36110
|
+
if (!wanted.has(doc.chunkId))
|
|
36111
|
+
wanted.set(doc.chunkId, doc);
|
|
36112
|
+
}
|
|
36113
|
+
const stored = new Map((await store.list(owner)).map((record) => [record.chunkId, record.textHash]));
|
|
36114
|
+
const embed = [];
|
|
36115
|
+
let unchanged = 0;
|
|
36116
|
+
for (const [chunkId, doc] of wanted) {
|
|
36117
|
+
const hash = await corpusTextHash(doc.text);
|
|
36118
|
+
if (stored.get(chunkId) === hash)
|
|
36119
|
+
unchanged += 1;
|
|
36120
|
+
else
|
|
36121
|
+
embed.push(doc);
|
|
36122
|
+
}
|
|
36123
|
+
return {
|
|
36124
|
+
embed,
|
|
36125
|
+
remove: [...stored.keys()].filter((chunkId) => !wanted.has(chunkId)),
|
|
36126
|
+
unchanged
|
|
36127
|
+
};
|
|
36128
|
+
};
|
|
36129
|
+
var reconcileRAGCorpus = async (store, owner, desired, apply) => {
|
|
36130
|
+
const plan = await planRAGCorpus(store, owner, desired);
|
|
36131
|
+
if (plan.remove.length > 0) {
|
|
36132
|
+
await apply.remove(plan.remove, owner);
|
|
36133
|
+
await store.forget(owner, plan.remove);
|
|
36134
|
+
}
|
|
36135
|
+
let embedded = 0;
|
|
36136
|
+
if (plan.embed.length > 0) {
|
|
36137
|
+
const outcome = await apply.embed(plan.embed, owner);
|
|
36138
|
+
const written = typeof outcome === "number" ? plan.embed.slice(0, Math.max(0, Math.min(outcome, plan.embed.length))) : plan.embed.filter((doc) => new Set(outcome).has(doc.chunkId));
|
|
36139
|
+
embedded = written.length;
|
|
36140
|
+
if (written.length > 0) {
|
|
36141
|
+
await store.remember(owner, await Promise.all(written.map(async (doc) => ({
|
|
36142
|
+
chunkId: doc.chunkId,
|
|
36143
|
+
textHash: await corpusTextHash(doc.text)
|
|
36144
|
+
}))));
|
|
36145
|
+
}
|
|
36146
|
+
}
|
|
36147
|
+
return { embedded, removed: plan.remove.length, unchanged: plan.unchanged };
|
|
36148
|
+
};
|
|
36102
36149
|
export {
|
|
36103
36150
|
xaiEmbeddings,
|
|
36104
36151
|
withEmbeddingBudget,
|
|
@@ -36123,6 +36170,7 @@ export {
|
|
|
36123
36170
|
removeRAGSource,
|
|
36124
36171
|
removeRAGEvaluationSuiteCaseHardNegative,
|
|
36125
36172
|
removeRAGEvaluationSuiteCase,
|
|
36173
|
+
reconcileRAGCorpus,
|
|
36126
36174
|
ragChat as ragPlugin,
|
|
36127
36175
|
ragChat,
|
|
36128
36176
|
querySimilarity,
|
|
@@ -36134,6 +36182,7 @@ export {
|
|
|
36134
36182
|
prepareRAGDocumentFile,
|
|
36135
36183
|
prepareRAGDocument,
|
|
36136
36184
|
prepareRAGDirectoryDocuments,
|
|
36185
|
+
planRAGCorpus,
|
|
36137
36186
|
persistRAGSearchTraceRecord,
|
|
36138
36187
|
persistRAGSearchTracePruneRun,
|
|
36139
36188
|
persistRAGRetrievalReleaseLanePolicyHistory,
|
|
@@ -36313,6 +36362,7 @@ export {
|
|
|
36313
36362
|
createEPUBExtractor,
|
|
36314
36363
|
createCohereRAGReranker,
|
|
36315
36364
|
createBuiltinArchiveExpander,
|
|
36365
|
+
corpusTextHash,
|
|
36316
36366
|
compareRAGRetrievalTraceSummaries,
|
|
36317
36367
|
compareRAGRetrievalStrategies,
|
|
36318
36368
|
compareRAGRerankers,
|
|
@@ -36396,5 +36446,5 @@ export {
|
|
|
36396
36446
|
addRAGEvaluationSuiteCase
|
|
36397
36447
|
};
|
|
36398
36448
|
|
|
36399
|
-
//# debugId=
|
|
36449
|
+
//# debugId=6D0F2872DF78972C64756E2164756E21
|
|
36400
36450
|
//# sourceMappingURL=index.js.map
|