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
impl EmbedVec
Sourcepub async fn new(
dim: usize,
distance: Distance,
m: usize,
ef_construction: usize,
) -> Result<Self>
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();
}Sourcepub async fn with_persistence(
path: impl AsRef<Path>,
dim: usize,
distance: Distance,
m: usize,
ef_construction: usize,
) -> Result<Self>
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)
Sourcepub async fn with_backend(
config: BackendConfig,
dim: usize,
distance: Distance,
m: usize,
ef_construction: usize,
) -> Result<Self>
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
Sourcepub fn new_internal(
dim: usize,
distance: Distance,
m: usize,
ef_construction: usize,
quantization: Quantization,
persistence_config: Option<BackendConfig>,
) -> Result<Self>
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)
Sourcepub fn builder() -> EmbedVecBuilder
pub fn builder() -> EmbedVecBuilder
Get a builder for configuring EmbedVec
Sourcepub async fn add_many(
&mut self,
vectors: &[Vec<f32>],
payloads: Vec<impl Into<Metadata>>,
) -> Result<()>
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 vectorspayloads- Associated metadata for each vector
Sourcepub fn add_internal(
&mut self,
vector: &[f32],
payload: Metadata,
) -> Result<usize>
pub fn add_internal( &mut self, vector: &[f32], payload: Metadata, ) -> Result<usize>
Internal add implementation (public for Python bindings)
Sourcepub async fn search(
&self,
query: &[f32],
k: usize,
ef_search: usize,
filter: Option<FilterExpr>,
) -> Result<Vec<Hit>>
pub async fn search( &self, query: &[f32], k: usize, ef_search: usize, filter: Option<FilterExpr>, ) -> Result<Vec<Hit>>
Sourcepub fn search_internal(
&self,
query: &[f32],
k: usize,
ef_search: usize,
filter: Option<FilterExpr>,
) -> Result<Vec<Hit>>
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)
Sourcepub fn quantization(&self) -> &Quantization
pub fn quantization(&self) -> &Quantization
Get current quantization mode
Sourcepub async fn set_quantization(&mut self, quant: Quantization) -> Result<()>
pub async fn set_quantization(&mut self, quant: Quantization) -> Result<()>
Set quantization mode (requires re-indexing)
Auto Trait Implementations§
impl Freeze for EmbedVec
impl !RefUnwindSafe for EmbedVec
impl Send for EmbedVec
impl Sync for EmbedVec
impl Unpin for EmbedVec
impl !UnwindSafe for EmbedVec
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> 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