MCPcopy Create free account
hub / github.com/cosdata/cosdata / retrieve_average_document_length

Function retrieve_average_document_length

src/models/meta_persist.rs:252–274  ·  view source on GitHub ↗
(lmdb: &MetaDb)

Source from the content-addressed store, hash-verified

250}
251
252pub fn retrieve_average_document_length(lmdb: &MetaDb) -> Result<Option<f32>, WaCustomError> {
253 let env = lmdb.env.clone();
254 let db = lmdb.db;
255 let txn = env
256 .begin_ro_txn()
257 .map_err(|e| WaCustomError::DatabaseError(format!("Failed to begin transaction: {}", e)))?;
258 let key = key!(m:average_document_length);
259
260 let serialized = match txn.get(db, &key) {
261 Ok(bytes) => bytes,
262 Err(lmdb::Error::NotFound) => return Ok(None),
263 Err(e) => return Err(WaCustomError::DatabaseError(e.to_string())),
264 };
265
266 let bytes: [u8; 4] = serialized.try_into().map_err(|_| {
267 WaCustomError::DeserializationError(
268 "Failed to deserialize average document length: length mismatch".to_string(),
269 )
270 })?;
271 let len = f32::from_le_bytes(bytes);
272
273 Ok(Some(len))
274}
275
276pub fn retrieve_highest_internal_id(lmdb: &MetaDb) -> Result<Option<u32>, WaCustomError> {
277 let env = lmdb.env.clone();

Callers 1

load_tf_idf_indexMethod · 0.85

Calls 2

cloneMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected