pub struct FannAdapter { /* private fields */ }Expand description
Adapter that lets ruv-FANN store and retrieve layer-weight embeddings.
Each neural-network layer can be fingerprinted as a flat f32 embedding
(e.g. the flattened weight matrix or its PCA projection). Storing these
fingerprints in RuVector enables fast recall of “similar layers” across
model checkpoints.
§Example
use ruvector_core::integration::FannAdapter;
let mut adapter = FannAdapter::new(128, "./fann_index.db").unwrap();
adapter.store_layer("model_v1/layer_0", &[0.1f32; 128], None).unwrap();
let similar = adapter.find_similar_layers(&[0.1f32; 128], 5).unwrap();Implementations§
Source§impl FannAdapter
impl FannAdapter
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 backed by a RuVector database.
dimensions must match the size of the layer embeddings you intend
to store. Cosine distance is used because weight embeddings are
typically meaningful up to scale.
Sourcepub fn store_layer(
&self,
layer_id: impl Into<String>,
embedding: &[f32],
metadata: Option<HashMap<String, Value>>,
) -> Result<String>
pub fn store_layer( &self, layer_id: impl Into<String>, embedding: &[f32], metadata: Option<HashMap<String, Value>>, ) -> Result<String>
Store a layer embedding identified by layer_id.
metadata can carry arbitrary JSON-serialisable key-value pairs
(e.g. model name, checkpoint step, layer type).
Sourcepub fn find_similar_layers(
&self,
query: &[f32],
k: usize,
) -> Result<Vec<SearchResult>>
pub fn find_similar_layers( &self, query: &[f32], k: usize, ) -> Result<Vec<SearchResult>>
Find the k most similar layer embeddings to query.
Returns results sorted by ascending cosine distance.
Sourcepub fn find_similar_layers_filtered(
&self,
query: &[f32],
k: usize,
filter: HashMap<String, Value>,
) -> Result<Vec<SearchResult>>
pub fn find_similar_layers_filtered( &self, query: &[f32], k: usize, filter: HashMap<String, Value>, ) -> Result<Vec<SearchResult>>
Find similar layers with a filter on metadata fields.
Only results where every (key, value) in filter matches are returned.
Sourcepub fn delete_layer(&self, layer_id: &str) -> Result<bool>
pub fn delete_layer(&self, layer_id: &str) -> Result<bool>
Delete a layer embedding by ID.
Auto Trait Implementations§
impl !RefUnwindSafe for FannAdapter
impl !UnwindSafe for FannAdapter
impl Freeze for FannAdapter
impl Send for FannAdapter
impl Sync for FannAdapter
impl Unpin for FannAdapter
impl UnsafeUnpin for FannAdapter
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