@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/index.js CHANGED
@@ -21092,7 +21092,10 @@ var createRAGCollection = (options) => {
21092
21092
  const embeddingProvider = resolveRAGEmbeddingProvider(options.embedding, options.store.embed, options.defaultModel);
21093
21093
  const getExpectedDimensions = () => embeddingProvider.dimensions ?? getStatus?.()?.dimensions;
21094
21094
  const embed = async (input, context) => {
21095
- const vector = await embeddingProvider.embed(input);
21095
+ const vector = await embeddingProvider.embed({
21096
+ ...input,
21097
+ kind: input.kind ?? (context === "query" ? "query" : "passage")
21098
+ });
21096
21099
  validateRAGEmbeddingDimensions(vector, getExpectedDimensions(), context);
21097
21100
  return vector;
21098
21101
  };
@@ -21552,6 +21555,115 @@ var createRAGCollection = (options) => {
21552
21555
  }))).flat();
21553
21556
  await options.store.upsert({ chunks });
21554
21557
  };
21558
+ const buildSourceUpsertInput = async (sourceId, input) => {
21559
+ const sharedMetadata = input.metadata;
21560
+ if (input.document) {
21561
+ return buildRAGUpsertInputFromDocuments({
21562
+ chunkingRegistry: input.chunkingRegistry,
21563
+ defaultChunking: input.chunking,
21564
+ documents: [
21565
+ {
21566
+ ...input.document,
21567
+ chunking: input.document.chunking ?? input.chunking,
21568
+ metadata: { ...input.document.metadata ?? {}, ...sharedMetadata },
21569
+ source: input.document.source ?? sourceId
21570
+ }
21571
+ ]
21572
+ });
21573
+ }
21574
+ if (input.upload) {
21575
+ return buildRAGUpsertInputFromUploads({
21576
+ chunkingRegistry: input.chunkingRegistry,
21577
+ extractorRegistry: input.extractorRegistry,
21578
+ extractors: input.extractors,
21579
+ uploads: [
21580
+ {
21581
+ ...input.upload,
21582
+ chunking: input.upload.chunking ?? input.chunking,
21583
+ metadata: { ...input.upload.metadata ?? {}, ...sharedMetadata },
21584
+ source: input.upload.source ?? sourceId
21585
+ }
21586
+ ]
21587
+ });
21588
+ }
21589
+ if (input.url) {
21590
+ return buildRAGUpsertInputFromURLs({
21591
+ chunkingRegistry: input.chunkingRegistry,
21592
+ extractorRegistry: input.extractorRegistry,
21593
+ extractors: input.extractors,
21594
+ urls: [
21595
+ {
21596
+ ...input.url,
21597
+ chunking: input.url.chunking ?? input.chunking,
21598
+ extractorRegistry: input.url.extractorRegistry ?? input.extractorRegistry,
21599
+ extractors: input.url.extractors ?? input.extractors,
21600
+ metadata: { ...input.url.metadata ?? {}, ...sharedMetadata },
21601
+ source: input.url.source ?? sourceId
21602
+ }
21603
+ ]
21604
+ });
21605
+ }
21606
+ throw new Error("ingestSource requires one of upload, url, or document to be provided.");
21607
+ };
21608
+ const removeSource = async (input) => {
21609
+ const sourceId = input.sourceId?.trim();
21610
+ if (!sourceId) {
21611
+ throw new Error("removeSource requires a non-empty sourceId.");
21612
+ }
21613
+ const deleteFromStore = options.store.delete;
21614
+ if (typeof deleteFromStore !== "function") {
21615
+ throw new Error("removeSource requires a store that implements delete().");
21616
+ }
21617
+ let deleted = 0;
21618
+ const chunkIds = input.chunkIds ?? (typeof input.chunkCount === "number" && input.chunkCount > 0 ? Array.from({ length: input.chunkCount }, (_unused, index) => `${sourceId}#${index}`) : undefined);
21619
+ if (chunkIds && chunkIds.length > 0) {
21620
+ deleted += await deleteFromStore({ chunkIds });
21621
+ }
21622
+ if (input.filterDelete !== false) {
21623
+ try {
21624
+ deleted += await deleteFromStore({ filter: { sourceId } });
21625
+ } catch {}
21626
+ }
21627
+ return { deleted, sourceId };
21628
+ };
21629
+ const ingestSource = async (input) => {
21630
+ const sourceId = input.sourceId?.trim();
21631
+ if (!sourceId) {
21632
+ throw new Error("ingestSource requires a non-empty sourceId.");
21633
+ }
21634
+ if (input.replace !== false) {
21635
+ await removeSource({
21636
+ chunkCount: input.previousChunkCount,
21637
+ sourceId
21638
+ });
21639
+ }
21640
+ const built = await buildSourceUpsertInput(sourceId, input);
21641
+ const embedKind = input.embedKind ?? "passage";
21642
+ const chunks = await Promise.all(built.chunks.map(async (chunk, index) => {
21643
+ const chunkId = `${sourceId}#${index}`;
21644
+ const embedding = chunk.embedding ?? await embed({
21645
+ kind: embedKind,
21646
+ model: options.defaultModel,
21647
+ text: chunk.text
21648
+ }, "chunk");
21649
+ return {
21650
+ ...chunk,
21651
+ chunkId,
21652
+ embedding,
21653
+ metadata: {
21654
+ ...chunk.metadata ?? {},
21655
+ sourceId
21656
+ },
21657
+ source: chunk.source ?? sourceId
21658
+ };
21659
+ }));
21660
+ await ingest({ chunks });
21661
+ return {
21662
+ chunkCount: chunks.length,
21663
+ chunkIds: chunks.map((chunk) => chunk.chunkId),
21664
+ sourceId
21665
+ };
21666
+ };
21555
21667
  return {
21556
21668
  clear: typeof options.store.clear === "function" ? () => options.store.clear?.() : undefined,
21557
21669
  getCapabilities: typeof getCapabilities === "function" ? () => getCapabilities() : undefined,
@@ -21559,12 +21671,16 @@ var createRAGCollection = (options) => {
21559
21671
  searchWithTrace,
21560
21672
  search,
21561
21673
  store: options.store,
21562
- ingest
21674
+ ingest,
21675
+ ingestSource,
21676
+ removeSource
21563
21677
  };
21564
21678
  };
21565
21679
  var ingestDocuments = async (collection, input) => collection.ingest(input);
21566
21680
  var ingestRAGDocuments = async (collection, input) => collection.ingest(buildRAGUpsertInputFromDocuments(input));
21567
21681
  var searchDocuments = async (collection, input) => collection.search(input);
21682
+ var ingestRAGSource = async (collection, input) => collection.ingestSource(input);
21683
+ var removeRAGSource = async (collection, input) => collection.removeSource(input);
21568
21684
 
21569
21685
  // src/presentation/htmxWorkflowRenderers.ts
21570
21686
  var escapeHtml2 = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
@@ -35882,6 +35998,7 @@ export {
35882
35998
  resolveRAGHybridSearchOptions,
35883
35999
  resolveRAGEmbeddingProvider,
35884
36000
  reorderRAGEvaluationSuiteCases,
36001
+ removeRAGSource,
35885
36002
  removeRAGEvaluationSuiteCaseHardNegative,
35886
36003
  removeRAGEvaluationSuiteCase,
35887
36004
  ragChat as ragPlugin,
@@ -35953,6 +36070,7 @@ export {
35953
36070
  loadRAGAnswerGroundingEvaluationHistory,
35954
36071
  loadRAGAnswerGroundingCaseDifficultyHistory,
35955
36072
  inspectRAGSQLiteStoreMigrations,
36073
+ ingestRAGSource,
35956
36074
  ingestRAGDocuments,
35957
36075
  ingestDocuments,
35958
36076
  googleEmbeddings,
@@ -36153,5 +36271,5 @@ export {
36153
36271
  addRAGEvaluationSuiteCase
36154
36272
  };
36155
36273
 
36156
- //# debugId=3C1CA4A1C596290364756E2164756E21
36274
+ //# debugId=CA76BA0B8835240864756E2164756E21
36157
36275
  //# sourceMappingURL=index.js.map