@absolutejs/rag 0.0.27 → 0.0.28
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/adapter-kit/index.js +119 -3
- package/dist/adapter-kit/index.js.map +3 -3
- package/dist/index.js +121 -3
- package/dist/index.js.map +3 -3
- package/dist/src/index.d.ts +1 -1
- package/dist/src/retrieval/collection.d.ts +3 -1
- package/dist/types/engine.d.ts +82 -0
- package/package.json +1 -1
|
@@ -20813,7 +20813,10 @@ var createRAGCollection = (options) => {
|
|
|
20813
20813
|
const embeddingProvider = resolveRAGEmbeddingProvider(options.embedding, options.store.embed, options.defaultModel);
|
|
20814
20814
|
const getExpectedDimensions = () => embeddingProvider.dimensions ?? getStatus?.()?.dimensions;
|
|
20815
20815
|
const embed = async (input, context) => {
|
|
20816
|
-
const vector = await embeddingProvider.embed(
|
|
20816
|
+
const vector = await embeddingProvider.embed({
|
|
20817
|
+
...input,
|
|
20818
|
+
kind: input.kind ?? (context === "query" ? "query" : "passage")
|
|
20819
|
+
});
|
|
20817
20820
|
validateRAGEmbeddingDimensions(vector, getExpectedDimensions(), context);
|
|
20818
20821
|
return vector;
|
|
20819
20822
|
};
|
|
@@ -21273,6 +21276,115 @@ var createRAGCollection = (options) => {
|
|
|
21273
21276
|
}))).flat();
|
|
21274
21277
|
await options.store.upsert({ chunks });
|
|
21275
21278
|
};
|
|
21279
|
+
const buildSourceUpsertInput = async (sourceId, input) => {
|
|
21280
|
+
const sharedMetadata = input.metadata;
|
|
21281
|
+
if (input.document) {
|
|
21282
|
+
return buildRAGUpsertInputFromDocuments({
|
|
21283
|
+
chunkingRegistry: input.chunkingRegistry,
|
|
21284
|
+
defaultChunking: input.chunking,
|
|
21285
|
+
documents: [
|
|
21286
|
+
{
|
|
21287
|
+
...input.document,
|
|
21288
|
+
chunking: input.document.chunking ?? input.chunking,
|
|
21289
|
+
metadata: { ...input.document.metadata ?? {}, ...sharedMetadata },
|
|
21290
|
+
source: input.document.source ?? sourceId
|
|
21291
|
+
}
|
|
21292
|
+
]
|
|
21293
|
+
});
|
|
21294
|
+
}
|
|
21295
|
+
if (input.upload) {
|
|
21296
|
+
return buildRAGUpsertInputFromUploads({
|
|
21297
|
+
chunkingRegistry: input.chunkingRegistry,
|
|
21298
|
+
extractorRegistry: input.extractorRegistry,
|
|
21299
|
+
extractors: input.extractors,
|
|
21300
|
+
uploads: [
|
|
21301
|
+
{
|
|
21302
|
+
...input.upload,
|
|
21303
|
+
chunking: input.upload.chunking ?? input.chunking,
|
|
21304
|
+
metadata: { ...input.upload.metadata ?? {}, ...sharedMetadata },
|
|
21305
|
+
source: input.upload.source ?? sourceId
|
|
21306
|
+
}
|
|
21307
|
+
]
|
|
21308
|
+
});
|
|
21309
|
+
}
|
|
21310
|
+
if (input.url) {
|
|
21311
|
+
return buildRAGUpsertInputFromURLs({
|
|
21312
|
+
chunkingRegistry: input.chunkingRegistry,
|
|
21313
|
+
extractorRegistry: input.extractorRegistry,
|
|
21314
|
+
extractors: input.extractors,
|
|
21315
|
+
urls: [
|
|
21316
|
+
{
|
|
21317
|
+
...input.url,
|
|
21318
|
+
chunking: input.url.chunking ?? input.chunking,
|
|
21319
|
+
extractorRegistry: input.url.extractorRegistry ?? input.extractorRegistry,
|
|
21320
|
+
extractors: input.url.extractors ?? input.extractors,
|
|
21321
|
+
metadata: { ...input.url.metadata ?? {}, ...sharedMetadata },
|
|
21322
|
+
source: input.url.source ?? sourceId
|
|
21323
|
+
}
|
|
21324
|
+
]
|
|
21325
|
+
});
|
|
21326
|
+
}
|
|
21327
|
+
throw new Error("ingestSource requires one of upload, url, or document to be provided.");
|
|
21328
|
+
};
|
|
21329
|
+
const removeSource = async (input) => {
|
|
21330
|
+
const sourceId = input.sourceId?.trim();
|
|
21331
|
+
if (!sourceId) {
|
|
21332
|
+
throw new Error("removeSource requires a non-empty sourceId.");
|
|
21333
|
+
}
|
|
21334
|
+
const deleteFromStore = options.store.delete;
|
|
21335
|
+
if (typeof deleteFromStore !== "function") {
|
|
21336
|
+
throw new Error("removeSource requires a store that implements delete().");
|
|
21337
|
+
}
|
|
21338
|
+
let deleted = 0;
|
|
21339
|
+
const chunkIds = input.chunkIds ?? (typeof input.chunkCount === "number" && input.chunkCount > 0 ? Array.from({ length: input.chunkCount }, (_unused, index) => `${sourceId}#${index}`) : undefined);
|
|
21340
|
+
if (chunkIds && chunkIds.length > 0) {
|
|
21341
|
+
deleted += await deleteFromStore({ chunkIds });
|
|
21342
|
+
}
|
|
21343
|
+
if (input.filterDelete !== false) {
|
|
21344
|
+
try {
|
|
21345
|
+
deleted += await deleteFromStore({ filter: { sourceId } });
|
|
21346
|
+
} catch {}
|
|
21347
|
+
}
|
|
21348
|
+
return { deleted, sourceId };
|
|
21349
|
+
};
|
|
21350
|
+
const ingestSource = async (input) => {
|
|
21351
|
+
const sourceId = input.sourceId?.trim();
|
|
21352
|
+
if (!sourceId) {
|
|
21353
|
+
throw new Error("ingestSource requires a non-empty sourceId.");
|
|
21354
|
+
}
|
|
21355
|
+
if (input.replace !== false) {
|
|
21356
|
+
await removeSource({
|
|
21357
|
+
chunkCount: input.previousChunkCount,
|
|
21358
|
+
sourceId
|
|
21359
|
+
});
|
|
21360
|
+
}
|
|
21361
|
+
const built = await buildSourceUpsertInput(sourceId, input);
|
|
21362
|
+
const embedKind = input.embedKind ?? "passage";
|
|
21363
|
+
const chunks = await Promise.all(built.chunks.map(async (chunk, index) => {
|
|
21364
|
+
const chunkId = `${sourceId}#${index}`;
|
|
21365
|
+
const embedding = chunk.embedding ?? await embed({
|
|
21366
|
+
kind: embedKind,
|
|
21367
|
+
model: options.defaultModel,
|
|
21368
|
+
text: chunk.text
|
|
21369
|
+
}, "chunk");
|
|
21370
|
+
return {
|
|
21371
|
+
...chunk,
|
|
21372
|
+
chunkId,
|
|
21373
|
+
embedding,
|
|
21374
|
+
metadata: {
|
|
21375
|
+
...chunk.metadata ?? {},
|
|
21376
|
+
sourceId
|
|
21377
|
+
},
|
|
21378
|
+
source: chunk.source ?? sourceId
|
|
21379
|
+
};
|
|
21380
|
+
}));
|
|
21381
|
+
await ingest({ chunks });
|
|
21382
|
+
return {
|
|
21383
|
+
chunkCount: chunks.length,
|
|
21384
|
+
chunkIds: chunks.map((chunk) => chunk.chunkId),
|
|
21385
|
+
sourceId
|
|
21386
|
+
};
|
|
21387
|
+
};
|
|
21276
21388
|
return {
|
|
21277
21389
|
clear: typeof options.store.clear === "function" ? () => options.store.clear?.() : undefined,
|
|
21278
21390
|
getCapabilities: typeof getCapabilities === "function" ? () => getCapabilities() : undefined,
|
|
@@ -21280,12 +21392,16 @@ var createRAGCollection = (options) => {
|
|
|
21280
21392
|
searchWithTrace,
|
|
21281
21393
|
search,
|
|
21282
21394
|
store: options.store,
|
|
21283
|
-
ingest
|
|
21395
|
+
ingest,
|
|
21396
|
+
ingestSource,
|
|
21397
|
+
removeSource
|
|
21284
21398
|
};
|
|
21285
21399
|
};
|
|
21286
21400
|
var ingestDocuments = async (collection, input) => collection.ingest(input);
|
|
21287
21401
|
var ingestRAGDocuments = async (collection, input) => collection.ingest(buildRAGUpsertInputFromDocuments(input));
|
|
21288
21402
|
var searchDocuments = async (collection, input) => collection.search(input);
|
|
21403
|
+
var ingestRAGSource = async (collection, input) => collection.ingestSource(input);
|
|
21404
|
+
var removeRAGSource = async (collection, input) => collection.removeSource(input);
|
|
21289
21405
|
// src/chat/chat.ts
|
|
21290
21406
|
import { Elysia, sse } from "elysia";
|
|
21291
21407
|
import { createMemoryStore } from "@absolutejs/ai";
|
|
@@ -31176,5 +31292,5 @@ export {
|
|
|
31176
31292
|
RAG_NATIVE_QUERY_CANDIDATE_LIMIT
|
|
31177
31293
|
};
|
|
31178
31294
|
|
|
31179
|
-
//# debugId=
|
|
31295
|
+
//# debugId=545F8D8FE97848CE64756E2164756E21
|
|
31180
31296
|
//# sourceMappingURL=index.js.map
|