use crate::dataset::DEFAULT_INDEX_CACHE_SIZE;
use crate::index::cache::IndexCache;
#[derive(Clone)]
pub struct Session {
pub(crate) index_cache: IndexCache,
}
impl std::fmt::Debug for Session {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Session()")
}
}
impl Session {
pub fn new(index_cache_size: usize) -> Self {
Self {
index_cache: IndexCache::new(index_cache_size),
}
}
}
impl Default for Session {
fn default() -> Self {
Self {
index_cache: IndexCache::new(DEFAULT_INDEX_CACHE_SIZE),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
datatypes::Schema,
format::Manifest,
index::vector::{
pq::{PQIndex, ProductQuantizer},
MetricType,
},
io::{deletion::LruDeletionVectorStore, ObjectStore},
};
use std::{collections::HashMap, sync::Arc};
#[tokio::test]
async fn test_disable_index_cache() {
let no_cache = Session::new(0);
assert!(no_cache.index_cache.get("abc").is_none());
let schema = Schema {
fields: vec![],
metadata: HashMap::new(),
};
let manifest = Arc::new(Manifest::new(&schema, Arc::new(vec![])));
let object_store = Arc::new(ObjectStore::from_uri("memory://").await.unwrap().0);
let deletion_cache = Arc::new(LruDeletionVectorStore::new(
object_store.clone(),
object_store.as_ref().base_path().clone(),
manifest,
100,
));
let pq = Arc::new(ProductQuantizer::new(1, 8, 1));
let idx = Arc::new(PQIndex::new(pq, MetricType::L2, deletion_cache));
no_cache.index_cache.insert("abc", idx);
assert!(no_cache.index_cache.get("abc").is_none());
assert_eq!(no_cache.index_cache.len(), 0);
}
}