velesdb_core/collection/
diagnostics.rs1use super::types::Collection;
7use super::{GraphCollection, MetadataCollection, VectorCollection};
8
9#[derive(Debug, Clone, PartialEq, Eq)]
11pub enum IndexHealth {
12 Healthy,
14 NeedsRebuild(String),
16 Empty,
18}
19
20#[derive(Debug, Clone)]
27pub struct CollectionDiagnostics {
28 pub has_vectors: bool,
30 pub search_ready: bool,
32 pub dimension_configured: bool,
34 pub point_count: usize,
36 pub index_health: IndexHealth,
38}
39
40impl CollectionDiagnostics {
41 pub(crate) fn from_collection(coll: &Collection) -> Self {
43 let config = coll.config();
44 let point_count = config.point_count;
45 let has_vectors = point_count > 0;
46 let dimension_configured = config.dimension > 0;
47 let search_ready = has_vectors && dimension_configured;
48 let index_health = if point_count == 0 {
49 IndexHealth::Empty
50 } else {
51 IndexHealth::Healthy
52 };
53
54 Self {
55 has_vectors,
56 search_ready,
57 dimension_configured,
58 point_count,
59 index_health,
60 }
61 }
62
63 pub(crate) fn from_metadata(coll: &Collection) -> Self {
65 let point_count = coll.len();
66
67 Self {
68 has_vectors: point_count > 0,
69 search_ready: false,
70 dimension_configured: false,
71 point_count,
72 index_health: if point_count == 0 {
73 IndexHealth::Empty
74 } else {
75 IndexHealth::Healthy
76 },
77 }
78 }
79}
80
81impl VectorCollection {
82 #[must_use]
84 pub fn diagnostics(&self) -> CollectionDiagnostics {
85 CollectionDiagnostics::from_collection(&self.inner)
86 }
87}
88
89impl GraphCollection {
90 #[must_use]
92 pub fn diagnostics(&self) -> CollectionDiagnostics {
93 CollectionDiagnostics::from_collection(&self.inner)
94 }
95}
96
97impl MetadataCollection {
98 #[must_use]
100 pub fn diagnostics(&self) -> CollectionDiagnostics {
101 CollectionDiagnostics::from_metadata(&self.inner)
102 }
103}