1use velesdb_core::DistanceMetric as CoreDistanceMetric;
6use velesdb_core::FusionStrategy as CoreFusionStrategy;
7
8#[derive(Debug, thiserror::Error, uniffi::Error)]
14pub enum VelesError {
15 #[error("Database error: {message}")]
17 Database { message: String },
18
19 #[error("Collection error: {message}")]
21 Collection { message: String },
22
23 #[error("Dimension mismatch: expected {expected}, got {actual}")]
25 DimensionMismatch { expected: u32, actual: u32 },
26}
27
28impl From<velesdb_core::Error> for VelesError {
29 fn from(err: velesdb_core::Error) -> Self {
30 match err {
31 velesdb_core::Error::DimensionMismatch { expected, actual } =>
32 {
33 #[allow(clippy::cast_possible_truncation)]
34 VelesError::DimensionMismatch {
35 expected: expected as u32,
36 actual: actual as u32,
37 }
38 }
39 velesdb_core::Error::CollectionNotFound(name) => VelesError::Collection {
40 message: format!("Collection not found: {name}"),
41 },
42 velesdb_core::Error::CollectionExists(name) => VelesError::Collection {
43 message: format!("Collection already exists: {name}"),
44 },
45 other => VelesError::Database {
46 message: other.to_string(),
47 },
48 }
49 }
50}
51
52#[derive(Debug, Clone, Copy, uniffi::Enum)]
58pub enum DistanceMetric {
59 Cosine,
61 Euclidean,
63 DotProduct,
65 Hamming,
67 Jaccard,
69}
70
71impl From<DistanceMetric> for CoreDistanceMetric {
72 fn from(metric: DistanceMetric) -> Self {
73 match metric {
74 DistanceMetric::Cosine => CoreDistanceMetric::Cosine,
75 DistanceMetric::Euclidean => CoreDistanceMetric::Euclidean,
76 DistanceMetric::DotProduct => CoreDistanceMetric::DotProduct,
77 DistanceMetric::Hamming => CoreDistanceMetric::Hamming,
78 DistanceMetric::Jaccard => CoreDistanceMetric::Jaccard,
79 }
80 }
81}
82
83#[derive(Debug, Clone, Copy, uniffi::Enum)]
85pub enum StorageMode {
86 Full,
88 Sq8,
90 Binary,
92}
93
94impl From<StorageMode> for velesdb_core::StorageMode {
95 fn from(mode: StorageMode) -> Self {
96 match mode {
97 StorageMode::Full => velesdb_core::StorageMode::Full,
98 StorageMode::Sq8 => velesdb_core::StorageMode::SQ8,
99 StorageMode::Binary => velesdb_core::StorageMode::Binary,
100 }
101 }
102}
103
104#[derive(Debug, Clone, uniffi::Enum)]
106pub enum FusionStrategy {
107 Average,
109 Maximum,
111 Rrf {
113 k: u32,
115 },
116 Weighted {
118 avg_weight: f32,
120 max_weight: f32,
122 hit_weight: f32,
124 },
125}
126
127impl From<FusionStrategy> for CoreFusionStrategy {
128 fn from(strategy: FusionStrategy) -> Self {
129 match strategy {
130 FusionStrategy::Average => CoreFusionStrategy::Average,
131 FusionStrategy::Maximum => CoreFusionStrategy::Maximum,
132 FusionStrategy::Rrf { k } => CoreFusionStrategy::RRF { k },
133 FusionStrategy::Weighted {
134 avg_weight,
135 max_weight,
136 hit_weight,
137 } => CoreFusionStrategy::Weighted {
138 avg_weight,
139 max_weight,
140 hit_weight,
141 },
142 }
143 }
144}
145
146impl Default for FusionStrategy {
147 fn default() -> Self {
148 Self::Rrf { k: 60 }
149 }
150}
151
152#[derive(Debug, Clone, uniffi::Record)]
161pub struct VelesSparseVector {
162 pub indices: Vec<u32>,
164 pub values: Vec<f32>,
166}
167
168#[derive(Debug, Clone, uniffi::Record)]
170pub struct PqTrainConfig {
171 pub m: u32,
173 pub k: u32,
175 pub opq: bool,
177}
178
179#[derive(Debug, Clone, uniffi::Record)]
181pub struct SearchResult {
182 pub id: u64,
184 pub score: f32,
186}
187
188#[derive(Debug, Clone, uniffi::Record)]
190pub struct VelesPoint {
191 pub id: u64,
193 pub vector: Vec<f32>,
195 pub payload: Option<String>,
197}
198
199#[derive(Debug, Clone, uniffi::Record)]
201pub struct IndividualSearchRequest {
202 pub vector: Vec<f32>,
204 pub top_k: u32,
206 pub filter: Option<String>,
208}
209
210#[derive(Debug, Clone, uniffi::Record)]
212pub struct MobileCollectionStats {
213 pub total_points: u64,
215 pub payload_size_bytes: u64,
217 pub row_count: u64,
219 pub deleted_count: u64,
221 pub avg_row_size_bytes: u64,
223 pub total_size_bytes: u64,
225 pub field_stats_count: u32,
227 pub column_stats_count: u32,
229 pub index_stats_count: u32,
231}
232
233impl From<velesdb_core::collection::stats::CollectionStats> for MobileCollectionStats {
234 fn from(stats: velesdb_core::collection::stats::CollectionStats) -> Self {
235 Self {
236 total_points: stats.total_points,
237 payload_size_bytes: stats.payload_size_bytes,
238 row_count: stats.row_count,
239 deleted_count: stats.deleted_count,
240 avg_row_size_bytes: stats.avg_row_size_bytes,
241 total_size_bytes: stats.total_size_bytes,
242 field_stats_count: u32::try_from(stats.field_stats.len()).unwrap_or(u32::MAX),
243 column_stats_count: u32::try_from(stats.column_stats.len()).unwrap_or(u32::MAX),
244 index_stats_count: u32::try_from(stats.index_stats.len()).unwrap_or(u32::MAX),
245 }
246 }
247}
248
249#[derive(Debug, Clone, uniffi::Record)]
251pub struct MobileIndexInfo {
252 pub label: String,
254 pub property: String,
256 pub index_type: String,
258 pub cardinality: u64,
260 pub memory_bytes: u64,
262}
263
264impl From<velesdb_core::IndexInfo> for MobileIndexInfo {
265 fn from(value: velesdb_core::IndexInfo) -> Self {
266 Self {
267 label: value.label,
268 property: value.property,
269 index_type: value.index_type,
270 cardinality: u64::try_from(value.cardinality).unwrap_or(u64::MAX),
271 memory_bytes: u64::try_from(value.memory_bytes).unwrap_or(u64::MAX),
272 }
273 }
274}