1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Collection health diagnostics for embedded SDK usage.
//!
//! Provides [`CollectionDiagnostics`] and [`IndexHealth`] to let developers
//! inspect a collection's readiness without relying on the REST server.
use super::types::Collection;
use super::{GraphCollection, MetadataCollection, VectorCollection};
/// Health status of a collection's search index.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum IndexHealth {
/// Index is populated and ready for search.
Healthy,
/// Index needs to be rebuilt (e.g., after corruption or schema change).
NeedsRebuild(String),
/// Index is empty (no data ingested yet).
Empty,
}
/// Diagnostic snapshot of a collection's state.
///
/// Returned by [`VectorCollection::diagnostics()`],
/// [`GraphCollection::diagnostics()`],
/// [`MetadataCollection::diagnostics()`],
/// and [`Database::collection_diagnostics()`](crate::Database::collection_diagnostics).
#[derive(Debug, Clone)]
pub struct CollectionDiagnostics {
/// Whether the collection contains at least one vector/point.
pub has_vectors: bool,
/// Whether the collection is ready to serve search queries.
pub search_ready: bool,
/// Whether a valid dimension is configured (> 0 for vector collections).
pub dimension_configured: bool,
/// Total number of points in the collection.
pub point_count: usize,
/// Health status of the primary search index.
pub index_health: IndexHealth,
}
impl CollectionDiagnostics {
/// Builds diagnostics from a `Collection` instance.
pub(crate) fn from_collection(coll: &Collection) -> Self {
let config = coll.config();
let point_count = config.point_count;
let has_vectors = point_count > 0;
let dimension_configured = config.dimension > 0;
let search_ready = has_vectors && dimension_configured;
let index_health = if point_count == 0 {
IndexHealth::Empty
} else {
IndexHealth::Healthy
};
Self {
has_vectors,
search_ready,
dimension_configured,
point_count,
index_health,
}
}
/// Builds diagnostics for a metadata-only collection.
pub(crate) fn from_metadata(coll: &Collection) -> Self {
let point_count = coll.len();
Self {
has_vectors: point_count > 0,
search_ready: false,
dimension_configured: false,
point_count,
index_health: if point_count == 0 {
IndexHealth::Empty
} else {
IndexHealth::Healthy
},
}
}
}
impl VectorCollection {
/// Returns diagnostic information about this collection.
#[must_use]
pub fn diagnostics(&self) -> CollectionDiagnostics {
CollectionDiagnostics::from_collection(&self.inner)
}
}
impl GraphCollection {
/// Returns diagnostic information about this collection.
#[must_use]
pub fn diagnostics(&self) -> CollectionDiagnostics {
CollectionDiagnostics::from_collection(&self.inner)
}
}
impl MetadataCollection {
/// Returns diagnostic information about this collection.
#[must_use]
pub fn diagnostics(&self) -> CollectionDiagnostics {
CollectionDiagnostics::from_metadata(&self.inner)
}
}