use crate::superfile::{
builder::FtsConfig,
vector::{builder::VectorConfig, distance::Metric},
};
const DEFAULT_ROT_SEED: u64 = 0x5EED_5EED_5EED_5EED;
#[derive(Debug, Clone)]
struct VectorIndex {
column: String,
dim: usize,
n_cent: usize,
metric: Metric,
}
#[derive(Debug, Clone, Default)]
pub struct IndexSpec {
fts: Vec<String>,
vectors: Vec<VectorIndex>,
}
impl IndexSpec {
pub fn new() -> Self {
Self::default()
}
pub fn fts(mut self, column: impl Into<String>) -> Self {
self.fts.push(column.into());
self
}
pub fn vector(
mut self,
column: impl Into<String>,
dim: usize,
n_cent: usize,
metric: Metric,
) -> Self {
self.vectors.push(VectorIndex {
column: column.into(),
dim,
n_cent,
metric,
});
self
}
pub(crate) fn fts_columns(&self) -> &[String] {
&self.fts
}
pub(crate) fn to_configs(&self) -> (Vec<FtsConfig>, Vec<VectorConfig>) {
let fts = self
.fts
.iter()
.map(|column| FtsConfig {
column: column.clone(),
})
.collect();
let vectors = self
.vectors
.iter()
.map(|v| {
VectorConfig::new(
v.column.clone(),
v.dim,
v.n_cent,
DEFAULT_ROT_SEED,
v.metric,
)
})
.collect();
(fts, vectors)
}
pub(crate) fn has_fts(&self) -> bool {
!self.fts.is_empty()
}
}