MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / stats

Method stats

nodedb-vector/src/collection/stats.rs:11–103  ·  view source on GitHub ↗

Collect live statistics from all segments.

(&self)

Source from the content-addressed store, hash-verified

9impl VectorCollection {
10 /// Collect live statistics from all segments.
11 pub fn stats(&self) -> nodedb_types::VectorIndexStats {
12 let growing_vectors = self.growing.len();
13 let sealed_vectors: usize = self.sealed.iter().map(|s| s.index.len()).sum();
14 let building_vectors: usize = self.building.iter().map(|s| s.flat.len()).sum();
15
16 let tombstone_count: usize = self
17 .sealed
18 .iter()
19 .map(|s| s.index.tombstone_count())
20 .sum::<usize>()
21 + self.growing.tombstone_count()
22 + self
23 .building
24 .iter()
25 .map(|s| s.flat.tombstone_count())
26 .sum::<usize>();
27
28 let total = growing_vectors + sealed_vectors + building_vectors;
29 let tombstone_ratio = if total > 0 {
30 tombstone_count as f64 / total as f64
31 } else {
32 0.0
33 };
34
35 let quantization = if let Some(ref dispatch) = self.codec_dispatch {
36 match dispatch.quantization() {
37 "rabitq" => nodedb_types::VectorIndexQuantization::RaBitQ,
38 "bbq" => nodedb_types::VectorIndexQuantization::Bbq,
39 _ => nodedb_types::VectorIndexQuantization::None,
40 }
41 } else if self.sealed.iter().any(|s| s.pq.is_some()) {
42 nodedb_types::VectorIndexQuantization::Pq
43 } else if self.sealed.iter().any(|s| s.sq8.is_some()) {
44 nodedb_types::VectorIndexQuantization::Sq8
45 } else {
46 nodedb_types::VectorIndexQuantization::None
47 };
48
49 let index_type = match self.index_config.index_type {
50 IndexType::HnswPq => nodedb_types::VectorIndexType::HnswPq,
51 IndexType::IvfPq => nodedb_types::VectorIndexType::IvfPq,
52 IndexType::Hnsw => nodedb_types::VectorIndexType::Hnsw,
53 };
54
55 let hnsw_mem: usize = self
56 .sealed
57 .iter()
58 .map(|s| s.index.memory_usage_bytes())
59 .sum();
60 let sq8_mem: usize = self
61 .sealed
62 .iter()
63 .filter_map(|s| s.sq8.as_ref().map(|(_, data)| data.len()))
64 .sum();
65 let growing_mem = growing_vectors * self.dim * std::mem::size_of::<f32>();
66 let building_mem = building_vectors * self.dim * std::mem::size_of::<f32>();
67 let memory_bytes = hnsw_mem + sq8_mem + growing_mem + building_mem;
68

Calls 10

sumMethod · 0.80
memory_usage_bytesMethod · 0.80
file_sizeMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
tombstone_countMethod · 0.45
quantizationMethod · 0.45
as_refMethod · 0.45
live_countMethod · 0.45
is_emptyMethod · 0.45