@oh-my-pi/pi-mnemosyne 15.7.0 → 15.7.2
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/pi-mnemosyne",
|
|
4
|
-
"version": "15.7.
|
|
4
|
+
"version": "15.7.2",
|
|
5
5
|
"description": "Local SQLite memory engine for Oh My Pi agents",
|
|
6
6
|
"homepage": "https://omp.sh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -39,8 +39,9 @@
|
|
|
39
39
|
"fmt": "biome format --write ."
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@oh-my-pi/pi-ai": "15.7.
|
|
43
|
-
"fastembed": "2.1.0"
|
|
42
|
+
"@oh-my-pi/pi-ai": "15.7.2",
|
|
43
|
+
"fastembed": "2.1.0",
|
|
44
|
+
"onnxruntime-node": "1.24.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/bun": "^1.3.14"
|
package/src/core/embeddings.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdirSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import type { EmbeddingModel, FlagEmbedding } from "fastembed";
|
|
3
4
|
import { getMnemosyneRuntimeOptions, resolveEmbeddingProvider } from "./runtime-options";
|
|
4
5
|
|
|
5
6
|
export type Vector = number[];
|
|
@@ -24,8 +25,14 @@ type LocalModelInitOptions = {
|
|
|
24
25
|
};
|
|
25
26
|
type LocalModelInitializer = (options: LocalModelInitOptions) => Promise<LocalEmbeddingModel>;
|
|
26
27
|
|
|
28
|
+
interface FastembedRuntime {
|
|
29
|
+
EmbeddingModel: typeof EmbeddingModel;
|
|
30
|
+
FlagEmbedding: typeof FlagEmbedding;
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
const FASTEMBED_CACHE_DIR = `${process.env.HOME ?? ""}/.hermes/cache/fastembed`;
|
|
28
34
|
const QUERY_CACHE_MAX = 512;
|
|
35
|
+
const sourceRequire = createRequire(import.meta.url);
|
|
29
36
|
|
|
30
37
|
let providerOverride: EmbeddingProvider | null = null;
|
|
31
38
|
let localModelPromise: Promise<LocalEmbeddingModel> | null = null;
|
|
@@ -33,8 +40,14 @@ let localModelInitializer: LocalModelInitializer = defaultLocalModelInitializer;
|
|
|
33
40
|
let apiCallCount = 0;
|
|
34
41
|
const queryCache = new Map<string, Vector>();
|
|
35
42
|
|
|
43
|
+
function loadFastembedRuntime(): FastembedRuntime {
|
|
44
|
+
// Preload ORT 1.24 before fastembed's ORT 1.21 binding to avoid Windows DLL reuse crashes.
|
|
45
|
+
sourceRequire("onnxruntime-node");
|
|
46
|
+
return sourceRequire("fastembed") as FastembedRuntime;
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
function defaultLocalModelInitializer(options: LocalModelInitOptions): Promise<LocalEmbeddingModel> {
|
|
37
|
-
return FlagEmbedding.init(options)
|
|
50
|
+
return loadFastembedRuntime().FlagEmbedding.init(options);
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
function activeEmbeddingOptions() {
|
|
@@ -242,17 +255,21 @@ function cacheSet(key: string, value: Vector): void {
|
|
|
242
255
|
}
|
|
243
256
|
}
|
|
244
257
|
|
|
258
|
+
const KNOWN_MODEL_NAMES: Record<string, string> = {
|
|
259
|
+
"BAAI/bge-small-en-v1.5": "fast-bge-small-en-v1.5",
|
|
260
|
+
"BAAI/bge-base-en-v1.5": "fast-bge-base-en-v1.5",
|
|
261
|
+
"BAAI/bge-small-en": "fast-bge-small-en",
|
|
262
|
+
"BAAI/bge-base-en": "fast-bge-base-en",
|
|
263
|
+
"BAAI/bge-small-zh-v1.5": "fast-bge-small-zh-v1.5",
|
|
264
|
+
"intfloat/multilingual-e5-large": "fast-multilingual-e5-large",
|
|
265
|
+
"sentence-transformers/all-MiniLM-L6-v2": "fast-all-MiniLM-L6-v2",
|
|
266
|
+
};
|
|
245
267
|
function fastembedModelName(modelName: string): StandardEmbeddingModel | null {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
"BAAI/bge-small-zh-v1.5": EmbeddingModel.BGESmallZH,
|
|
252
|
-
"intfloat/multilingual-e5-large": EmbeddingModel.MLE5Large,
|
|
253
|
-
"sentence-transformers/all-MiniLM-L6-v2": EmbeddingModel.AllMiniLML6V2,
|
|
254
|
-
};
|
|
255
|
-
return known[modelName] ?? null;
|
|
268
|
+
// Fastembed `EmbeddingModel` enum string values, inlined so resolving a model name
|
|
269
|
+
// (and `available()`) never imports `fastembed` — its module eagerly loads the
|
|
270
|
+
// `onnxruntime-node` native addon, which segfaults in some runtimes.
|
|
271
|
+
const id = KNOWN_MODEL_NAMES[modelName];
|
|
272
|
+
return id === undefined ? null : (id as StandardEmbeddingModel);
|
|
256
273
|
}
|
|
257
274
|
|
|
258
275
|
async function getLocalModel(): Promise<LocalEmbeddingModel | null> {
|