Collection

Struct Collection 

Source
pub struct Collection { /* private fields */ }
Expand description

A collection of vectors with associated metadata.

Implementations§

Source§

impl Collection

Source

pub fn create( path: PathBuf, dimension: usize, metric: DistanceMetric, ) -> Result<Self>

Creates a new collection at the specified path.

§Errors

Returns an error if the directory cannot be created or the config cannot be saved.

Source

pub fn create_with_options( path: PathBuf, dimension: usize, metric: DistanceMetric, storage_mode: StorageMode, ) -> Result<Self>

Creates a new collection with custom storage options.

§Arguments
  • path - Path to the collection directory
  • dimension - Vector dimension
  • metric - Distance metric
  • storage_mode - Vector storage mode (Full, SQ8, Binary)
§Errors

Returns an error if the directory cannot be created or the config cannot be saved.

Source

pub fn open(path: PathBuf) -> Result<Self>

Opens an existing collection from the specified path.

§Errors

Returns an error if the config file cannot be read or parsed.

Source

pub fn config(&self) -> CollectionConfig

Returns the collection configuration.

Source

pub fn upsert(&self, points: impl IntoIterator<Item = Point>) -> Result<()>

Inserts or updates points in the collection.

Accepts any iterator of points (Vec, slice, array, etc.)

§Errors

Returns an error if any point has a mismatched dimension.

Source

pub fn upsert_bulk(&self, points: &[Point]) -> Result<usize>

Bulk insert optimized for high-throughput import.

§Performance

This method is optimized for bulk loading:

  • Uses sequential HNSW insertion (reliable, no rayon conflicts)
  • Single flush at the end (not per-point)
  • No HNSW index save (deferred for performance)
  • ~20-30% faster than previous parallel approach on large batches (5000+)
  • Benchmark: 1.5-2.1 Kvec/s on 768D vectors
§Errors

Returns an error if any point has a mismatched dimension.

Source

pub fn get(&self, ids: &[u64]) -> Vec<Option<Point>>

Retrieves points by their IDs.

Source

pub fn delete(&self, ids: &[u64]) -> Result<()>

Deletes points by their IDs.

§Errors

Returns an error if storage operations fail.

Source

pub fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>

Searches for the k nearest neighbors of the query vector.

Uses HNSW index for fast approximate nearest neighbor search.

§Errors

Returns an error if the query vector dimension doesn’t match the collection.

Source

pub fn search_ids(&self, query: &[f32], k: usize) -> Result<Vec<(u64, f32)>>

Performs fast vector similarity search returning only IDs and scores.

Perf: This is ~3-5x faster than search() because it skips vector/payload retrieval. Use this when you only need IDs and scores, not full point data.

§Arguments
  • query - Query vector
  • k - Maximum number of results to return
§Returns

Vector of (id, score) tuples sorted by similarity.

§Errors

Returns an error if the query vector dimension doesn’t match the collection.

Source

pub fn search_batch_parallel( &self, queries: &[&[f32]], k: usize, ) -> Result<Vec<Vec<SearchResult>>>

Performs batch vector similarity search in parallel using rayon.

Perf: This is significantly faster than calling search in a loop because it parallelizes across CPU cores and amortizes lock overhead.

§Arguments
  • queries - Slice of query vectors
  • k - Maximum number of results per query
§Returns

Vector of search results for each query, with full point data.

§Errors

Returns an error if any query vector dimension doesn’t match the collection.

Source

pub fn len(&self) -> usize

Returns the number of points in the collection. Perf: Uses cached point_count from config instead of acquiring storage lock

Source

pub fn is_empty(&self) -> bool

Returns true if the collection is empty. Perf: Uses cached point_count from config instead of acquiring storage lock

Source

pub fn flush(&self) -> Result<()>

Saves the collection configuration and index to disk.

§Errors

Returns an error if storage operations fail.

Performs full-text search using BM25.

§Arguments
  • query - Text query to search for
  • k - Maximum number of results to return
§Returns

Vector of search results sorted by BM25 score (descending).

Performs hybrid search combining vector similarity and full-text search.

Uses Reciprocal Rank Fusion (RRF) to combine results from both searches.

§Arguments
  • vector_query - Query vector for similarity search
  • text_query - Text query for BM25 search
  • k - Maximum number of results to return
  • vector_weight - Weight for vector results (0.0-1.0, default 0.5)
§Errors

Returns an error if the query vector dimension doesn’t match.

Trait Implementations§

Source§

impl Clone for Collection

Source§

fn clone(&self) -> Collection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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