pub struct UfpIndex { /* private fields */ }Expand description
Index structure with lock-free concurrent access via DashMap and ANN support
Implementations§
Source§impl UfpIndex
Provides semantic & perceptual retrieval methods
impl UfpIndex
Provides semantic & perceptual retrieval methods
Sourcepub fn search(
&self,
query: &IndexRecord,
mode: QueryMode,
top_k: usize,
) -> Result<Vec<QueryResult>, IndexError>
pub fn search( &self, query: &IndexRecord, mode: QueryMode, top_k: usize, ) -> Result<Vec<QueryResult>, IndexError>
Search for top-k most similar entries.
Source§impl UfpIndex
impl UfpIndex
Sourcepub fn new(cfg: IndexConfig) -> Result<Self, IndexError>
pub fn new(cfg: IndexConfig) -> Result<Self, IndexError>
Initialize or open an index using the configured backend. This will build the backend from the config.
Sourcepub fn with_backend(cfg: IndexConfig, backend: Box<dyn IndexBackend>) -> Self
pub fn with_backend(cfg: IndexConfig, backend: Box<dyn IndexBackend>) -> Self
Build an index with a custom backend (e.g., in-memory for tests). This is useful for dependency injection and testing.
Sourcepub fn semantic_vector_count(&self) -> usize
pub fn semantic_vector_count(&self) -> usize
Get the number of vectors in the semantic index.
Sourcepub fn should_use_ann(&self) -> bool
pub fn should_use_ann(&self) -> bool
Check if ANN search should be used for the current dataset size.
Sourcepub fn rebuild_ann_if_needed(&self)
pub fn rebuild_ann_if_needed(&self)
Rebuild the ANN index if needed. This should be called periodically after batch insertions.
Sourcepub fn quantize(vec: &Array1<f32>, scale: f32) -> QuantizedVec
pub fn quantize(vec: &Array1<f32>, scale: f32) -> QuantizedVec
Quantize float embeddings -> i8 using a raw scale. This is a simple linear quantization with clamping.
Sourcepub fn quantize_with_strategy(
vec: &Array1<f32>,
cfg: &QuantizationConfig,
) -> QuantizedVec
pub fn quantize_with_strategy( vec: &Array1<f32>, cfg: &QuantizationConfig, ) -> QuantizedVec
Quantize using a configured strategy. This allows for different quantization strategies to be used in the future.
Sourcepub fn upsert(&self, rec: &IndexRecord) -> Result<(), IndexError>
pub fn upsert(&self, rec: &IndexRecord) -> Result<(), IndexError>
Insert or update a record. The record is encoded and compressed before being sent to the backend.
Sourcepub fn flush(&self) -> Result<(), IndexError>
pub fn flush(&self) -> Result<(), IndexError>
Flush backend buffers if supported. This is useful for ensuring data is written to disk.
Sourcepub fn get(&self, hash: &str) -> Result<Option<IndexRecord>, IndexError>
pub fn get(&self, hash: &str) -> Result<Option<IndexRecord>, IndexError>
Retrieve a record by hash. The record is decompressed and decoded after being retrieved from the backend.
Sourcepub fn scan(
&self,
visitor: &mut dyn FnMut(&IndexRecord) -> Result<(), IndexError>,
) -> Result<(), IndexError>
pub fn scan( &self, visitor: &mut dyn FnMut(&IndexRecord) -> Result<(), IndexError>, ) -> Result<(), IndexError>
Scan all records in the index. Iterates over all records in the backend, decodes them, and passes them to the visitor.
Sourcepub fn batch_insert(&self, records: &[IndexRecord]) -> Result<(), IndexError>
pub fn batch_insert(&self, records: &[IndexRecord]) -> Result<(), IndexError>
Batch insert multiple records (efficient for large datasets).
This can be much faster than calling upsert in a loop.
Auto Trait Implementations§
impl !Freeze for UfpIndex
impl !RefUnwindSafe for UfpIndex
impl Send for UfpIndex
impl Sync for UfpIndex
impl Unpin for UfpIndex
impl !UnwindSafe for UfpIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more