@absolutejs/rag 0.0.27 → 0.0.29

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.
@@ -1,4 +1,19 @@
1
1
  // @bun
2
+ var __defProp = Object.defineProperty;
3
+ var __returnValue = (v) => v;
4
+ function __exportSetter(name, newValue) {
5
+ this[name] = __returnValue.bind(null, newValue);
6
+ }
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true,
12
+ configurable: true,
13
+ set: __exportSetter.bind(all, name)
14
+ });
15
+ };
16
+
2
17
  // src/quality/quality.ts
3
18
  import { mkdir, readFile } from "fs/promises";
4
19
 
@@ -20813,7 +20828,10 @@ var createRAGCollection = (options) => {
20813
20828
  const embeddingProvider = resolveRAGEmbeddingProvider(options.embedding, options.store.embed, options.defaultModel);
20814
20829
  const getExpectedDimensions = () => embeddingProvider.dimensions ?? getStatus?.()?.dimensions;
20815
20830
  const embed = async (input, context) => {
20816
- const vector = await embeddingProvider.embed(input);
20831
+ const vector = await embeddingProvider.embed({
20832
+ ...input,
20833
+ kind: input.kind ?? (context === "query" ? "query" : "passage")
20834
+ });
20817
20835
  validateRAGEmbeddingDimensions(vector, getExpectedDimensions(), context);
20818
20836
  return vector;
20819
20837
  };
@@ -21273,6 +21291,115 @@ var createRAGCollection = (options) => {
21273
21291
  }))).flat();
21274
21292
  await options.store.upsert({ chunks });
21275
21293
  };
21294
+ const buildSourceUpsertInput = async (sourceId, input) => {
21295
+ const sharedMetadata = input.metadata;
21296
+ if (input.document) {
21297
+ return buildRAGUpsertInputFromDocuments({
21298
+ chunkingRegistry: input.chunkingRegistry,
21299
+ defaultChunking: input.chunking,
21300
+ documents: [
21301
+ {
21302
+ ...input.document,
21303
+ chunking: input.document.chunking ?? input.chunking,
21304
+ metadata: { ...input.document.metadata ?? {}, ...sharedMetadata },
21305
+ source: input.document.source ?? sourceId
21306
+ }
21307
+ ]
21308
+ });
21309
+ }
21310
+ if (input.upload) {
21311
+ return buildRAGUpsertInputFromUploads({
21312
+ chunkingRegistry: input.chunkingRegistry,
21313
+ extractorRegistry: input.extractorRegistry,
21314
+ extractors: input.extractors,
21315
+ uploads: [
21316
+ {
21317
+ ...input.upload,
21318
+ chunking: input.upload.chunking ?? input.chunking,
21319
+ metadata: { ...input.upload.metadata ?? {}, ...sharedMetadata },
21320
+ source: input.upload.source ?? sourceId
21321
+ }
21322
+ ]
21323
+ });
21324
+ }
21325
+ if (input.url) {
21326
+ return buildRAGUpsertInputFromURLs({
21327
+ chunkingRegistry: input.chunkingRegistry,
21328
+ extractorRegistry: input.extractorRegistry,
21329
+ extractors: input.extractors,
21330
+ urls: [
21331
+ {
21332
+ ...input.url,
21333
+ chunking: input.url.chunking ?? input.chunking,
21334
+ extractorRegistry: input.url.extractorRegistry ?? input.extractorRegistry,
21335
+ extractors: input.url.extractors ?? input.extractors,
21336
+ metadata: { ...input.url.metadata ?? {}, ...sharedMetadata },
21337
+ source: input.url.source ?? sourceId
21338
+ }
21339
+ ]
21340
+ });
21341
+ }
21342
+ throw new Error("ingestSource requires one of upload, url, or document to be provided.");
21343
+ };
21344
+ const removeSource = async (input) => {
21345
+ const sourceId = input.sourceId?.trim();
21346
+ if (!sourceId) {
21347
+ throw new Error("removeSource requires a non-empty sourceId.");
21348
+ }
21349
+ const deleteFromStore = options.store.delete;
21350
+ if (typeof deleteFromStore !== "function") {
21351
+ throw new Error("removeSource requires a store that implements delete().");
21352
+ }
21353
+ let deleted = 0;
21354
+ const chunkIds = input.chunkIds ?? (typeof input.chunkCount === "number" && input.chunkCount > 0 ? Array.from({ length: input.chunkCount }, (_unused, index) => `${sourceId}#${index}`) : undefined);
21355
+ if (chunkIds && chunkIds.length > 0) {
21356
+ deleted += await deleteFromStore({ chunkIds });
21357
+ }
21358
+ if (input.filterDelete !== false) {
21359
+ try {
21360
+ deleted += await deleteFromStore({ filter: { sourceId } });
21361
+ } catch {}
21362
+ }
21363
+ return { deleted, sourceId };
21364
+ };
21365
+ const ingestSource = async (input) => {
21366
+ const sourceId = input.sourceId?.trim();
21367
+ if (!sourceId) {
21368
+ throw new Error("ingestSource requires a non-empty sourceId.");
21369
+ }
21370
+ if (input.replace !== false) {
21371
+ await removeSource({
21372
+ chunkCount: input.previousChunkCount,
21373
+ sourceId
21374
+ });
21375
+ }
21376
+ const built = await buildSourceUpsertInput(sourceId, input);
21377
+ const embedKind = input.embedKind ?? "passage";
21378
+ const chunks = await Promise.all(built.chunks.map(async (chunk, index) => {
21379
+ const chunkId = `${sourceId}#${index}`;
21380
+ const embedding = chunk.embedding ?? await embed({
21381
+ kind: embedKind,
21382
+ model: options.defaultModel,
21383
+ text: chunk.text
21384
+ }, "chunk");
21385
+ return {
21386
+ ...chunk,
21387
+ chunkId,
21388
+ embedding,
21389
+ metadata: {
21390
+ ...chunk.metadata ?? {},
21391
+ sourceId
21392
+ },
21393
+ source: chunk.source ?? sourceId
21394
+ };
21395
+ }));
21396
+ await ingest({ chunks });
21397
+ return {
21398
+ chunkCount: chunks.length,
21399
+ chunkIds: chunks.map((chunk) => chunk.chunkId),
21400
+ sourceId
21401
+ };
21402
+ };
21276
21403
  return {
21277
21404
  clear: typeof options.store.clear === "function" ? () => options.store.clear?.() : undefined,
21278
21405
  getCapabilities: typeof getCapabilities === "function" ? () => getCapabilities() : undefined,
@@ -21280,12 +21407,16 @@ var createRAGCollection = (options) => {
21280
21407
  searchWithTrace,
21281
21408
  search,
21282
21409
  store: options.store,
21283
- ingest
21410
+ ingest,
21411
+ ingestSource,
21412
+ removeSource
21284
21413
  };
21285
21414
  };
21286
21415
  var ingestDocuments = async (collection, input) => collection.ingest(input);
21287
21416
  var ingestRAGDocuments = async (collection, input) => collection.ingest(buildRAGUpsertInputFromDocuments(input));
21288
21417
  var searchDocuments = async (collection, input) => collection.search(input);
21418
+ var ingestRAGSource = async (collection, input) => collection.ingestSource(input);
21419
+ var removeRAGSource = async (collection, input) => collection.removeSource(input);
21289
21420
  // src/chat/chat.ts
21290
21421
  import { Elysia, sse } from "elysia";
21291
21422
  import { createMemoryStore } from "@absolutejs/ai";
@@ -31176,5 +31307,5 @@ export {
31176
31307
  RAG_NATIVE_QUERY_CANDIDATE_LIMIT
31177
31308
  };
31178
31309
 
31179
- //# debugId=57847B95D7296A0764756E2164756E21
31310
+ //# debugId=7D3E433ED526972764756E2164756E21
31180
31311
  //# sourceMappingURL=index.js.map