@lov3kaizen/agentsea-embeddings 1.0.1 → 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.
- package/dist/caching/index.js +7 -1
- package/dist/caching/index.mjs +1 -1
- package/dist/chunk-2TCNSTX3.mjs +12 -0
- package/dist/{chunk-NBHIRTJT.mjs → chunk-5GTQFVEI.mjs} +41 -1
- package/dist/chunk-JHWMXQ56.mjs +1650 -0
- package/dist/{chunk-VPSMDBHH.mjs → chunk-MNJPAUDC.mjs} +7 -1
- package/dist/{index-DmEEUzJg.d.mts → index-DGzfvyHY.d.mts} +3 -0
- package/dist/{index-G-KgyvZT.d.ts → index-_uJcyK8e.d.ts} +3 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +812 -7
- package/dist/index.mjs +15 -14
- package/dist/providers/index.d.mts +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +47 -1
- package/dist/providers/index.mjs +2 -1
- package/dist/stores/index.d.mts +255 -1
- package/dist/stores/index.d.ts +255 -1
- package/dist/stores/index.js +794 -7
- package/dist/stores/index.mjs +20 -3
- package/package.json +6 -3
- package/dist/chunk-TER262ST.mjs +0 -877
package/dist/caching/index.js
CHANGED
|
@@ -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(
|
|
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,
|
package/dist/caching/index.mjs
CHANGED
|
@@ -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
|
-
"
|
|
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
|
}
|