fix: derive EMBEDDING_DIM from embeddings module (was hardcoded 384)#200
Conversation
binary_vectors.py hardcoded EMBEDDING_DIM=384 (bge-small-en-v1.5), which silently truncated larger embeddings to the first 384 components, losing up to 62.5% of vector information. Now imports from mnemosyne.core.embeddings with a 384 fallback. Also fixes BYTES_PER_VECTOR, compression_ratio, and theoretical_size_mb. Updated tests to use dynamic constants.
shmr.py had the same hardcoded EMBEDDING_DIM=384 as binary_vectors. polyphonic_recall.py hardcoded for bit-type vector normalization, silently breaking for non-384-dim models. Both now derive from embeddings.EMBEDDING_DIM at import time with a 384 fallback. polyphonic_recall uses a module-level cached float to avoid per-row imports in the hot path.
Missed one np.random.randn(384) on line 238 — now uses EMBEDDING_DIM like the other test methods already fixed.
|
Thank you @Whishp for this. Clean PR. Two files with hardcoded 384 dims is the kind of bug that lives for months because nobody runs anything but the default model. I appreciate that you tested against both 384 and 1024 models and verified sqlite-vec stores the correct vectors. Thats the right level of rigor. I do have one contrarian take. This is the third time someone hardcoded 384 in a file. Nothing stops a fourth next month. The real fix is a centralized dimension getter that every module imports, with a linting rule that flags hardcoded numbers near embedding operations. Ill open a follow-up issue for that. For now this ships. Low risk, high correctness, fixes silent data corruption for multilingual users. Thats a real problem, if you switch to e5-large and your vectors get truncated by 62%, you notice nothing until recall starts returning garbage. Merging. |
This release includes contributions from 6 contributors across 36 commits: Added: - sync_roles config for role-based autosave filtering (bitr8, #209) - sync_turn content limit env vars - Fact recall merged into standard recall path (MNEMOSYNE_FACT_RECALL_ENABLED) - Auto-default scope=global when extract=true - fact_recall() now searches consolidated_facts - MNEMOSYNE_EMBEDDING_API_URL independent of OPENROUTER_BASE_URL (mia-fourier, #206) Fixed: - remember() silently never stored embeddings - Hardcoded EMBEDDING_DIM=384 across 3 files + 1 test (Whishp, #200) - Plugin dir named 'mnemosyne' shadows pip package (#212) - Cross-session deletion of scope=global memories blocked (#204) - _vec_insert() ran inside deferred transaction (chinesewebman) - symlink rmtree crash on upgrade path - Windows directory junctions (no admin required) - Dead hermes_plugin tests breaking CI Changed: - Modular Hermes provider (2007-line split into 5 modules) - Consolidated extensions/ and hermes/ into integrations/ - Dropped Python 3.9 CI support Docs: benchmarks restored, plugin section revamped, standalone README, multilingual setup, UPDATING.md updated, install script link fixed (Joao Fernandes, #201)
Problem
Three hardcoded references to
EMBEDDING_DIM = 384(bge-small-en-v1.5) silently break vector operations when using larger models likeintfloat/multilingual-e5-large(1024-dim):binary_vectors.pyEMBEDDING_DIM = 384maximally_informative_binarizationtruncates 1024→384, losing 62.5% infobinary_vectors.py48.0,count * 48shmr.pyEMBEDDING_DIM = 384polyphonic_recall.pysim = 1.0 - (raw_dist / 384.0)While
embeddings.pyandbeam.pycorrectly resolve to the configured model's dimension (e.g. 1024 for e5-large), these three files had their own hardcoded constants.Fix
Derive
EMBEDDING_DIMfrommnemosyne.core.embeddingsat import time with a 384 fallback for standalone/test use:binary_vectors.py— importsEMBEDDING_DIMfromembeddings;BYTES_PER_VECTOR,compression_ratio, andtheoretical_size_mbnow use the resolved dimension instead of hardcoded constantsshmr.py— uses_embeddings.EMBEDDING_DIMinstead of384polyphonic_recall.py— module-level cached_EMBEDDING_DIM_BITSfor bit-vector normalisation (avoids per-row imports in hot path)test_integration.py— tests useEMBEDDING_DIM/BYTES_PER_VECTORinstead of hardcoded 384/48Verification
Unit tests pass with both models
Default (bge-small, 384-dim): 4 binary vector tests passed ✅
With multilingual-e5-large (1024-dim): 4 tests passed ✅
EmbeddingDimConfig (3 tests): all passed ✅
End-to-end on production DB (multilingual-e5-large)
embeddings.EMBEDDING_DIM= 1024 ✅vec_episodesDDL:int8[1024]matches model output ✅CI note
The CI failure (
ModuleNotFoundError: No module named 'hermes_plugin'in test collection) is a pre-existing issue, not caused by this PR.Files changed