pub struct SemanticSearchAdapter { /* private fields */ }Expand description
Adapter for sparc-style semantic file search.
sparc needs to locate relevant source files given a natural-language query string. This adapter stores one embedding per file (derived externally, e.g. from an ONNX all-MiniLM model) and retrieves the closest matches using HNSW approximate nearest-neighbour search.
§Example
use ruvector_core::integration::SemanticSearchAdapter;
let mut adapter = SemanticSearchAdapter::new(384, "./sparc_index.db").unwrap();
// Index source files (embeddings produced by your embedding pipeline)
adapter.index_file("src/auth/service.rs", "authentication service", &[0.0f32; 384]).unwrap();
adapter.index_file("src/user/model.rs", "user data model", &[0.1f32; 384]).unwrap();
// Query with a natural-language description
let results = adapter.search("jwt token validation", &[0.05f32; 384], 5).unwrap();
for r in results {
println!(" {} (score={:.4})", r.id, r.score);
}Implementations§
Source§impl SemanticSearchAdapter
impl SemanticSearchAdapter
Sourcepub fn new(dimensions: usize, storage_path: impl Into<String>) -> Result<Self>
pub fn new(dimensions: usize, storage_path: impl Into<String>) -> Result<Self>
Create a new adapter.
dimensions is the embedding dimension of your model (e.g. 384 for
all-MiniLM-L6-v2, 768 for BERT-base).
Sourcepub fn index_file(
&self,
path: impl Into<String>,
description: impl Into<String>,
embedding: &[f32],
) -> Result<String>
pub fn index_file( &self, path: impl Into<String>, description: impl Into<String>, embedding: &[f32], ) -> Result<String>
Index a source file.
The file path is used as the vector ID so look-ups are O(1).
description is stored in metadata for debugging / display.
embedding must have the same length as the adapter’s dimensions.
Sourcepub fn remove_file(&self, path: &str) -> Result<bool>
pub fn remove_file(&self, path: &str) -> Result<bool>
Remove a previously indexed file.
Sourcepub fn search(
&self,
_query_text: &str,
query_embedding: &[f32],
k: usize,
) -> Result<Vec<SearchResult>>
pub fn search( &self, _query_text: &str, query_embedding: &[f32], k: usize, ) -> Result<Vec<SearchResult>>
Search for source files semantically related to query_embedding.
Returns up to k results sorted by ascending cosine distance
(most relevant first). Each SearchResult has .id set to the
file path and .metadata containing the description.
Sourcepub fn list_files(&self) -> Result<Vec<String>>
pub fn list_files(&self) -> Result<Vec<String>>
List all indexed file paths.
Auto Trait Implementations§
impl !RefUnwindSafe for SemanticSearchAdapter
impl !UnwindSafe for SemanticSearchAdapter
impl Freeze for SemanticSearchAdapter
impl Send for SemanticSearchAdapter
impl Sync for SemanticSearchAdapter
impl Unpin for SemanticSearchAdapter
impl UnsafeUnpin for SemanticSearchAdapter
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> 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>
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