@mrplex/embedder 0.1.2 → 0.1.3
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/README.md +6 -2
- package/embedder.mjs +13 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -19,8 +19,9 @@ embeddings.
|
|
|
19
19
|
npm install -g @mrplex/embedder
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
The model (~130 MB) auto-downloads
|
|
23
|
-
`~/.cache/
|
|
22
|
+
The model (~130 MB) auto-downloads on first run and caches under
|
|
23
|
+
`~/.cache/mrplex/embedder` (or `$XDG_CACHE_HOME/mrplex/embedder`). Override with
|
|
24
|
+
`MRPLEX_EMBEDDER_CACHE` or `--cache-dir PATH`.
|
|
24
25
|
|
|
25
26
|
**From the mrplex monorepo** (development):
|
|
26
27
|
|
|
@@ -74,6 +75,9 @@ mrplex-embedder --list-models
|
|
|
74
75
|
- `--dim N` — truncate + re-normalize each vector to `N` dims (for Matryoshka
|
|
75
76
|
models). The truncation is encoded into the reported model string
|
|
76
77
|
(`<key>@<N>`) so mrplex treats a dim change as a model change and re-embeds.
|
|
78
|
+
- `--cache-dir PATH` — where ONNX model archives are stored. Default
|
|
79
|
+
`$MRPLEX_EMBEDDER_CACHE`, else `$XDG_CACHE_HOME/mrplex/embedder` or
|
|
80
|
+
`~/.cache/mrplex/embedder`.
|
|
77
81
|
- `--stdio` — optional no-op; stdio is the default transport (one JSON line
|
|
78
82
|
per batch over stdin/stdout).
|
|
79
83
|
- `--list-models` — print supported `--model` keys and exit.
|
package/embedder.mjs
CHANGED
|
@@ -17,10 +17,18 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { readFileSync } from "node:fs";
|
|
20
|
+
import { homedir } from "node:os";
|
|
20
21
|
import { createInterface } from "node:readline";
|
|
21
22
|
import { dirname, join } from "node:path";
|
|
22
23
|
import { fileURLToPath } from "node:url";
|
|
23
24
|
|
|
25
|
+
/** Where fastembed stores downloaded ONNX model archives (not HuggingFace hub). */
|
|
26
|
+
function defaultCacheDir() {
|
|
27
|
+
if (process.env.MRPLEX_EMBEDDER_CACHE) return process.env.MRPLEX_EMBEDDER_CACHE;
|
|
28
|
+
const xdgCache = process.env.XDG_CACHE_HOME || join(homedir(), ".cache");
|
|
29
|
+
return join(xdgCache, "mrplex", "embedder");
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
const pkg = JSON.parse(
|
|
25
33
|
readFileSync(join(dirname(fileURLToPath(import.meta.url)), "package.json"), "utf8"),
|
|
26
34
|
);
|
|
@@ -38,12 +46,13 @@ function printHelp() {
|
|
|
38
46
|
Local CPU embedding provider for mrplex's --embedder hook.
|
|
39
47
|
|
|
40
48
|
Usage:
|
|
41
|
-
mrplex-embedder [--model KEY] [--dim N]
|
|
49
|
+
mrplex-embedder [--model KEY] [--dim N] [--cache-dir PATH]
|
|
42
50
|
|
|
43
51
|
Options:
|
|
44
52
|
--stdio optional; stdio is the default (one JSON line per batch over stdin/stdout)
|
|
45
53
|
--model KEY fastembed model key (default: fast-bge-small-en-v1.5)
|
|
46
54
|
--dim N truncate + re-normalize to N dims (Matryoshka models only)
|
|
55
|
+
--cache-dir PATH model download cache (default: $MRPLEX_EMBEDDER_CACHE or ~/.cache/mrplex/embedder)
|
|
47
56
|
--list-models print supported --model keys and exit
|
|
48
57
|
--help, -h show this help
|
|
49
58
|
--version, -V print version
|
|
@@ -63,6 +72,7 @@ if (has("--version") || has("-V")) {
|
|
|
63
72
|
|
|
64
73
|
const modelKey = flag("--model", "fast-bge-small-en-v1.5");
|
|
65
74
|
const truncateDim = argv.includes("--dim") ? Number.parseInt(flag("--dim", ""), 10) : null;
|
|
75
|
+
const cacheDir = argv.includes("--cache-dir") ? flag("--cache-dir", "") : defaultCacheDir();
|
|
66
76
|
|
|
67
77
|
if (truncateDim !== null && (!Number.isInteger(truncateDim) || truncateDim <= 0)) {
|
|
68
78
|
console.error(`embedder: --dim must be a positive integer (got ${flag("--dim", "")})`);
|
|
@@ -99,7 +109,7 @@ if (!model) {
|
|
|
99
109
|
}
|
|
100
110
|
|
|
101
111
|
// maxLength covers the chunker's 2000-char cap (~512 tokens); bge tops out at 512.
|
|
102
|
-
const embedder = await FlagEmbedding.init({ model, maxLength: 512 });
|
|
112
|
+
const embedder = await FlagEmbedding.init({ model, maxLength: 512, cacheDir });
|
|
103
113
|
|
|
104
114
|
/** Truncate a unit vector to `n` dims and re-normalize (Matryoshka). */
|
|
105
115
|
function truncate(vec, n) {
|
|
@@ -181,5 +191,5 @@ rl.on("line", (line) => {
|
|
|
181
191
|
});
|
|
182
192
|
|
|
183
193
|
console.error(
|
|
184
|
-
`embedder stdio model=${modelKey}${truncateDim !== null ? ` dim=${truncateDim}` : ""}`,
|
|
194
|
+
`embedder stdio model=${modelKey}${truncateDim !== null ? ` dim=${truncateDim}` : ""} cache=${cacheDir}`,
|
|
185
195
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrplex/embedder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Local CPU embedding provider for mrplex's --embedder hook (bge-small-en-v1.5 via fastembed). Isolated from mrplex core so fastembed/tar stay out of the core dependency graph.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"README.md"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
+
"pretest": "node -e \"try{require.resolve('fastembed')}catch{console.error('pretest: run npm install first');process.exit(1)}\"",
|
|
36
37
|
"start": "node embedder.mjs",
|
|
37
38
|
"test": "node --test test/*.test.mjs"
|
|
38
39
|
},
|