Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

feat(embeddings): in-process local embeddings - no key, no server

AkitaOnRailsaf965abaad5e
diff --git a/.gitignore b/.gitignore
index e6f2c031..30308091 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,3 +44,4 @@ evals/runs/
# ai-memory atomic-write backups (apply_atomic in apply_shared.rs)
*.bak-*
evals/datasets/
+evals/models/
diff --git a/CHANGELOG.md b/CHANGELOG.md
index edd9b6eb..76c4a93e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
+- `AI_MEMORY_EMBEDDING_PROVIDER=local` — in-process sentence embeddings
+ (pure-Rust candle BERT, `all-MiniLM-L6-v2`, 384-dim) with no API key
+ and no external server. The ~87 MB model is fetched once into
+ `<data_dir>/models/` with source-pinned sha256s (offline installs drop
+ the files in manually); vectors coexist with any provider's via the
+ stored `(provider, model, dim)` triple, and switching is a config
+ change. Feature-gated (`local-embeddings`, default on). The eval
+ harness gained `--embeddings local` and publishes the hybrid
+ LongMemEval row next to the zero-LLM baseline. See
+ `docs/local-embeddings.md`.
- The entity index carries ingestion-time validity windows
(bi-temporal-lite): entity links open at their page version's creation
and close when the version is superseded, backfilled for existing
diff --git a/Cargo.lock b/Cargo.lock
index 0618c42f..f372a80e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -15,7 +15,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
dependencies = [
"cfg-if",
+ "getrandom 0.3.4",
"once_cell",
+ "serde",
"version_check",
"zerocopy",
]
@@ -44,7 +46,7 @@ dependencies = [
"ai-memory-workstream",
"anyhow",
"axum",
- "base64",
+ "base64 0.22.1",
"clap",
"clap_complete",
"crossterm",
@@ -167,7 +169,10 @@ dependencies = [
"ai-memory-core",
"anyhow",
"async-trait",
- "base64",
+ "base64 0.22.1",
+ "candle-core",
+ "candle-nn",
+ "candle-transformers",
"jiff",
"regex",
"reqwest 0.12.28",
@@ -175,8 +180,10 @@ dependencies = [
"secrecy",
"serde",
"serde_json",
+ "sha2",
"tempfile",
"thiserror 2.0.18",
+ "tokenizers 0.21.4",
"tokio",
"tracing",
"uuid",
@@ -196,7 +203,7 @@ dependencies = [
"anyhow",
"async-trait",
"axum",
- "base64",
+ "base64 0.22.1",
"flate2",
"getrandom 0.3.4",
"http",
@@ -222,7 +229,7 @@ dependencies = [
"ai-memory-core",
"anyhow",
"argon2",
- "base64",
+ "base64 0.22.1",
"getrandom 0.3.4",
"jiff",
"parking_lot",
@@ -310,6 +317,12 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "allocator-api2"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
+
[[package]]
name = "android_system_properties"
version = "0.1.5"
@@ -413,7 +426,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -449,7 +462,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -525,6 +538,12 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "base64"
+version = "0.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
+
[[package]]
name = "base64"
version = "0.22.1"
@@ -546,6 +565,21 @@ dependencies = [
"serde",
]
+[[package]]
+name = "bit-set"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
+dependencies = [
+ "bit-vec",
+]
+
+[[package]]
+name = "bit-vec"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
+
[[package]]
name = "bitflags"
version = "2.11.1"
@@ -581,6 +615,26 @@ name = "bytemuck"
version = "1.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec"
+dependencies = [
+ "bytemuck_derive",
+]
+
+[[package]]
+name = "bytemuck_derive"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc0e56a716f1e132ff6bf4bdac1c944a3fcdc1cae65f70a4a2a1ac3b401d2d1f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.4",
+]
+
+[[package]]
+name = "byteorder"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
@@ -588,6 +642,76 @@ version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
+[[package]]
+name = "candle-core"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ecb245093b0f791b89d3420c3df9c6d49c60ab63ba54db896bf8a3baf486706"
+dependencies = [
+ "byteorder",
+ "float8",
+ "gemm",
+ "half",
+ "libc",
+ "libm",
+ "memmap2",
+ "num-traits",
+ "num_cpus",
+ "rand 0.9.4",
+ "rand_distr",
+ "rayon",
+ "safetensors",
+ "thiserror 2.0.18",
+ "tokenizers 0.22.2",
+ "yoke",
+ "zerocopy",
+ "zip",
+]
+
+[[package]]
+name = "candle-nn"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaa10b6ccc365b33210ce404fbf45e60d3e0bdac1004463cf1052e6ee1c1739a"
+dependencies = [
+ "candle-core",
+ "half",
+ "libc",
+ "num-traits",
+ "rayon",
+ "safetensors",
+ "serde",
+ "thiserror 2.0.18",
+]
+
+[[package]]
+name = "candle-transformers"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3bcbbf7ff00ff6fe2af22b93600195917fe90e90ff48424a140d1a926c44b1c1"
+dependencies = [
+ "byteorder",
+ "candle-core",
+ "candle-nn",
+ "fancy-regex 0.18.0",
+ "num-traits",
+ "rand 0.9.4",
+ "rayon",
+ "serde",
+ "serde_json",
+ "serde_plain",
+ "tracing",
+]
+
+[[package]]
+name = "castaway"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a"
+dependencies = [
+ "rustversion",
+]
+
[[package]]
name = "cc"
version = "1.2.62"
@@ -675,7 +799,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -700,6 +824,21 @@ dependencies = [
"memchr",
]
+[[package]]
+name = "compact_str"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9dfdd1c2274d9aa354115b09dc9a901d6c5576818cdf70d14cae2bdb47df00ab"
+dependencies = [
+ "castaway",
+ "cfg-if",
+ "itoa",
+ "rustversion",
+ "ryu",
+ "serde",
+ "static_assertions",
+]
+
[[package]]
name = "convert_case"
version = "0.10.0"
@@ -813,6 +952,12 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "crunchy"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
+
[[package]]
name = "crypto-common"
version = "0.1.7"
@@ -823,14 +968,38 @@ dependencies = [
"typenum",
]
+[[package]]
+name = "darling"
+version = "0.20.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
+dependencies = [
+ "darling_core 0.20.11",
+ "darling_macro 0.20.11",
+]
+
[[package]]
name = "darling"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d"
dependencies = [
- "darling_core",
- "darling_macro",
+ "darling_core 0.23.0",
+ "darling_macro 0.23.0",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.20.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim",
+ "syn 2.0.117",
]
[[package]]
@@ -843,7 +1012,18 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
- "syn",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.20.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
+dependencies = [
+ "darling_core 0.20.11",
+ "quote",
+ "syn 2.0.117",
]
[[package]]
@@ -852,9 +1032,18 @@ version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d"
dependencies = [
- "darling_core",
+ "darling_core 0.23.0",
"quote",
- "syn",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "dary_heap"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b1e3a325bc115f096c8b77bbf027a7c2592230e70be2d985be950d3d5e60ebe"
+dependencies = [
+ "serde",
]
[[package]]
@@ -884,6 +1073,37 @@ dependencies = [
"powerfmt",
]
+[[package]]
+name = "derive_builder"
+version = "0.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947"
+dependencies = [
+ "derive_builder_macro",
+]
+
+[[package]]
+name = "derive_builder_core"
+version = "0.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8"
+dependencies = [
+ "darling 0.20.11",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "derive_builder_macro"
+version = "0.20.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c"
+dependencies = [
+ "derive_builder_core",
+ "syn 2.0.117",
+]
+
[[package]]
name = "derive_more"
version = "2.1.1"
@@ -903,7 +1123,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -946,7 +1166,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -964,12 +1184,40 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555"
+[[package]]
+name = "dyn-stack"
+version = "0.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c4713e43e2886ba72b8271aa66c93d722116acf7a75555cce11dcde84388fe8"
+dependencies = [
+ "bytemuck",
+ "dyn-stack-macros",
+]
+
+[[package]]
+name = "dyn-stack-macros"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1d926b4d407d372f141f93bb444696142c29d32962ccbd3531117cf3aa0bfa9"
+
[[package]]
name = "either"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
+[[package]]
+name = "enum-as-inner"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
[[package]]
name = "equivalent"
version = "1.0.2"
@@ -986,6 +1234,12 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "esaxx-rs"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d817e038c30374a4bcb22f94d0a8a0e216958d4c3dcde369b1439fec4bdda6e6"
+
[[package]]
name = "fallible-iterator"
version = "0.3.0"
@@ -998,6 +1252,28 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
+[[package]]
+name = "fancy-regex"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e24cb5a94bcae1e5408b0effca5cd7172ea3c5755049c5f3af4cd283a165298"
+dependencies = [
+ "bit-set",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "fancy-regex"
+version = "0.18.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e1e1dacd0d2082dfcf1351c4bdd566bbe89a2b263235a2b50058f1e130a47277"
+dependencies = [
+ "bit-set",
+ "regex-automata",
+ "regex-syntax",
+]
+
[[package]]
name = "fastrand"
version = "2.4.1"
@@ -1053,6 +1329,18 @@ dependencies = [
"miniz_oxide",
]
+[[package]]
+name = "float8"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c2d1f04709a8ac06e8e8042875a3c466cc4832d3c1a18dbcb9dba3c6e83046bc"
+dependencies = [
+ "half",
+ "num-traits",
+ "rand 0.9.4",
+ "rand_distr",
+]
+
[[package]]
name = "fnv"
version = "1.0.7"
@@ -1065,6 +1353,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
+[[package]]
+name = "foldhash"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
+
[[package]]
name = "form_urlencoded"
version = "1.2.2"
@@ -1149,7 +1443,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -1181,6 +1475,125 @@ dependencies = [
"slab",
]
+[[package]]
+name = "gemm"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa0673db364b12263d103b68337a68fbecc541d6f6b61ba72fe438654709eacb"
+dependencies = [
+ "dyn-stack",
+ "gemm-c32",
+ "gemm-c64",
+ "gemm-common",
+ "gemm-f16",
+ "gemm-f32",
+ "gemm-f64",
+ "num-complex",
+ "num-traits",
+ "paste",
+ "raw-cpuid",
+ "seq-macro",
+]
+
+[[package]]
+name = "gemm-c32"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "086936dbdcb99e37aad81d320f98f670e53c1e55a98bee70573e83f95beb128c"
+dependencies = [
+ "dyn-stack",
+ "gemm-common",
+ "num-complex",
+ "num-traits",
+ "paste",
+ "raw-cpuid",
+ "seq-macro",
+]
+
+[[package]]
+name = "gemm-c64"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "20c8aeeeec425959bda4d9827664029ba1501a90a0d1e6228e48bef741db3a3f"
+dependencies = [
+ "dyn-stack",
+ "gemm-common",
+ "num-complex",
+ "num-traits",
+ "paste",
+ "raw-cpuid",
+ "seq-macro",
+]
+
+[[package]]
+name = "gemm-common"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88027625910cc9b1085aaaa1c4bc46bb3a36aad323452b33c25b5e4e7c8e2a3e"
+dependencies = [
+ "bytemuck",
+ "dyn-stack",
+ "half",
+ "libm",
+ "num-complex",
+ "num-traits",
+ "once_cell",
+ "paste",
+ "pulp",
+ "raw-cpuid",
+ "rayon",
+ "seq-macro",
+ "sysctl",
+]
+
+[[package]]
+name = "gemm-f16"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e3df7a55202e6cd6739d82ae3399c8e0c7e1402859b30e4cb780e61525d9486e"
+dependencies = [
+ "dyn-stack",
+ "gemm-common",
+ "gemm-f32",
+ "half",
+ "num-complex",
+ "num-traits",
+ "paste",
+ "raw-cpuid",
+ "rayon",
+ "seq-macro",
+]
+
+[[package]]
+name = "gemm-f32"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "02e0b8c9da1fbec6e3e3ab2ce6bc259ef18eb5f6f0d3e4edf54b75f9fd41a81c"
+dependencies = [
+ "dyn-stack",
+ "gemm-common",
+ "num-complex",
+ "num-traits",
+ "paste",
+ "raw-cpuid",
+ "seq-macro",
+]
+
+[[package]]
+name = "gemm-f64"
+version = "0.19.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "056131e8f2a521bfab322f804ccd652520c79700d81209e9d9275bbdecaadc6a"
+dependencies = [
+ "dyn-stack",
+ "gemm-common",
+ "num-complex",
+ "num-traits",
+ "paste",
+ "raw-cpuid",
+ "seq-macro",
+]
+
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -1263,6 +1676,21 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "half"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
+dependencies = [
+ "bytemuck",
+ "cfg-if",
+ "crunchy",
+ "num-traits",
+ "rand 0.9.4",
+ "rand_distr",
+ "zerocopy",
+]
+
[[package]]
name = "hashbrown"
version = "0.14.5"
@@ -1278,7 +1706,20 @@ version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
dependencies = [
- "foldhash",
+ "foldhash 0.1.5",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
+dependencies = [
+ "allocator-api2",
+ "equivalent",
+ "foldhash 0.2.0",
+ "serde",
+ "serde_core",
]
[[package]]
@@ -1412,7 +1853,7 @@ version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0"
dependencies = [
- "base64",
+ "base64 0.22.1",
"bytes",
"futures-channel",
"futures-util",
@@ -1618,6 +2059,15 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
+[[package]]
+name = "itertools"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
+dependencies = [
+ "either",
+]
+
[[package]]
name = "itoa"
version = "1.0.18"
@@ -1647,7 +2097,7 @@ checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -1692,7 +2142,7 @@ dependencies = [
"quote",
"rustc_version",
"simd_cesu8",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -1711,7 +2161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264"
dependencies = [
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -1872,6 +2322,22 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
+[[package]]
+name = "macro_rules_attribute"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b3ae8f6d608c795738406608304d30a2dfbdc8e58e44f7ba43236da5208ded3c"
+dependencies = [
+ "macro_rules_attribute-proc_macro",
+ "pastey",
+]
+
+[[package]]
+name = "macro_rules_attribute-proc_macro"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc04a4c58212d57930a24bf47d3fa87485264a3a054e9c10e042eb373573ad3c"
+
[[package]]
name = "matchers"
version = "0.2.0"
@@ -1893,6 +2359,16 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
+[[package]]
+name = "memmap2"
+version = "0.9.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0"
+dependencies = [
+ "libc",
+ "stable_deref_trait",
+]
+
[[package]]
name = "mime"
version = "0.3.17"
@@ -1937,6 +2413,28 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "monostate"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3341a273f6c9d5bef1908f17b7267bbab0e95c9bf69a0d4dcf8e9e1b2c76ef67"
+dependencies = [
+ "monostate-impl",
+ "serde",
+ "serde_core",
+]
+
+[[package]]
+name = "monostate-impl"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e4db6d5580af57bf992f59068d4ea26fd518574ff48d7639b255a36f9de6e7e9"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.117",
+]
+
[[package]]
name = "nom"
version = "7.1.3"
@@ -2005,6 +2503,16 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "num-complex"
+version = "0.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
+dependencies = [
+ "bytemuck",
+ "num-traits",
+]
+
[[package]]
name = "num-conv"
version = "0.2.2"
@@ -2018,6 +2526,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
+ "libm",
]
[[package]]
@@ -2042,6 +2551,28 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
+[[package]]
+name = "onig"
+version = "6.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0cc3cbf698f9438986c11a880c90a6d04b9de27575afd28bbf45b154b6c709e2"
+dependencies = [
+ "bitflags",
+ "libc",
+ "once_cell",
+ "onig_sys",
+]
+
+[[package]]
+name = "onig_sys"
+version = "69.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e68317604e77e53b85896388e1a803c1d21b74c899ec9e5e1112db90735edd7"
+dependencies = [
+ "cc",
+ "pkg-config",
+]
+
[[package]]
name = "openssl-probe"
version = "0.2.1"
@@ -2088,6 +2619,12 @@ dependencies = [
"subtle",
]
+[[package]]
+name = "paste"
+version = "1.0.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
+
[[package]]
name = "pastey"
version = "0.2.3"
@@ -2114,7 +2651,7 @@ dependencies = [
"proc-macro2",
"proc-macro2-diagnostics",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2181,7 +2718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
dependencies = [
"proc-macro2",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2201,7 +2738,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
"version_check",
"yansi",
]
@@ -2224,6 +2761,29 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
+[[package]]
+name = "pulp"
+version = "0.22.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "046aa45b989642ec2e4717c8e72d677b13edd831a4d3b6cf37d9a3e54912496a"
+dependencies = [
+ "bytemuck",
+ "cfg-if",
+ "libm",
+ "num-complex",
+ "paste",
+ "pulp-wasm-simd-flag",
+ "raw-cpuid",
+ "reborrow",
+ "version_check",
+]
+
+[[package]]
+name = "pulp-wasm-simd-flag"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d8f70e07b9c3962945a74e59ca1c511bba65b6419468acc217c457d93f3c740"
+
[[package]]
name = "quinn"
version = "0.11.9"
@@ -2355,6 +2915,25 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
+[[package]]
+name = "rand_distr"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a8615d50dcf34fa31f7ab52692afec947c4dd0ab803cc87cb3b0b4570ff7463"
+dependencies = [
+ "num-traits",
+ "rand 0.9.4",
+]
+
+[[package]]
+name = "raw-cpuid"
+version = "11.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186"
+dependencies = [
+ "bitflags",
+]
+
[[package]]
name = "rayon"
version = "1.12.0"
@@ -2365,6 +2944,17 @@ dependencies = [
"rayon-core",
]
+[[package]]
+name = "rayon-cond"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2964d0cf57a3e7a06e8183d14a8b527195c706b7983549cd5462d5aa3747438f"
+dependencies = [
+ "either",
+ "itertools",
+ "rayon",
+]
+
[[package]]
name = "rayon-core"
version = "1.13.0"
@@ -2375,6 +2965,12 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "reborrow"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "03251193000f4bd3b042892be858ee50e8b3719f2b08e5833ac4353724632430"
+
[[package]]
name = "redox_syscall"
version = "0.5.18"
@@ -2412,7 +3008,7 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2456,7 +3052,7 @@ dependencies = [
"quote",
"refinery-core",
"regex",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2494,7 +3090,7 @@ version = "0.12.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
dependencies = [
- "base64",
+ "base64 0.22.1",
"bytes",
"futures-core",
"futures-util",
@@ -2535,7 +3131,7 @@ version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3"
dependencies = [
- "base64",
+ "base64 0.22.1",
"bytes",
"futures-core",
"futures-util",
@@ -2589,7 +3185,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0810a9f717d9828f475fe1f629f4c305c8464b7f496c3a854b58d29e65f4058e"
dependencies = [
"async-trait",
- "base64",
+ "base64 0.22.1",
"bytes",
"chrono",
"futures",
@@ -2620,11 +3216,11 @@ version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aefac48c364756e97f04c0401ba3231e8607882c7c1d92da0437dc16307904d"
dependencies = [
- "darling",
+ "darling 0.23.0",
"proc-macro2",
"quote",
"serde_json",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2724,7 +3320,7 @@ dependencies = [
"security-framework",
"security-framework-sys",
"webpki-root-certs",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -2756,6 +3352,19 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
+[[package]]
+name = "safetensors"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "79b079b829cb27a1c3c374341345ed2e8b2c0c839034522cee576c140bd7f846"
+dependencies = [
+ "hashbrown 0.16.1",
+ "libc",
+ "serde",
+ "serde_json",
+ "tempfile",
+]
+
[[package]]
name = "same-file"
version = "1.0.6"
@@ -2797,7 +3406,7 @@ dependencies = [
"proc-macro2",
"quote",
"serde_derive_internals",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2845,6 +3454,12 @@ version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
+[[package]]
+name = "seq-macro"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
+
[[package]]
name = "serde"
version = "1.0.228"
@@ -2872,7 +3487,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2883,7 +3498,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -2911,6 +3526,15 @@ dependencies = [
"serde_core",
]
+[[package]]
+name = "serde_plain"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9ce1fc6db65a611022b23a0dec6975d63fb80a302cb3388835ff02c097258d50"
+dependencies = [
+ "serde",
+]
+
[[package]]
name = "serde_spanned"
version = "0.6.9"
@@ -3058,6 +3682,18 @@ dependencies = [
"windows-sys 0.61.2",
]
+[[package]]
+name = "spm_precompiled"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5851699c4033c63636f7ea4cf7b7c1f1bf06d0cc03cfb42e711de5a5c46cf326"
+dependencies = [
+ "base64 0.13.1",
+ "nom",
+ "serde",
+ "unicode-segmentation",
+]
+
[[package]]
name = "sse-stream"
version = "0.2.3"
@@ -3077,6 +3713,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
+[[package]]
+name = "static_assertions"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+
[[package]]
name = "strsim"
version = "0.11.1"
@@ -3106,6 +3748,17 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "syn"
+version = "3.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
[[package]]
name = "sync_wrapper"
version = "1.0.2"
@@ -3123,7 +3776,21 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "sysctl"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "01198a2debb237c62b6826ec7081082d951f46dbb64b0e8c7649a452230d1dfc"
+dependencies = [
+ "bitflags",
+ "byteorder",
+ "enum-as-inner",
+ "libc",
+ "thiserror 1.0.69",
+ "walkdir",
]
[[package]]
@@ -3190,7 +3857,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -3201,7 +3868,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -3269,6 +3936,72 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
+[[package]]
+name = "tokenizers"
+version = "0.21.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a620b996116a59e184c2fa2dfd8251ea34a36d0a514758c6f966386bd2e03476"
+dependencies = [
+ "ahash",
+ "aho-corasick",
+ "compact_str",
+ "dary_heap",
+ "derive_builder",
+ "esaxx-rs",
+ "fancy-regex 0.14.0",
+ "getrandom 0.3.4",
+ "itertools",
+ "log",
+ "macro_rules_attribute",
+ "monostate",
+ "paste",
+ "rand 0.9.4",
+ "rayon",
+ "rayon-cond",
+ "regex",
+ "regex-syntax",
+ "serde",
+ "serde_json",
+ "spm_precompiled",
+ "thiserror 2.0.18",
+ "unicode-normalization-alignments",
+ "unicode-segmentation",
+ "unicode_categories",
+]
+
+[[package]]
+name = "tokenizers"
+version = "0.22.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b238e22d44a15349529690fb07bd645cf58149a1b1e44d6cb5bd1641ff1a6223"
+dependencies = [
+ "ahash",
+ "aho-corasick",
+ "compact_str",
+ "dary_heap",
+ "derive_builder",
+ "esaxx-rs",
+ "getrandom 0.3.4",
+ "itertools",
+ "log",
+ "macro_rules_attribute",
+ "monostate",
+ "onig",
+ "paste",
+ "rand 0.9.4",
+ "rayon",
+ "rayon-cond",
+ "regex",
+ "regex-syntax",
+ "serde",
+ "serde_json",
+ "spm_precompiled",
+ "thiserror 2.0.18",
+ "unicode-normalization-alignments",
+ "unicode-segmentation",
+ "unicode_categories",
+]
+
[[package]]
name = "tokio"
version = "1.52.3"
@@ -3294,7 +4027,7 @@ checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -3461,7 +4194,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -3522,6 +4255,12 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
+[[package]]
+name = "typed-path"
+version = "0.12.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e"
+
[[package]]
name = "typenum"
version = "1.20.0"
@@ -3549,6 +4288,15 @@ version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
+[[package]]
+name = "unicode-normalization-alignments"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "43f613e4fa046e69818dd287fdc4bc78175ff20331479dab6e1b0f98d57062de"
+dependencies = [
+ "smallvec",
+]
+
[[package]]
name = "unicode-segmentation"
version = "1.13.3"
@@ -3561,6 +4309,12 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
+[[package]]
+name = "unicode_categories"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
+
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
@@ -3713,7 +4467,7 @@ dependencies = [
"bumpalo",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
"wasm-bindgen-shared",
]
@@ -3876,7 +4630,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -3887,7 +4641,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -4143,7 +4897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08db1edfb05d9b3c1542e521aea074442088292f00b5f28e435c714a98f85031"
dependencies = [
"assert-json-diff",
- "base64",
+ "base64 0.22.1",
"deadpool",
"futures",
"http",
@@ -4195,7 +4949,7 @@ dependencies = [
"heck",
"indexmap",
"prettyplease",
- "syn",
+ "syn 2.0.117",
"wasm-metadata",
"wit-bindgen-core",
"wit-component",
@@ -4211,7 +4965,7 @@ dependencies = [
"prettyplease",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
"wit-bindgen-core",
"wit-bindgen-rust",
]
@@ -4294,7 +5048,7 @@ checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
"synstructure",
]
@@ -4315,7 +5069,7 @@ checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
]
[[package]]
@@ -4335,7 +5089,7 @@ checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
"synstructure",
]
@@ -4375,7 +5129,19 @@ checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.117",
+]
+
+[[package]]
+name = "zip"
+version = "8.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b"
+dependencies = [
+ "crc32fast",
+ "indexmap",
+ "memchr",
+ "typed-path",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 123940b9..01c2c28a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -147,6 +147,11 @@ git2 = { version = "0.21", default-features = false, features = ["vendored-libgi
# store instead; the runtime image installs `ca-certificates`, so the server
# path keeps a populated store.
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls-native-roots", "stream"] }
+# Local (in-process, pure-Rust) embeddings — 2.0 item 5.
+candle-core = "0.11"
+candle-nn = "0.11"
+candle-transformers = "0.11"
+tokenizers = { version = "0.21", default-features = false, features = ["fancy-regex"] }
futures-util = "0.3"
async-trait = "0.1"
diff --git a/README.md b/README.md
index bbecc672..4099e3ba 100644
--- a/README.md
+++ b/README.md
@@ -347,6 +347,7 @@ diagram, crate breakdown, schema notes, and invariants.
- [`docs/okf.md`](docs/okf.md) - the wiki is natively an Open Knowledge Format (OKF v0.2) bundle; design and field mapping.
- [`docs/typed-edges.md`](docs/typed-edges.md) - typed relation edges (`causes` / `fixes` / `contradicts`) and how lint uses them.
- [`docs/temporal.md`](docs/temporal.md) - ingestion-time validity on the entity index and `as_of` time-travel queries.
+- [`docs/local-embeddings.md`](docs/local-embeddings.md) - in-process embeddings with no API key (`embedding_provider = "local"`).
- [`docs/MIGRATION-2.0.md`](docs/MIGRATION-2.0.md) - upgrading an existing store to 2.0: the backup-gated automatic migration and how to restore.
- [`docs/benchmarks/`](docs/benchmarks/README.md) - published retrieval-quality numbers with provenance, reproducible from the in-repo harness.
- [`docs/ROADMAP-2.0.md`](docs/ROADMAP-2.0.md) - the 2.0 plan.
diff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rs
index bbcd9e52..cbd41aa1 100644
--- a/crates/ai-memory-cli/src/commands/serve.rs
+++ b/crates/ai-memory-cli/src/commands/serve.rs
@@ -1704,6 +1704,21 @@ async fn configure_embedder(
let provider_name = cfg.provider.name().to_string();
let model = cfg.model.clone();
let dim = cfg.dim;
+ // Local embeddings: fetch the model once, checksum-pinned, before
+ // the loader runs (docs/local-embeddings.md). Offline installs drop
+ // the files into models/ by hand and never hit the network.
+ if cfg.provider == ai_memory_llm::EmbedderChoice::Local
+ && let Some(models_dir) = cfg.models_dir.as_deref()
+ && !ai_memory_llm::model_present(models_dir)
+ {
+ tracing::info!(
+ dir = %models_dir.display(),
+ "local embedding model not present; fetching (~87 MB, one time)"
+ );
+ ai_memory_llm::fetch_model(models_dir)
+ .await
+ .context("fetching the local embedding model (set up offline per docs/local-embeddings.md if this host has no network)")?;
+ }
let embedder = build_embedder(cfg).context("building embedder from config")?;
let mismatch = store
.reader
diff --git a/crates/ai-memory-cli/src/config.rs b/crates/ai-memory-cli/src/config.rs
index c99afd66..e61d8370 100644
--- a/crates/ai-memory-cli/src/config.rs
+++ b/crates/ai-memory-cli/src/config.rs
@@ -1148,10 +1148,11 @@ impl Config {
"voyage" => EmbedderChoice::Voyage,
"google" | "gemini" => EmbedderChoice::Google,
"openai-compat" | "openai_compat" => EmbedderChoice::OpenAiCompat,
+ "local" => EmbedderChoice::Local,
other => {
return Err(LlmError::NotConfigured(format!(
"AI_MEMORY_EMBEDDING_PROVIDER={other} not one of \
- openai|voyage|google|gemini|openai-compat"
+ openai|voyage|google|gemini|openai-compat|local"
)));
}
};
@@ -1168,6 +1169,7 @@ impl Config {
.into(),
));
}
+ EmbedderChoice::Local => ai_memory_llm::LOCAL_MODEL.to_string(),
},
};
let dim = match self.embedding_dim {
@@ -1206,6 +1208,8 @@ impl Config {
.clone()
.or_else(|| self.runtime_env.llm_api_key.clone())
.unwrap_or_else(|| SecretString::from(String::new())),
+ // In-process: no key, ever.
+ EmbedderChoice::Local => SecretString::from(String::new()),
};
let base_url = self.embedding_base_url.clone();
if provider == EmbedderChoice::OpenAiCompat && non_empty(base_url.as_deref()).is_none() {
@@ -1219,6 +1223,7 @@ impl Config {
dim,
api_key,
base_url,
+ models_dir: Some(self.data_dir.join("models")),
}))
}
diff --git a/crates/ai-memory-llm/Cargo.toml b/crates/ai-memory-llm/Cargo.toml
index 8b6d8496..a7953cb1 100644
--- a/crates/ai-memory-llm/Cargo.toml
+++ b/crates/ai-memory-llm/Cargo.toml
@@ -24,6 +24,22 @@ regex.workspace = true
base64.workspace = true
uuid.workspace = true
jiff.workspace = true
+sha2.workspace = true
+# Local in-process embeddings (2.0 item 5): pure-Rust BERT inference,
+# feature-gated so a slim build can drop the ML dependency tree.
+candle-core = { workspace = true, optional = true }
+candle-nn = { workspace = true, optional = true }
+candle-transformers = { workspace = true, optional = true }
+tokenizers = { workspace = true, optional = true }
+
+[features]
+default = ["local-embeddings"]
+local-embeddings = [
+ "dep:candle-core",
+ "dep:candle-nn",
+ "dep:candle-transformers",
+ "dep:tokenizers",
+]
[dev-dependencies]
tokio = { workspace = true }
diff --git a/crates/ai-memory-llm/src/embedding.rs b/crates/ai-memory-llm/src/embedding.rs
index 2b34c89f..e2a8f4f5 100644
--- a/crates/ai-memory-llm/src/embedding.rs
+++ b/crates/ai-memory-llm/src/embedding.rs
@@ -9,8 +9,9 @@
//! embedding so integration tests can demonstrate semantic
//! retrieval without an API key.
//!
-//! Future: a local `ort` + `bge-small-en-v1.5` embedder. The trait is
-//! generic so dropping it in later doesn't touch consumers.
+//! * [`LocalEmbedder`](crate::local::LocalEmbedder) — in-process
+//! pure-Rust BERT (`all-MiniLM-L6-v2`), no key and no server; see
+//! `docs/local-embeddings.md`.
use std::time::Duration;
diff --git a/crates/ai-memory-llm/src/factory.rs b/crates/ai-memory-llm/src/factory.rs
index 89c1511d..5b181b5e 100644
--- a/crates/ai-memory-llm/src/factory.rs
+++ b/crates/ai-memory-llm/src/factory.rs
@@ -117,6 +117,12 @@ pub enum EmbedderChoice {
/// OpenAI-compatible embeddings endpoint (Ollama / LM Studio /
/// vLLM). Keyless-capable; base URL, model, and dim are required.
OpenAiCompat,
+ /// In-process pure-Rust embeddings (all-MiniLM-L6-v2, 384-dim) —
+ /// no API key, no server. Requires the model files under
+ /// `<data_dir>/models/` (fetched at serve startup or dropped in
+ /// manually; docs/local-embeddings.md).
+ #[cfg(feature = "local-embeddings")]
+ Local,
}
impl EmbedderChoice {
@@ -129,6 +135,8 @@ impl EmbedderChoice {
Self::Voyage => "voyage",
Self::Google => "google",
Self::OpenAiCompat => "openai-compat",
+ #[cfg(feature = "local-embeddings")]
+ Self::Local => "local",
}
}
}
@@ -148,6 +156,8 @@ pub struct EmbedderConfig {
pub api_key: SecretString,
/// Optional base URL override. Required for openai-compat.
pub base_url: Option<String>,
+ /// `<data_dir>/models/` root, required by the `local` provider.
+ pub models_dir: Option<std::path::PathBuf>,
}
/// Construct an `Arc<dyn Embedder>` from the config.
@@ -195,6 +205,13 @@ pub fn build_embedder(config: EmbedderConfig) -> LlmResult<Arc<dyn Embedder>> {
config.dim,
)?)
}
+ #[cfg(feature = "local-embeddings")]
+ EmbedderChoice::Local => {
+ let models_dir = config.models_dir.ok_or_else(|| {
+ LlmError::NotConfigured("local embeddings need the data dir's models/ root".into())
+ })?;
+ Arc::new(crate::local::LocalEmbedder::load(&models_dir)?)
+ }
};
Ok(arc)
}
@@ -218,6 +235,8 @@ pub fn try_default_embedding_dim(provider: EmbedderChoice, model: &str) -> Optio
(EmbedderChoice::OpenAi, _) => Some(1536),
(EmbedderChoice::Voyage, "voyage-3-large") => Some(1024),
(EmbedderChoice::Voyage, _) => Some(1024),
+ #[cfg(feature = "local-embeddings")]
+ (EmbedderChoice::Local, _) => Some(crate::local::LOCAL_DIM),
(EmbedderChoice::Google, "gemini-embedding-2") => Some(768),
(EmbedderChoice::Google, "gemini-embedding-001") => Some(768),
(EmbedderChoice::Google, _) => Some(768),
diff --git a/crates/ai-memory-llm/src/lib.rs b/crates/ai-memory-llm/src/lib.rs
index 2166a9e0..ef9d88e0 100644
--- a/crates/ai-memory-llm/src/lib.rs
+++ b/crates/ai-memory-llm/src/lib.rs
@@ -45,6 +45,8 @@ pub mod factory;
pub mod gemini;
pub mod google;
pub mod health;
+#[cfg(feature = "local-embeddings")]
+pub mod local;
pub mod oidc;
pub mod openai;
pub mod openai_compat;
@@ -79,6 +81,8 @@ pub use google::{DEFAULT_MODEL as GOOGLE_DEFAULT_EMBED_MODEL, GoogleEmbedder};
pub use health::{
ProviderHealth, ProviderHealthSnapshot, ProviderHealthStatus, ProviderRoleHealthSnapshot,
};
+#[cfg(feature = "local-embeddings")]
+pub use local::{LOCAL_DIM, LOCAL_MODEL, LocalEmbedder, fetch_model, model_present};
pub use oidc::{
DeviceAuthorizationResponse, OIDC_DEFAULT_SCOPE, OidcDiscovery, OidcExtras, OidcToken,
OidcTokenResponse, PollOutcome, discover, poll_token_once, refresh_access_token,
diff --git a/crates/ai-memory-llm/src/local.rs b/crates/ai-memory-llm/src/local.rs
new file mode 100644
index 00000000..255e5509
--- /dev/null
+++ b/crates/ai-memory-llm/src/local.rs
@@ -0,0 +1,315 @@
+//! Local in-process embeddings (2.0 item 5, `docs/local-embeddings.md`).
+//!
+//! Pure-Rust BERT inference via candle — no API key, no server, no
+//! native onnxruntime. The model (`all-MiniLM-L6-v2`, 384-dim, the
+//! sentence-transformers workhorse the comparable memory servers ship)
+//! is NOT bundled in the binary: ~87 MB of safetensors is fetched once
+//! into `<data_dir>/models/` with pinned sha256s, or dropped there by
+//! hand for offline installs.
+
+use std::path::{Path, PathBuf};
+use std::sync::Arc;
+
+use candle_core::{Device, Tensor};
+use candle_nn::VarBuilder;
+use candle_transformers::models::bert::{BertModel, Config as BertConfig, DTYPE};
+use sha2::{Digest, Sha256};
+use tokenizers::Tokenizer;
+
+use crate::embedding::Embedder;
+use crate::error::{LlmError, LlmResult};
+
+/// Model identity as stored on `page_embeddings` rows.
+pub const LOCAL_MODEL: &str = "all-MiniLM-L6-v2";
+/// Output dimensionality of [`LOCAL_MODEL`].
+pub const LOCAL_DIM: u32 = 384;
+/// Token cap per input (the model's positional limit is 512; sentence
+/// embeddings degrade past ~256 anyway, matching sentence-transformers'
+/// own default).
+const MAX_TOKENS: usize = 512;
+
+/// The three files that make up the model, with sha256s pinned on
+/// 2026-09-01. A drifted upstream file fails loudly instead of silently
+/// changing every vector.
+pub const MODEL_FILES: [(&str, &str); 3] = [
+ (
+ "model.safetensors",
+ "53aa51172d142c89d9012cce15ae4d6cc0ca6895895114379cacb4fab128d9db",
+ ),
+ (
+ "tokenizer.json",
+ "be50c3628f2bf5bb5e3a7f17b1f74611b2561a3a27eeab05e5aa30f411572037",
+ ),
+ (
+ "config.json",
+ "953f9c0d463486b10a6871cc2fd59f223b2c70184f49815e7efbcab5d8908b41",
+ ),
+];
+
+const MODEL_BASE_URL: &str =
+ "https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main";
+
+/// Directory the model lives in under the data dir's `models/` root.
+#[must_use]
+pub fn model_dir(models_root: &Path) -> PathBuf {
+ models_root.join(LOCAL_MODEL)
+}
+
+/// Whether every model file is present (checksums are verified at load,
+/// not here — presence is the cheap serve-startup probe).
+#[must_use]
+pub fn model_present(models_root: &Path) -> bool {
+ let dir = model_dir(models_root);
+ MODEL_FILES.iter().all(|(name, _)| dir.join(name).exists())
+}
+
+/// Download the model files with pinned checksums (atomic: tmp +
+/// verify + rename). Skips files already present and valid; a present
+/// file with a wrong checksum is replaced.
+///
+/// # Errors
+/// Network failures, checksum mismatches, and IO errors — the caller
+/// (serve startup / embed) surfaces them with the offline instructions.
+pub async fn fetch_model(models_root: &Path) -> LlmResult<()> {
+ let dir = model_dir(models_root);
+ std::fs::create_dir_all(&dir).map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ let client = reqwest::Client::new();
+ for (name, pinned) in MODEL_FILES {
+ let dest = dir.join(name);
+ if let Ok(existing) = std::fs::read(&dest)
+ && hex(&Sha256::digest(&existing)) == pinned
+ {
+ continue;
+ }
+ tracing::info!(file = name, "fetching local embedding model file");
+ let bytes = client
+ .get(format!("{MODEL_BASE_URL}/{name}"))
+ .send()
+ .await?
+ .error_for_status()?
+ .bytes()
+ .await?;
+ let digest = hex(&Sha256::digest(&bytes));
+ if digest != pinned {
+ return Err(LlmError::UnexpectedShape(format!(
+ "downloaded {name} sha256 {digest} does not match pin {pinned}; \
+ refusing to install an unverified model"
+ )));
+ }
+ let tmp = dest.with_extension("part");
+ std::fs::write(&tmp, &bytes).map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ std::fs::rename(&tmp, &dest).map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ }
+ Ok(())
+}
+
+fn hex(bytes: &[u8]) -> String {
+ bytes.iter().map(|b| format!("{b:02x}")).collect()
+}
+
+/// In-process sentence embedder. Cheap to clone-share via `Arc`; the
+/// forward pass runs on `spawn_blocking` so the async runtime never
+/// blocks on CPU inference.
+pub struct LocalEmbedder {
+ inner: Arc<Inner>,
+}
+
+struct Inner {
+ model: BertModel,
+ tokenizer: Tokenizer,
+ device: Device,
+}
+
+impl LocalEmbedder {
+ /// Load the model from `<models_root>/all-MiniLM-L6-v2/`, verifying
+ /// every file against its pinned sha256 first — a tampered or torn
+ /// model must not silently produce garbage vectors.
+ ///
+ /// # Errors
+ /// Missing files (with the fetch/offline instructions), checksum
+ /// mismatches, and model-load failures.
+ pub fn load(models_root: &Path) -> LlmResult<Self> {
+ let dir = model_dir(models_root);
+ for (name, pinned) in MODEL_FILES {
+ let path = dir.join(name);
+ let bytes = std::fs::read(&path).map_err(|_| {
+ LlmError::NotConfigured(format!(
+ "local embedding model file missing: {}. Start the server once \
+ with network access to fetch it, or download \
+ {MODEL_BASE_URL}/{name} manually into {}",
+ path.display(),
+ dir.display(),
+ ))
+ })?;
+ let digest = hex(&Sha256::digest(&bytes));
+ if digest != pinned {
+ return Err(LlmError::NotConfigured(format!(
+ "local embedding model file {} sha256 {digest} does not match \
+ the pinned {pinned}; delete it and re-fetch",
+ path.display(),
+ )));
+ }
+ }
+
+ let device = Device::Cpu;
+ let config: BertConfig = serde_json::from_str(
+ &std::fs::read_to_string(dir.join("config.json"))
+ .map_err(|e| LlmError::UnexpectedShape(e.to_string()))?,
+ )
+ .map_err(|e| LlmError::UnexpectedShape(format!("parsing model config: {e}")))?;
+ let mut tokenizer = Tokenizer::from_file(dir.join("tokenizer.json"))
+ .map_err(|e| LlmError::UnexpectedShape(format!("loading tokenizer: {e}")))?;
+ tokenizer
+ .with_truncation(Some(tokenizers::TruncationParams {
+ max_length: MAX_TOKENS,
+ ..Default::default()
+ }))
+ .map_err(|e| LlmError::UnexpectedShape(format!("configuring truncation: {e}")))?;
+ // Buffered (safe) loader: ~87 MB read once into memory — the
+ // workspace forbids unsafe, and the mmap variant is `unsafe`.
+ let weights = std::fs::read(dir.join("model.safetensors"))
+ .map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ let vb = VarBuilder::from_buffered_safetensors(weights, DTYPE, &device)
+ .map_err(|e| LlmError::UnexpectedShape(format!("loading model weights: {e}")))?;
+ let model = BertModel::load(vb, &config)
+ .map_err(|e| LlmError::UnexpectedShape(format!("building BERT model: {e}")))?;
+ Ok(Self {
+ inner: Arc::new(Inner {
+ model,
+ tokenizer,
+ device,
+ }),
+ })
+ }
+
+ fn embed_blocking(inner: &Inner, text: &str) -> LlmResult<Vec<f32>> {
+ let encoding = inner
+ .tokenizer
+ .encode(text, true)
+ .map_err(|e| LlmError::UnexpectedShape(format!("tokenizing: {e}")))?;
+ let ids = encoding.get_ids();
+ if ids.is_empty() {
+ return Err(LlmError::UnexpectedShape("empty tokenization".into()));
+ }
+ let input_ids = Tensor::new(ids, &inner.device)
+ .and_then(|t| t.unsqueeze(0))
+ .map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ let token_type_ids = input_ids
+ .zeros_like()
+ .map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ let hidden = inner
+ .model
+ .forward(&input_ids, &token_type_ids, None)
+ .map_err(|e| LlmError::UnexpectedShape(format!("forward pass: {e}")))?;
+ // Mean pooling over the token axis (no padding in a single
+ // unbatched input, so a plain mean is the masked mean), then L2
+ // normalise — the sentence-transformers contract, and the unit
+ // vector the Embedder trait promises.
+ let pooled = hidden
+ .mean(1)
+ .and_then(|t| t.squeeze(0))
+ .map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ let vec: Vec<f32> = pooled
+ .to_vec1()
+ .map_err(|e| LlmError::UnexpectedShape(e.to_string()))?;
+ let norm = vec.iter().map(|v| v * v).sum::<f32>().sqrt();
+ if norm == 0.0 || !norm.is_finite() {
+ return Err(LlmError::UnexpectedShape(
+ "degenerate embedding norm".into(),
+ ));
+ }
+ Ok(vec.into_iter().map(|v| v / norm).collect())
+ }
+}
+
+#[async_trait::async_trait]
+impl Embedder for LocalEmbedder {
+ fn provider(&self) -> &'static str {
+ "local"
+ }
+
+ fn model(&self) -> &str {
+ LOCAL_MODEL
+ }
+
+ fn dim(&self) -> u32 {
+ LOCAL_DIM
+ }
+
+ async fn embed(&self, text: &str) -> LlmResult<Vec<f32>> {
+ let inner = Arc::clone(&self.inner);
+ let text = crate::text::truncate_for_embedding(text, MAX_TOKENS * 4);
+ tokio::task::spawn_blocking(move || Self::embed_blocking(&inner, &text))
+ .await
+ .map_err(|e| LlmError::UnexpectedShape(format!("embedding task: {e}")))?
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn model_presence_probe_requires_all_three_files() {
+ let tmp = tempfile::tempdir().unwrap();
+ assert!(!model_present(tmp.path()));
+ let dir = model_dir(tmp.path());
+ std::fs::create_dir_all(&dir).unwrap();
+ for (name, _) in &MODEL_FILES[..2] {
+ std::fs::write(dir.join(name), b"x").unwrap();
+ }
+ assert!(!model_present(tmp.path()), "two of three is not present");
+ std::fs::write(dir.join(MODEL_FILES[2].0), b"x").unwrap();
+ assert!(model_present(tmp.path()));
+ }
+
+ #[test]
+ fn load_refuses_tampered_files() {
+ let tmp = tempfile::tempdir().unwrap();
+ let dir = model_dir(tmp.path());
+ std::fs::create_dir_all(&dir).unwrap();
+ for (name, _) in MODEL_FILES {
+ std::fs::write(dir.join(name), b"not the real file").unwrap();
+ }
+ let err = match LocalEmbedder::load(tmp.path()) {
+ Err(e) => e.to_string(),
+ Ok(_) => panic!("tampered files must not load"),
+ };
+ assert!(err.contains("does not match"), "{err}");
+ }
+
+ #[test]
+ fn load_names_the_missing_file_and_the_fix() {
+ let tmp = tempfile::tempdir().unwrap();
+ let err = match LocalEmbedder::load(tmp.path()) {
+ Err(e) => e.to_string(),
+ Ok(_) => panic!("missing files must not load"),
+ };
+ assert!(err.contains("model.safetensors"), "{err}");
+ assert!(err.contains("manually"), "{err}");
+ }
+
+ /// Full inference against the real fetched model: `#[ignore]`d like
+ /// the eval smoke (needs ~87 MB in the workspace models dir; run
+ /// `cargo test -p ai-memory-llm --lib local -- --ignored` after a
+ /// fetch).
+ #[tokio::test]
+ #[ignore = "needs the fetched all-MiniLM-L6-v2 model files"]
+ async fn real_model_produces_unit_vectors_with_semantic_order() {
+ let root = std::env::var("AI_MEMORY_TEST_MODELS_DIR")
+ .expect("set AI_MEMORY_TEST_MODELS_DIR to a dir containing all-MiniLM-L6-v2");
+ let embedder = LocalEmbedder::load(Path::new(&root)).unwrap();
+ assert_eq!(embedder.dim(), 384);
+ let db = embedder.embed("the database write path").await.unwrap();
+ assert_eq!(db.len(), 384);
+ let norm: f32 = db.iter().map(|v| v * v).sum::<f32>().sqrt();
+ assert!((norm - 1.0).abs() < 1e-4, "unit vector, got {norm}");
+ let storage = embedder.embed("sqlite storage layer").await.unwrap();
+ let weather = embedder.embed("tomorrow will be sunny").await.unwrap();
+ let dot = |a: &[f32], b: &[f32]| -> f32 { a.iter().zip(b).map(|(x, y)| x * y).sum() };
+ assert!(
+ dot(&db, &storage) > dot(&db, &weather),
+ "semantic neighbour must beat the unrelated sentence"
+ );
+ }
+}
diff --git a/crates/ai-memory-llm/tests/openai_compat_embedder.rs b/crates/ai-memory-llm/tests/openai_compat_embedder.rs
index ac70b128..5925bf03 100644
--- a/crates/ai-memory-llm/tests/openai_compat_embedder.rs
+++ b/crates/ai-memory-llm/tests/openai_compat_embedder.rs
@@ -84,6 +84,7 @@ async fn factory_builds_compat_embedder_and_requires_base_url() {
dim: 768,
api_key: SecretString::from(String::new()),
base_url: Some("http://localhost:11434/v1".into()),
+ models_dir: None,
})
.expect("factory builds compat embedder");
assert_eq!(ok.provider(), "openai-compat");
@@ -95,6 +96,7 @@ async fn factory_builds_compat_embedder_and_requires_base_url() {
dim: 768,
api_key: SecretString::from(String::new()),
base_url: None,
+ models_dir: None,
}) {
Ok(_) => panic!("compat embedder must not build without a base URL"),
Err(err) => err,
@@ -110,6 +112,7 @@ async fn factory_builds_compat_embedder_and_requires_base_url() {
dim: 0,
api_key: SecretString::from(String::new()),
base_url: Some("http://localhost:11434/v1".into()),
+ models_dir: None,
});
assert!(
matches!(zero_dim, Err(LlmError::NotConfigured(ref msg)) if msg.contains("greater than zero")),
diff --git a/docs/llm-providers.md b/docs/llm-providers.md
index 64da381b..3f296996 100644
--- a/docs/llm-providers.md
+++ b/docs/llm-providers.md
@@ -147,6 +147,11 @@ hybrid paths apply the same bounded page-authority adjustment after candidate
generation; embeddings improve relevance recall but do not decide which source
is canonical.
+`AI_MEMORY_EMBEDDING_PROVIDER=local` needs no key and no server at all:
+sentence embeddings run in-process (pure-Rust `all-MiniLM-L6-v2`,
+384-dim), with the model fetched once into `<data_dir>/models/` under
+pinned checksums — see [`docs/local-embeddings.md`](local-embeddings.md).
+
See [`docs/install.md#llm-provider-tiers`](docs/install.md#llm-provider-tiers)
for env vars and Ollama/OpenRouter/Atlas Cloud/OrcaRouter examples, and
[`docs/llm-provider-comparison.md`](docs/llm-provider-comparison.md)
diff --git a/docs/local-embeddings.md b/docs/local-embeddings.md
new file mode 100644
index 00000000..55e6f97f
--- /dev/null
+++ b/docs/local-embeddings.md
@@ -0,0 +1,61 @@
+# Local embeddings
+
+*2.0 item 5.* `AI_MEMORY_EMBEDDING_PROVIDER=local` runs sentence
+embeddings **in-process** — no API key, no external server, no GPU
+required. Pure-Rust BERT inference (candle) with
+`all-MiniLM-L6-v2` (384-dim), the sentence-transformers workhorse the
+comparable memory servers ship by default.
+
+```toml
+# config.toml
+embedding_provider = "local" # model/dim default correctly
+```
+
+## The model files
+
+The binary does not bundle the model (~87 MB). On the first start with
+`local` configured, the server fetches three files into
+`<data_dir>/models/all-MiniLM-L6-v2/` — each verified against a sha256
+pinned in the source, so a drifted or tampered upstream file fails
+loudly instead of silently changing every vector:
+
+| file | sha256 (pinned 2026-09-01) |
+|---|---|
+| `model.safetensors` | `53aa5117…` |
+| `tokenizer.json` | `be50c362…` |
+| `config.json` | `953f9c0d…` |
+
+**Offline installs**: download the three files from
+`https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2/resolve/main/`
+on any machine and drop them into the directory above; the loader
+verifies the same checksums and never touches the network. The model
+is Apache-2.0.
+
+## Coexistence and migration
+
+Nothing is forced. `(provider, model, dim)` is stored on every
+embedding row, and hybrid search ignores vectors whose triple does not
+match the configured embedder — so local vectors sit beside any
+provider vectors you already have, and switching back is a config
+change. `ai-memory embed --force` re-embeds a project under the
+current provider when you want one consistent set.
+
+Existing installs keep their configured provider; `local` is opt-in.
+Fresh-install defaults are decided by benchmark numbers, not vibes —
+see `docs/benchmarks/` for the zero-LLM vs local-embeddings
+LongMemEval rows, reproducible via:
+
+```bash
+cargo run --release -p ai-memory-eval -- retrieval --embeddings local
+```
+
+## Operational notes
+
+- Inference is CPU, off the async runtime (`spawn_blocking`);
+ first-load reads ~87 MB into memory once per server process.
+- The `local-embeddings` cargo feature (default on) carries the ML
+ dependency tree; a slim build can disable it and keep every other
+ provider.
+- Tokenization truncates at 512 tokens — the model's positional limit;
+ page bodies beyond that contribute their head, same contract as the
+ hosted embedders.
diff --git a/evals/src/retrieval/mod.rs b/evals/src/retrieval/mod.rs
index 6fa095d4..11fe8ac1 100644
--- a/evals/src/retrieval/mod.rs
+++ b/evals/src/retrieval/mod.rs
@@ -60,6 +60,12 @@ pub struct RetrievalArgs {
/// Keep the server's temp data dir for post-mortem inspection.
#[arg(long)]
keep_data_dir: bool,
+
+ /// Embedding mode: `none` (zero-LLM, the default) or `local`
+ /// (in-process all-MiniLM-L6-v2; the model is fetched once into
+ /// `evals/models/`, checksum-pinned).
+ #[arg(long, default_value = "none")]
+ embeddings: String,
}
pub async fn run(args: RetrievalArgs) -> Result<()> {
@@ -90,7 +96,29 @@ pub async fn run(args: RetrievalArgs) -> Result<()> {
args.server_bin.display()
);
}
- let server = EvalServer::launch(&args.server_bin, args.keep_data_dir).await?;
+ let (embeddings, mode, models_root) = match args.embeddings.as_str() {
+ "none" => (server::EvalEmbeddings::None, "zero-llm", None),
+ "local" => {
+ let root = PathBuf::from("evals/models");
+ if !ai_memory_llm::model_present(&root) {
+ tracing::info!("fetching the local embedding model into evals/models (~87 MB)");
+ ai_memory_llm::fetch_model(&root).await?;
+ }
+ (
+ server::EvalEmbeddings::Local,
+ "local-embeddings",
+ Some(root),
+ )
+ }
+ other => bail!("--embeddings must be `none` or `local`, got {other}"),
+ };
+ let server = EvalServer::launch(
+ &args.server_bin,
+ args.keep_data_dir,
+ embeddings,
+ models_root.as_deref(),
+ )
+ .await?;
tracing::info!(url = server.base_url, data_dir = %server.data_dir_path.display(), "eval server up");
let client = reqwest::Client::builder()
@@ -177,7 +205,7 @@ pub async fn run(args: RetrievalArgs) -> Result<()> {
hardware: report::hardware(),
dataset: "longmemeval_s",
dataset_sha256: dataset::LONGMEMEVAL_S_SHA256,
- mode: "zero-llm",
+ mode,
questions_scored: scores.len(),
abstention_excluded: abstention.len(),
ks: args.ks.clone(),
diff --git a/evals/src/retrieval/server.rs b/evals/src/retrieval/server.rs
index 1127ffb9..f3aeb192 100644
--- a/evals/src/retrieval/server.rs
+++ b/evals/src/retrieval/server.rs
@@ -22,9 +22,25 @@ pub struct EvalServer {
pub data_dir_path: PathBuf,
}
+/// Which embedding configuration the eval server runs with.
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum EvalEmbeddings {
+ /// Deterministic zero-LLM mode: no embedder at all.
+ None,
+ /// In-process local embeddings (all-MiniLM-L6-v2). The model files
+ /// must already sit in the given models root; the harness seeds the
+ /// server's data dir from there so the server never fetches.
+ Local,
+}
+
impl EvalServer {
/// Launch `server_bin` on a free loopback port with a fresh data dir.
- pub async fn launch(server_bin: &PathBuf, keep_data_dir: bool) -> Result<Self> {
+ pub async fn launch(
+ server_bin: &PathBuf,
+ keep_data_dir: bool,
+ embeddings: EvalEmbeddings,
+ models_root: Option<&std::path::Path>,
+ ) -> Result<Self> {
let tmp = tempfile::Builder::new()
.prefix("ai-memory-eval-")
.tempdir()
@@ -39,25 +55,45 @@ impl EvalServer {
};
let bind = format!("127.0.0.1:{port}");
- let child = Command::new(server_bin)
- .args([
- "serve",
- "--transport",
- "http",
- "--bind",
- &bind,
- "--data-dir",
- ])
- .arg(&data_dir_path)
- .env("AI_MEMORY_AUTH_TOKEN", EVAL_AUTH_TOKEN)
- .env("AI_MEMORY_CAPTURE_ASSISTANT", "true")
- // Zero-LLM determinism: nothing may call out.
- .env_remove("AI_MEMORY_LLM_PROVIDER")
- .env_remove("AI_MEMORY_EMBEDDING_PROVIDER")
- .env_remove("AI_MEMORY_RERANKER")
- .env_remove("OPENAI_API_KEY")
- .env_remove("ANTHROPIC_API_KEY")
- .env_remove("LLM_API_KEY")
+ if embeddings == EvalEmbeddings::Local {
+ let src = models_root
+ .ok_or_else(|| anyhow::anyhow!("local embeddings need a models root"))?
+ .join("all-MiniLM-L6-v2");
+ let dest = data_dir_path.join("models/all-MiniLM-L6-v2");
+ std::fs::create_dir_all(&dest)?;
+ for entry in std::fs::read_dir(&src).context("reading model dir")? {
+ let entry = entry?;
+ std::fs::copy(entry.path(), dest.join(entry.file_name()))?;
+ }
+ }
+ let mut cmd = Command::new(server_bin);
+ cmd.args([
+ "serve",
+ "--transport",
+ "http",
+ "--bind",
+ &bind,
+ "--data-dir",
+ ])
+ .arg(&data_dir_path)
+ .env("AI_MEMORY_AUTH_TOKEN", EVAL_AUTH_TOKEN)
+ .env("AI_MEMORY_CAPTURE_ASSISTANT", "true")
+ // No chat LLM and no reranker in either mode; the embedding env
+ // selects the one nondefault stream under test.
+ .env_remove("AI_MEMORY_LLM_PROVIDER")
+ .env_remove("AI_MEMORY_RERANKER")
+ .env_remove("OPENAI_API_KEY")
+ .env_remove("ANTHROPIC_API_KEY")
+ .env_remove("LLM_API_KEY");
+ match embeddings {
+ EvalEmbeddings::None => {
+ cmd.env_remove("AI_MEMORY_EMBEDDING_PROVIDER");
+ }
+ EvalEmbeddings::Local => {
+ cmd.env("AI_MEMORY_EMBEDDING_PROVIDER", "local");
+ }
+ }
+ let child = cmd
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()