{"record":{"id":"5d22e2f7274ee22c","repo":"xai-org/x-algorithm","slug":"embeddingcache-no-database-in","errorCode":null,"errorMessage":"EmbeddingCache: no database in {}","messagePattern":"EmbeddingCache: no database in (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"phoenix/crates/serving/xai-recsys-mm-server/src/embedding_cache.rs","lineNumber":280,"sourceCode":"        lmdb_path: &Path,\n        data_path: &Path,\n        ttl: std::time::Duration,\n    ) -> anyhow::Result<Self> {\n        let data_mdb = lmdb_path.join(\"data.mdb\");\n        let map_size = std::fs::metadata(&data_mdb)\n            .map(|m| m.len() as usize)\n            .unwrap_or(0)\n            .max(1024 * 1024);\n\n        let env = unsafe {\n            heed::EnvOpenOptions::new()\n                .map_size(map_size)\n                .max_readers(1024)\n                .open(lmdb_path)?\n        };\n        let rtxn = env.read_txn()?;\n        let db = env.open_database(&rtxn, None)?.ok_or_else(|| {\n            anyhow::anyhow!(\"EmbeddingCache: no database in {}\", lmdb_path.display())\n        })?;\n        let emb_dim = db\n            .get(&rtxn, &LMDB_META_KEY_EMB_DIM)?\n            .ok_or_else(|| anyhow::anyhow!(\"EmbeddingCache: missing emb_dim metadata\"))?\n            as usize;\n        rtxn.commit()?;\n\n        let file = OpenOptions::new().read(true).write(true).open(data_path)?;\n        let mmap = unsafe { MmapMut::map_mut(&file)? };\n        let slot_size = SLOT_HEADER_SIZE + emb_dim * std::mem::size_of::<f16>();\n        let capacity = (mmap.len() - HEADER_SIZE) / slot_size;\n\n        log::info!(\n            \"EmbeddingCache: opened lmdb={} data={} (capacity={}, emb_dim={})\",\n            lmdb_path.display(),\n            data_path.display(),\n            capacity,\n            emb_dim,","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/crates/serving/xai-recsys-mm-server/src/embedding_cache.rs#L262-L298","documentation":"Raised by EmbeddingCache::open when the LMDB environment at lmdb_path opens successfully but contains no named database — the file exists but has no data inside it. The cache cannot be initialized because there is nothing to read.","triggerScenarios":"Calling EmbeddingCache::open on an empty, freshly-created, or corrupted LMDB directory/file; pointing lmdb_path at a file created by another tool or an aborted create() run.","commonSituations":"Passing a wrong --lmdb-path pointing at an empty file; a previous create() crashed before writing; using open() where create() was intended.","solutions":["Point lmdb_path at a database produced by EmbeddingCache::create","If the cache should be built fresh, call create() instead of open()","If the file is corrupted, delete it and regenerate via create()","Add a preflight check that the path is a non-empty, valid LMDB file before calling open"],"exampleFix":"// before\nlet cache = EmbeddingCache::open(lmdb_path, data_path, map_size)?;\n\n// after\nif std::fs::metadata(&lmdb_path).map(|m| m.len()).unwrap_or(0) == 0 {\n    anyhow::bail!(\"LMDB file {} is empty; run create() first\", lmdb_path.display());\n}\nlet cache = EmbeddingCache::open(lmdb_path, data_path, map_size)?;","handlingStrategy":"validation","validationCode":"fn is_valid_lmdb(p: &Path) -> bool { std::fs::metadata(p).map(|m| m.len() > 0).unwrap_or(false) }","typeGuard":null,"tryCatchPattern":"null","preventionTips":["Always create caches via create(); open() only for verified artifacts","Store a format magic/version in the first record","Fail fast at startup with a clear message pointing to regeneration"],"tags":["lmdb","embedding-cache","empty-database","rust"],"backgroundTag":"database-file-empty","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}