EmbedVec

Struct EmbedVec 

Source
pub struct EmbedVec {
    pub index: Arc<RwLock<HnswIndex>>,
    pub storage: Arc<RwLock<VectorStorage>>,
    pub metadata: Arc<RwLock<Vec<Metadata>>>,
    /* private fields */
}
Expand description

Main embedded vector database struct

Provides HNSW-based approximate nearest neighbor search with optional E8 lattice quantization for memory efficiency.

Fields§

§index: Arc<RwLock<HnswIndex>>

HNSW index

§storage: Arc<RwLock<VectorStorage>>

Vector storage (raw or quantized)

§metadata: Arc<RwLock<Vec<Metadata>>>

Metadata storage

Implementations§

Source§

impl EmbedVec

Source

pub async fn new( dim: usize, distance: Distance, m: usize, ef_construction: usize, ) -> Result<Self>

Create a new in-memory EmbedVec instance

§Arguments
  • dim - Vector dimension (e.g., 768 for many LLM embeddings)
  • distance - Distance metric (Cosine, Euclidean, DotProduct)
  • m - HNSW M parameter (connections per layer, typically 16-64)
  • ef_construction - HNSW construction parameter (typically 100-500)
§Example
use embedvec::{EmbedVec, Distance};

#[tokio::main]
async fn main() {
    let db = EmbedVec::new(768, Distance::Cosine, 32, 200).await.unwrap();
}
Source

pub async fn with_persistence( path: impl AsRef<Path>, dim: usize, distance: Distance, m: usize, ef_construction: usize, ) -> Result<Self>

Create a new EmbedVec with persistence (uses Sled by default)

Source

pub async fn with_backend( config: BackendConfig, dim: usize, distance: Distance, m: usize, ef_construction: usize, ) -> Result<Self>

Create a new EmbedVec with a specific persistence backend

Source

pub fn new_internal( dim: usize, distance: Distance, m: usize, ef_construction: usize, quantization: Quantization, persistence_config: Option<BackendConfig>, ) -> Result<Self>

Internal constructor (public for Python bindings)

Source

pub fn builder() -> EmbedVecBuilder

Get a builder for configuring EmbedVec

Source

pub async fn add( &mut self, vector: &[f32], payload: impl Into<Metadata>, ) -> Result<usize>

Add a single vector with metadata

§Arguments
  • vector - The embedding vector (must match configured dimension)
  • payload - Associated metadata (JSON-compatible)
§Returns

The assigned vector ID

Source

pub async fn add_many( &mut self, vectors: &[Vec<f32>], payloads: Vec<impl Into<Metadata>>, ) -> Result<()>

Add multiple vectors with metadata in batch

§Arguments
  • vectors - Slice of embedding vectors
  • payloads - Associated metadata for each vector
Source

pub fn add_internal( &mut self, vector: &[f32], payload: Metadata, ) -> Result<usize>

Internal add implementation (public for Python bindings)

Source

pub async fn search( &self, query: &[f32], k: usize, ef_search: usize, filter: Option<FilterExpr>, ) -> Result<Vec<Hit>>

Search for nearest neighbors

§Arguments
  • query - Query vector
  • k - Number of results to return
  • ef_search - Search parameter (higher = better recall, slower)
  • filter - Optional metadata filter expression
§Returns

Vector of Hit results sorted by similarity

Source

pub fn search_internal( &self, query: &[f32], k: usize, ef_search: usize, filter: Option<FilterExpr>, ) -> Result<Vec<Hit>>

Internal search implementation (public for Python bindings)

Source

pub async fn len(&self) -> usize

Get the number of vectors in the database

Source

pub async fn is_empty(&self) -> bool

Check if the database is empty

Source

pub async fn clear(&mut self) -> Result<()>

Clear all vectors and metadata

Source

pub fn quantization(&self) -> &Quantization

Get current quantization mode

Source

pub async fn set_quantization(&mut self, quant: Quantization) -> Result<()>

Set quantization mode (requires re-indexing)

Source

pub fn dimension(&self) -> usize

Get vector dimension

Source

pub fn distance(&self) -> Distance

Get distance metric

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V