pub struct Collection { /* private fields */ }Expand description
A named collection of vectors.
Each collection has:
- A unique name
- Fixed vector dimensions
- A distance metric for similarity calculations
- An HNSW index for fast approximate nearest neighbor search
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn new(
name: String,
dimensions: usize,
metric: DistanceMetric,
hnsw_config: HnswConfig,
) -> Result<Self>
pub fn new( name: String, dimensions: usize, metric: DistanceMetric, hnsw_config: HnswConfig, ) -> Result<Self>
Create a new collection.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the vector dimensions.
Sourcepub fn metric(&self) -> DistanceMetric
pub fn metric(&self) -> DistanceMetric
Get the distance metric.
Sourcepub fn insert(
&self,
id: &str,
vector: &[f32],
metadata: Option<VectorMetadata>,
) -> Result<()>
pub fn insert( &self, id: &str, vector: &[f32], metadata: Option<VectorMetadata>, ) -> Result<()>
Insert a vector.
Sourcepub fn insert_batch<'a, I>(&self, vectors: I) -> Result<usize>
pub fn insert_batch<'a, I>(&self, vectors: I) -> Result<usize>
Insert multiple vectors in batch.
Sourcepub fn update(
&self,
id: &str,
vector: &[f32],
metadata: Option<VectorMetadata>,
) -> Result<()>
pub fn update( &self, id: &str, vector: &[f32], metadata: Option<VectorMetadata>, ) -> Result<()>
Update a vector.
Sourcepub fn delete_batch(&self, ids: &[&str]) -> Result<usize>
pub fn delete_batch(&self, ids: &[&str]) -> Result<usize>
Delete multiple vectors.
Sourcepub fn search(&self, query: &[f32], limit: usize) -> Result<Vec<SearchResult>>
pub fn search(&self, query: &[f32], limit: usize) -> Result<Vec<SearchResult>>
Search for similar vectors.
Sourcepub fn search_with_threshold(
&self,
query: &[f32],
limit: usize,
min_score: f32,
) -> Result<Vec<SearchResult>>
pub fn search_with_threshold( &self, query: &[f32], limit: usize, min_score: f32, ) -> Result<Vec<SearchResult>>
Search with a minimum score threshold.
Sourcepub fn stats(&self) -> CollectionStats
pub fn stats(&self) -> CollectionStats
Get collection statistics.
Sourcepub fn hnsw_config(&self) -> &HnswConfig
pub fn hnsw_config(&self) -> &HnswConfig
Get the HNSW configuration.
Sourcepub fn export_all(&self) -> Vec<(String, Vec<f32>, Option<VectorMetadata>)>
pub fn export_all(&self) -> Vec<(String, Vec<f32>, Option<VectorMetadata>)>
Export all vectors for persistence.
Returns a vector of (id, vector, metadata) tuples.
Auto Trait Implementations§
impl !RefUnwindSafe for Collection
impl !UnwindSafe for Collection
impl Freeze for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl UnsafeUnpin for Collection
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