selene_graph/graph/
index_entries.rs1use 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#[derive(Clone, Debug)]
14pub struct PropertyIndexEntry {
15 pub index: Arc<TypedIndex>,
17 pub name: Option<DbString>,
19}
20
21impl PropertyIndexEntry {
22 #[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 #[must_use]
33 pub fn kind(&self) -> TypedIndexKind {
34 self.index.kind()
35 }
36}
37
38#[derive(Clone, Debug)]
40pub struct CompositePropertyIndexEntry {
41 pub index: Arc<CompositeTypedIndex>,
43 pub declared_properties: SmallVec<[DbString; 4]>,
45 pub name: Option<DbString>,
47}
48
49impl CompositePropertyIndexEntry {
50 #[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 #[must_use]
66 pub fn kinds(&self) -> SmallVec<[TypedIndexKind; 4]> {
67 self.index.kinds().iter().copied().collect()
68 }
69}
70
71#[derive(Clone, Debug)]
73pub struct VectorIndexEntry {
74 pub index: Arc<VectorIndex>,
76 pub name: Option<DbString>,
78}
79
80impl VectorIndexEntry {
81 #[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 #[must_use]
92 pub fn kind(&self) -> VectorIndexKind {
93 self.index.kind()
94 }
95
96 #[must_use]
98 pub fn dimension(&self) -> u32 {
99 self.index.dimension()
100 }
101
102 #[must_use]
104 pub fn hnsw_config(&self) -> Option<HnswIndexConfig> {
105 self.index.hnsw_config()
106 }
107
108 #[must_use]
110 pub fn ivf_config(&self) -> Option<IvfIndexConfig> {
111 self.index.ivf_config()
112 }
113
114 #[must_use]
116 pub fn memory_usage(&self) -> VectorIndexMemoryUsage {
117 self.index.memory_usage()
118 }
119}
120
121#[derive(Clone, Debug)]
123pub struct TextIndexEntry {
124 pub index: Arc<TextIndex>,
126 pub name: Option<DbString>,
128}
129
130impl TextIndexEntry {
131 #[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 #[must_use]
142 pub fn stats(&self) -> TextIndexStats {
143 self.index.stats()
144 }
145
146 #[must_use]
148 pub fn memory_usage(&self) -> TextIndexMemoryUsage {
149 self.index.memory_usage()
150 }
151}
152
153pub type CompositePropertyIndexEntryRow = (
155 DbString,
156 SmallVec<[DbString; 4]>,
157 SmallVec<[TypedIndexKind; 4]>,
158 Option<DbString>,
159);
160
161pub type VectorIndexEntryRow = (
163 DbString,
164 DbString,
165 VectorIndexKind,
166 u32,
167 Option<HnswIndexConfig>,
168 Option<IvfIndexConfig>,
169 Option<DbString>,
170);
171
172pub type TextIndexEntryRow = (
174 DbString,
175 DbString,
176 TextIndexStats,
177 TextIndexMemoryUsage,
178 Option<DbString>,
179);