pub mod operators;
use dashmap::DashMap;
use ruvector_sona::{SonaConfig, SonaEngine};
use std::sync::Arc;
fn engine_key(table_name: &str, dim: u32) -> String {
format!("{}::{}", table_name, dim)
}
static SONA_ENGINES: once_cell::sync::Lazy<DashMap<String, Arc<SonaEngine>>> =
once_cell::sync::Lazy::new(DashMap::new);
const DEFAULT_DIM: u32 = 256;
pub fn get_or_create_engine(table_name: &str) -> Arc<SonaEngine> {
get_or_create_engine_with_dim(table_name, DEFAULT_DIM)
}
pub fn get_or_create_engine_with_dim(table_name: &str, dim: u32) -> Arc<SonaEngine> {
let key = engine_key(table_name, dim);
SONA_ENGINES
.entry(key)
.or_insert_with(|| {
Arc::new(SonaEngine::with_config(SonaConfig {
hidden_dim: dim as usize,
embedding_dim: dim as usize,
..Default::default()
}))
})
.value()
.clone()
}