pub struct VectorSearchEngine { /* private fields */ }Expand description
VectorSearchEngine with HNSW indexing and fastembed embeddings
Features:
- Pure Rust embeddings via fastembed (no Python dependency)
- HNSW index for O(log n) approximate nearest neighbor search
- Background indexing with async channel-based processing
- Multi-tenant support with tenant isolation
- Configurable similarity thresholds
Implementations§
Source§impl VectorSearchEngine
impl VectorSearchEngine
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a VectorSearchEngine without the embedding model (for testing)
pub fn with_config(config: VectorSearchEngineConfig) -> Result<Self>
Sourcepub fn config(&self) -> &VectorSearchEngineConfig
pub fn config(&self) -> &VectorSearchEngineConfig
Get the engine configuration
pub fn embed_text(&self, _text: &str) -> Result<Vec<f32>>
Sourcepub fn embed_event(&self, payload: &Value) -> Result<Vec<f32>>
pub fn embed_event(&self, payload: &Value) -> Result<Vec<f32>>
Generate embedding from an event payload
Extracts text content from the event payload and generates an embedding. Handles various payload structures by extracting relevant text fields.
Sourcepub async fn index_event(
&self,
event_id: Uuid,
tenant_id: &str,
embedding: Vec<f32>,
source_text: Option<String>,
) -> Result<()>
pub async fn index_event( &self, event_id: Uuid, tenant_id: &str, embedding: Vec<f32>, source_text: Option<String>, ) -> Result<()>
Index an event with its embedding
Sourcepub fn search_similar(
&self,
query: &SimilarityQuery,
) -> Result<Vec<SimilarityResult>>
pub fn search_similar( &self, query: &SimilarityQuery, ) -> Result<Vec<SimilarityResult>>
Fallback search using brute force (when HNSW not available or for testing)
Sourcepub fn start_background_indexer(&mut self) -> Sender<IndexRequest>
pub fn start_background_indexer(&mut self) -> Sender<IndexRequest>
Start background indexing worker
Returns a sender that can be used to submit index requests. The worker runs asynchronously and processes requests in batches.
Sourcepub fn delete_by_tenant(&self, tenant_id: &str) -> Result<usize>
pub fn delete_by_tenant(&self, tenant_id: &str) -> Result<usize>
Delete all vectors for a tenant
Sourcepub fn health_check(&self) -> Result<()>
pub fn health_check(&self) -> Result<()>
Health check
Auto Trait Implementations§
impl Freeze for VectorSearchEngine
impl !RefUnwindSafe for VectorSearchEngine
impl Send for VectorSearchEngine
impl Sync for VectorSearchEngine
impl Unpin for VectorSearchEngine
impl !UnwindSafe for VectorSearchEngine
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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