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