@lov3kaizen/agentsea-embeddings 1.0.0 → 1.1.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.
@@ -1,4 +1,4 @@
1
- import { E as EmbeddingVector, a as EmbeddingResult } from '../embedding.types-CCgPVxt1.mjs';
1
+ import { E as EmbeddingVector, b as EmbeddingResult } from '../embedding.types-6Qr8Mgij.mjs';
2
2
 
3
3
  type CacheBackendType = 'memory' | 'redis' | 'sqlite' | 'file' | 'tiered';
4
4
  interface CachedEmbedding {
@@ -1,4 +1,4 @@
1
- import { E as EmbeddingVector, a as EmbeddingResult } from '../embedding.types-CCgPVxt1.js';
1
+ import { E as EmbeddingVector, b as EmbeddingResult } from '../embedding.types-6Qr8Mgij.js';
2
2
 
3
3
  type CacheBackendType = 'memory' | 'redis' | 'sqlite' | 'file' | 'tiered';
4
4
  interface CachedEmbedding {
@@ -620,7 +620,13 @@ var SQLiteCache = class extends BaseCache {
620
620
  `);
621
621
  updateStmt.run(Date.now(), key);
622
622
  const vectorBuffer = row.vector;
623
- const vector = Array.from(new Float32Array(vectorBuffer.buffer));
623
+ const vector = Array.from(
624
+ new Float32Array(
625
+ vectorBuffer.buffer,
626
+ vectorBuffer.byteOffset,
627
+ vectorBuffer.byteLength / Float32Array.BYTES_PER_ELEMENT
628
+ )
629
+ );
624
630
  return {
625
631
  key: row.key,
626
632
  vector,
@@ -10,7 +10,7 @@ import {
10
10
  createSQLiteCache,
11
11
  createStandardTieredCache,
12
12
  createTieredCache
13
- } from "../chunk-VPSMDBHH.mjs";
13
+ } from "../chunk-MNJPAUDC.mjs";
14
14
  import "../chunk-3KM32UQK.mjs";
15
15
  export {
16
16
  BaseCache,
@@ -0,0 +1,12 @@
1
+ // src/core/optional-import.ts
2
+ function importOptional(name) {
3
+ return import(
4
+ /* @vite-ignore */
5
+ /* webpackIgnore: true */
6
+ name
7
+ );
8
+ }
9
+
10
+ export {
11
+ importOptional
12
+ };
@@ -1,3 +1,6 @@
1
+ import {
2
+ importOptional
3
+ } from "./chunk-2TCNSTX3.mjs";
1
4
  import {
2
5
  batch,
3
6
  measureTime,
@@ -616,14 +619,18 @@ var LocalProvider = class extends BaseProvider {
616
619
  embedFn = null;
617
620
  normalize;
618
621
  batchSize;
622
+ modelPath;
623
+ /** Lazily-built ONNX extractor (only when loading from `modelPath`). */
624
+ extractorPromise;
619
625
  constructor(config) {
620
626
  super({ ...config, type: "local" });
621
627
  if (!config.embedFn && !config.modelPath) {
622
628
  throw new Error(
623
- "Either embedFn or modelPath is required for local provider"
629
+ "`embedFn` or `modelPath` (ONNX) is required for the local provider"
624
630
  );
625
631
  }
626
632
  this.embedFn = config.embedFn ?? null;
633
+ this.modelPath = config.modelPath;
627
634
  this.normalize = config.normalize ?? true;
628
635
  this.batchSize = config.batchSize ?? 32;
629
636
  this.modelInfo = {
@@ -637,10 +644,43 @@ var LocalProvider = class extends BaseProvider {
637
644
  description: "Local embedding model"
638
645
  };
639
646
  }
647
+ /**
648
+ * Lazily load the ONNX feature-extraction pipeline from `modelPath` via
649
+ * Transformers.js and adapt it into a {@link LocalEmbeddingFn}.
650
+ */
651
+ getOnnxEmbedFn() {
652
+ if (!this.extractorPromise) {
653
+ this.extractorPromise = (async () => {
654
+ let mod;
655
+ try {
656
+ mod = await importOptional("@xenova/transformers");
657
+ } catch {
658
+ throw new Error(
659
+ 'Loading local ONNX models from `modelPath` requires the "@xenova/transformers" package. Install it, or pass an `embedFn`.'
660
+ );
661
+ }
662
+ const transformers = mod;
663
+ return transformers.pipeline("feature-extraction", this.modelPath);
664
+ })();
665
+ }
666
+ return this.extractorPromise;
667
+ }
640
668
  get info() {
641
669
  return this.modelInfo;
642
670
  }
643
671
  async doEmbed(texts, options) {
672
+ if (!this.embedFn && this.modelPath) {
673
+ const extractor = await this.getOnnxEmbedFn();
674
+ this.embedFn = async (input) => {
675
+ const output = await extractor(input, {
676
+ pooling: "mean",
677
+ normalize: false
678
+ // we normalize below if configured
679
+ });
680
+ const list = output.tolist();
681
+ return Array.isArray(list[0]) ? list : [list];
682
+ };
683
+ }
644
684
  if (!this.embedFn) {
645
685
  throw new Error("No embedding function configured");
646
686
  }