Skip to main content

selene_graph/graph/
index_entries.rs

1use std::sync::Arc;
2
3use smallvec::SmallVec;
4
5use selene_core::{DbString, HnswIndexConfig, IvfIndexConfig};
6
7use crate::composite_typed_index::CompositeTypedIndex;
8use crate::text_index::{TextIndex, TextIndexMemoryUsage, TextIndexStats};
9use crate::typed_index::{TypedIndex, TypedIndexKind};
10use crate::vector_index::{VectorIndex, VectorIndexKind, VectorIndexMemoryUsage};
11
12/// Registered built-in property-index metadata.
13#[derive(Clone, Debug)]
14pub struct PropertyIndexEntry {
15    /// Index data for the `(label, property)` registration.
16    pub index: Arc<TypedIndex>,
17    /// Optional explicit catalog name. `None` means the name is derived at render time.
18    pub name: Option<DbString>,
19}
20
21impl PropertyIndexEntry {
22    /// Construct an index entry from the built index and optional explicit name.
23    #[must_use]
24    pub fn new(index: TypedIndex, name: Option<DbString>) -> Self {
25        Self {
26            index: Arc::new(index),
27            name,
28        }
29    }
30
31    /// Return the registered index kind.
32    #[must_use]
33    pub fn kind(&self) -> TypedIndexKind {
34        self.index.kind()
35    }
36}
37
38/// Registered built-in composite-property index metadata.
39#[derive(Clone, Debug)]
40pub struct CompositePropertyIndexEntry {
41    /// Index data for the `(label, properties...)` registration.
42    pub index: Arc<CompositeTypedIndex>,
43    /// Indexed properties in declaration order.
44    pub declared_properties: SmallVec<[DbString; 4]>,
45    /// Optional explicit catalog name. `None` means the name is derived at render time.
46    pub name: Option<DbString>,
47}
48
49impl CompositePropertyIndexEntry {
50    /// Construct a composite index entry.
51    #[must_use]
52    pub fn new(
53        index: CompositeTypedIndex,
54        declared_properties: SmallVec<[DbString; 4]>,
55        name: Option<DbString>,
56    ) -> Self {
57        Self {
58            index: Arc::new(index),
59            declared_properties,
60            name,
61        }
62    }
63
64    /// Return the registered component kinds in declaration order.
65    #[must_use]
66    pub fn kinds(&self) -> SmallVec<[TypedIndexKind; 4]> {
67        self.index.kinds().iter().copied().collect()
68    }
69}
70
71/// Registered built-in vector-index metadata.
72#[derive(Clone, Debug)]
73pub struct VectorIndexEntry {
74    /// Index data for the `(label, property)` registration.
75    pub index: Arc<VectorIndex>,
76    /// Optional explicit catalog name. `None` means the name is derived at render time.
77    pub name: Option<DbString>,
78}
79
80impl VectorIndexEntry {
81    /// Construct a vector index entry from the built index and optional name.
82    #[must_use]
83    pub fn new(index: VectorIndex, name: Option<DbString>) -> Self {
84        Self {
85            index: Arc::new(index),
86            name,
87        }
88    }
89
90    /// Return the registered vector index kind.
91    #[must_use]
92    pub fn kind(&self) -> VectorIndexKind {
93        self.index.kind()
94    }
95
96    /// Return the registered vector dimensionality.
97    #[must_use]
98    pub fn dimension(&self) -> u32 {
99        self.index.dimension()
100    }
101
102    /// Return the registered HNSW construction config, if this is an HNSW index.
103    #[must_use]
104    pub fn hnsw_config(&self) -> Option<HnswIndexConfig> {
105        self.index.hnsw_config()
106    }
107
108    /// Return the registered IVF construction config, if this is a configured IVF index.
109    #[must_use]
110    pub fn ivf_config(&self) -> Option<IvfIndexConfig> {
111        self.index.ivf_config()
112    }
113
114    /// Return an estimated memory usage snapshot for this vector index.
115    #[must_use]
116    pub fn memory_usage(&self) -> VectorIndexMemoryUsage {
117        self.index.memory_usage()
118    }
119}
120
121/// Registered built-in text-index metadata.
122#[derive(Clone, Debug)]
123pub struct TextIndexEntry {
124    /// Index data for the `(label, property)` registration.
125    pub index: Arc<TextIndex>,
126    /// Optional explicit catalog name. `None` means the name is derived at render time.
127    pub name: Option<DbString>,
128}
129
130impl TextIndexEntry {
131    /// Construct a text index entry from the built index and optional name.
132    #[must_use]
133    pub fn new(index: TextIndex, name: Option<DbString>) -> Self {
134        Self {
135            index: Arc::new(index),
136            name,
137        }
138    }
139
140    /// Return aggregate index counters.
141    #[must_use]
142    pub fn stats(&self) -> TextIndexStats {
143        self.index.stats()
144    }
145
146    /// Return an estimated memory usage snapshot for this text index.
147    #[must_use]
148    pub fn memory_usage(&self) -> TextIndexMemoryUsage {
149        self.index.memory_usage()
150    }
151}
152
153/// Owned row returned when iterating composite property-index registrations.
154pub type CompositePropertyIndexEntryRow = (
155    DbString,
156    SmallVec<[DbString; 4]>,
157    SmallVec<[TypedIndexKind; 4]>,
158    Option<DbString>,
159);
160
161/// Owned row returned when iterating vector-index registrations.
162pub type VectorIndexEntryRow = (
163    DbString,
164    DbString,
165    VectorIndexKind,
166    u32,
167    Option<HnswIndexConfig>,
168    Option<IvfIndexConfig>,
169    Option<DbString>,
170);
171
172/// Owned row returned when iterating text-index registrations.
173pub type TextIndexEntryRow = (
174    DbString,
175    DbString,
176    TextIndexStats,
177    TextIndexMemoryUsage,
178    Option<DbString>,
179);