use velesdb_core::DistanceMetric as CoreDistanceMetric;
use velesdb_core::FusionStrategy as CoreFusionStrategy;
#[derive(Debug, thiserror::Error, uniffi::Error)]
pub enum VelesError {
#[error("Database error: {message}")]
Database { message: String },
#[error("Collection error: {message}")]
Collection { message: String },
#[error("Dimension mismatch: expected {expected}, got {actual}")]
DimensionMismatch { expected: u32, actual: u32 },
}
impl From<velesdb_core::Error> for VelesError {
fn from(err: velesdb_core::Error) -> Self {
match err {
velesdb_core::Error::DimensionMismatch { expected, actual } =>
{
#[allow(clippy::cast_possible_truncation)]
VelesError::DimensionMismatch {
expected: expected as u32,
actual: actual as u32,
}
}
velesdb_core::Error::CollectionNotFound(name) => VelesError::Collection {
message: format!("Collection not found: {name}"),
},
velesdb_core::Error::CollectionExists(name) => VelesError::Collection {
message: format!("Collection already exists: {name}"),
},
other => VelesError::Database {
message: other.to_string(),
},
}
}
}
#[derive(Debug, Clone, Copy, uniffi::Enum)]
pub enum DistanceMetric {
Cosine,
Euclidean,
DotProduct,
Hamming,
Jaccard,
}
impl From<DistanceMetric> for CoreDistanceMetric {
fn from(metric: DistanceMetric) -> Self {
match metric {
DistanceMetric::Cosine => CoreDistanceMetric::Cosine,
DistanceMetric::Euclidean => CoreDistanceMetric::Euclidean,
DistanceMetric::DotProduct => CoreDistanceMetric::DotProduct,
DistanceMetric::Hamming => CoreDistanceMetric::Hamming,
DistanceMetric::Jaccard => CoreDistanceMetric::Jaccard,
}
}
}
#[derive(Debug, Clone, Copy, uniffi::Enum)]
pub enum StorageMode {
Full,
Sq8,
Binary,
}
impl From<StorageMode> for velesdb_core::StorageMode {
fn from(mode: StorageMode) -> Self {
match mode {
StorageMode::Full => velesdb_core::StorageMode::Full,
StorageMode::Sq8 => velesdb_core::StorageMode::SQ8,
StorageMode::Binary => velesdb_core::StorageMode::Binary,
}
}
}
#[derive(Debug, Clone, uniffi::Enum)]
pub enum FusionStrategy {
Average,
Maximum,
Rrf {
k: u32,
},
Weighted {
avg_weight: f32,
max_weight: f32,
hit_weight: f32,
},
}
impl From<FusionStrategy> for CoreFusionStrategy {
fn from(strategy: FusionStrategy) -> Self {
match strategy {
FusionStrategy::Average => CoreFusionStrategy::Average,
FusionStrategy::Maximum => CoreFusionStrategy::Maximum,
FusionStrategy::Rrf { k } => CoreFusionStrategy::RRF { k },
FusionStrategy::Weighted {
avg_weight,
max_weight,
hit_weight,
} => CoreFusionStrategy::Weighted {
avg_weight,
max_weight,
hit_weight,
},
}
}
}
impl Default for FusionStrategy {
fn default() -> Self {
Self::Rrf { k: 60 }
}
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct VelesSparseVector {
pub indices: Vec<u32>,
pub values: Vec<f32>,
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct PqTrainConfig {
pub m: u32,
pub k: u32,
pub opq: bool,
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct SearchResult {
pub id: u64,
pub score: f32,
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct VelesPoint {
pub id: u64,
pub vector: Vec<f32>,
pub payload: Option<String>,
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct IndividualSearchRequest {
pub vector: Vec<f32>,
pub top_k: u32,
pub filter: Option<String>,
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct MobileCollectionStats {
pub total_points: u64,
pub payload_size_bytes: u64,
pub row_count: u64,
pub deleted_count: u64,
pub avg_row_size_bytes: u64,
pub total_size_bytes: u64,
pub field_stats_count: u32,
pub column_stats_count: u32,
pub index_stats_count: u32,
}
impl From<velesdb_core::collection::stats::CollectionStats> for MobileCollectionStats {
fn from(stats: velesdb_core::collection::stats::CollectionStats) -> Self {
Self {
total_points: stats.total_points,
payload_size_bytes: stats.payload_size_bytes,
row_count: stats.row_count,
deleted_count: stats.deleted_count,
avg_row_size_bytes: stats.avg_row_size_bytes,
total_size_bytes: stats.total_size_bytes,
field_stats_count: u32::try_from(stats.field_stats.len()).unwrap_or(u32::MAX),
column_stats_count: u32::try_from(stats.column_stats.len()).unwrap_or(u32::MAX),
index_stats_count: u32::try_from(stats.index_stats.len()).unwrap_or(u32::MAX),
}
}
}
#[derive(Debug, Clone, uniffi::Record)]
pub struct MobileIndexInfo {
pub label: String,
pub property: String,
pub index_type: String,
pub cardinality: u64,
pub memory_bytes: u64,
}
impl From<velesdb_core::IndexInfo> for MobileIndexInfo {
fn from(value: velesdb_core::IndexInfo) -> Self {
Self {
label: value.label,
property: value.property,
index_type: value.index_type,
cardinality: u64::try_from(value.cardinality).unwrap_or(u64::MAX),
memory_bytes: u64::try_from(value.memory_bytes).unwrap_or(u64::MAX),
}
}
}