AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(native): dashboard summary reports real measured size_bytes
xerj-org062b8e492acd
diff --git a/engine/crates/xerj-api/src/native.rs b/engine/crates/xerj-api/src/native.rsindex 8dc4d736b..cb9996308 100644--- a/engine/crates/xerj-api/src/native.rs+++ b/engine/crates/xerj-api/src/native.rs@@ -1818,7 +1818,8 @@ pub async fn get_index_encodings(// Handler: GET /v1/dashboard/summary//// First step toward a built-in UI — returns an overview of all indices with-// doc counts, estimated on-disk sizes, per-field encodings, and health status.+// doc counts, measured on-disk + memtable sizes, per-field encodings, and+// health status.// This is intentionally designed as a "one-shot" endpoint so a lightweight// dashboard can render a complete picture with a single HTTP request.// ─────────────────────────────────────────────────────────────────────────────@@ -1828,7 +1829,9 @@ pub async fn get_index_encodings(pub struct DashboardIndexSummary {pub name: String,pub doc_count: u64,- /// Approximate segment data size in bytes (sum of segment section sizes).+ /// Real measured size in bytes: sum of on-disk segment file sizes plus the+ /// in-memory memtable byte size (the same figures reported by the+ /// `_segments` API and `IndexStats`).pub size_bytes: u64,/// Number of distinct fields.pub field_count: usize,@@ -1861,13 +1864,16 @@ pub async fn dashboard_summary(State(state): State<AppState>) -> impl IntoRespon"green"};- // Approximate disk size: rough heuristic — 200 bytes per doc in segments,- // 500 bytes per memtable doc (uncompressed).- let size_bytes = stats- .doc_count- .saturating_sub(stats.memtable_doc_count as u64)- * 200- + stats.memtable_doc_count as u64 * 500;+ // Real measured size: sum of on-disk segment file sizes (the same+ // per-segment `size_bytes` reported by the `_segments` API) plus the+ // in-memory memtable byte size (as reported by `IndexStats`).+ let segment_bytes: u64 = idx+ .store_snapshot()+ .segments+ .iter()+ .map(|s| s.size_bytes)+ .sum();+ let size_bytes = segment_bytes + stats.memtable_size_bytes as u64;let mut encodings = stats.field_encodings;encodings.sort_by(|a, b| {diff --git a/engine/crates/xerj-engine/tests/integration.rs b/engine/crates/xerj-engine/tests/integration.rsindex a8bb24abf..0b78e2b75 100644--- a/engine/crates/xerj-engine/tests/integration.rs+++ b/engine/crates/xerj-engine/tests/integration.rs@@ -4429,3 +4429,76 @@ async fn test_smart_field_encoding_apache_logs() {);}}++// ── Dashboard summary size_bytes is real measured bytes, not a heuristic ──────+//+// The native `/v1/dashboard/summary` handler reports per-index `size_bytes` as+// `sum(store_snapshot().segments[].size_bytes) + stats.memtable_size_bytes`.+// Both inputs are real byte measurements (the segment figures also back the+// `_segments` API; the memtable figure backs `IndexStats`). This test asserts+// that computation at the engine level — the handler is a thin wrapper over it,+// so we verify the load-bearing data here rather than through the HTTP harness.+#[tokio::test]+async fn test_dashboard_summary_size_is_measured_bytes() {+ let dir = TempDir::new().unwrap();+ let engine = make_engine(&dir);++ engine.create_index("dash", Schema::empty()).unwrap();+ let idx = engine.get_index("dash").unwrap();++ for i in 0..50 {+ idx.index_document(+ Some(format!("doc{i}")),+ json!({ "n": i, "name": format!("item {i}"), "tag": "dashboard" }),+ )+ .await+ .unwrap();+ }++ // Before flush: everything lives in the memtable, so the measured memtable+ // byte count must be non-zero and there are no segments yet.+ let stats = idx.stats().await;+ assert_eq!(+ stats.segment_count, 0,+ "no segments should exist before flush"+ );+ assert!(+ stats.memtable_size_bytes > 0,+ "memtable byte size should be > 0 with docs buffered"+ );++ // Flush to disk so a real on-disk segment (with a real byte size) exists.+ idx.flush().await.unwrap();++ // Recompute the exact expression the dashboard handler uses.+ let snap = idx.store_snapshot();+ assert!(+ !snap.segments.is_empty(),+ "at least one segment should exist after flush"+ );+ let segment_bytes: u64 = snap.segments.iter().map(|s| s.size_bytes).sum();+ assert!(+ segment_bytes > 0,+ "segment byte size should be > 0 after flush (real .seg file bytes)"+ );++ let stats = idx.stats().await;+ // This mirrors the dashboard handler's size_bytes computation exactly:+ // real segment file bytes + real memtable bytes.+ let size_bytes = segment_bytes + stats.memtable_size_bytes as u64;++ // The measured size must be real (> 0).+ assert!(size_bytes > 0, "measured dashboard size_bytes must be > 0");++ // Sanity: the measured on-disk size is nothing like the old heuristic's+ // fixed 200-bytes-per-segment-doc fabrication, proving it is real.+ let old_heuristic = stats+ .doc_count+ .saturating_sub(stats.memtable_doc_count as u64)+ * 200+ + stats.memtable_doc_count as u64 * 500;+ assert_ne!(+ size_bytes, old_heuristic,+ "measured size should differ from the removed docs*200+memtable*500 heuristic"+ );+}