@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/index.js
CHANGED
|
@@ -36099,6 +36099,49 @@ 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
|
+
embedded = await apply.embed(plan.embed, owner);
|
|
36138
|
+
await store.remember(owner, await Promise.all(plan.embed.map(async (doc) => ({
|
|
36139
|
+
chunkId: doc.chunkId,
|
|
36140
|
+
textHash: await corpusTextHash(doc.text)
|
|
36141
|
+
}))));
|
|
36142
|
+
}
|
|
36143
|
+
return { embedded, removed: plan.remove.length, unchanged: plan.unchanged };
|
|
36144
|
+
};
|
|
36102
36145
|
export {
|
|
36103
36146
|
xaiEmbeddings,
|
|
36104
36147
|
withEmbeddingBudget,
|
|
@@ -36123,6 +36166,7 @@ export {
|
|
|
36123
36166
|
removeRAGSource,
|
|
36124
36167
|
removeRAGEvaluationSuiteCaseHardNegative,
|
|
36125
36168
|
removeRAGEvaluationSuiteCase,
|
|
36169
|
+
reconcileRAGCorpus,
|
|
36126
36170
|
ragChat as ragPlugin,
|
|
36127
36171
|
ragChat,
|
|
36128
36172
|
querySimilarity,
|
|
@@ -36134,6 +36178,7 @@ export {
|
|
|
36134
36178
|
prepareRAGDocumentFile,
|
|
36135
36179
|
prepareRAGDocument,
|
|
36136
36180
|
prepareRAGDirectoryDocuments,
|
|
36181
|
+
planRAGCorpus,
|
|
36137
36182
|
persistRAGSearchTraceRecord,
|
|
36138
36183
|
persistRAGSearchTracePruneRun,
|
|
36139
36184
|
persistRAGRetrievalReleaseLanePolicyHistory,
|
|
@@ -36313,6 +36358,7 @@ export {
|
|
|
36313
36358
|
createEPUBExtractor,
|
|
36314
36359
|
createCohereRAGReranker,
|
|
36315
36360
|
createBuiltinArchiveExpander,
|
|
36361
|
+
corpusTextHash,
|
|
36316
36362
|
compareRAGRetrievalTraceSummaries,
|
|
36317
36363
|
compareRAGRetrievalStrategies,
|
|
36318
36364
|
compareRAGRerankers,
|
|
@@ -36396,5 +36442,5 @@ export {
|
|
|
36396
36442
|
addRAGEvaluationSuiteCase
|
|
36397
36443
|
};
|
|
36398
36444
|
|
|
36399
|
-
//# debugId=
|
|
36445
|
+
//# debugId=8567BF91160369B364756E2164756E21
|
|
36400
36446
|
//# sourceMappingURL=index.js.map
|