Skip to main content

Collection

Struct Collection 

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

A zvec collection for storing and querying vector data.

Collections are the primary data container in zvec. They hold documents with typed fields and support vector similarity search.

The collection is automatically closed when dropped.

Implementations§

Source§

impl Collection

Source

pub unsafe fn as_raw(&self) -> *mut zvec_collection_t

Returns the raw FFI handle.

§Safety

The caller must not use the handle after the Collection is dropped.

Source

pub unsafe fn from_raw(handle: *mut zvec_collection_t) -> Self

Creates a Collection from a raw FFI handle.

§Safety

The caller must ensure the handle is valid and was created by the zvec C API. The Collection takes ownership and will call zvec_collection_close on drop.

Source

pub fn create_and_open( path: &str, schema: &CollectionSchema, options: Option<&CollectionOptions>, ) -> Result<Self>

Creates a new collection and opens it.

Source

pub fn open(path: &str, options: Option<&CollectionOptions>) -> Result<Self>

Opens an existing collection.

Source

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

Flushes collection data to disk.

Source

pub fn schema(&self) -> Result<CollectionSchema>

Returns the collection schema.

Source

pub fn stats(&self) -> Result<CollectionStats>

Returns collection statistics.

Source

pub fn insert(&self, docs: &[&Doc]) -> Result<WriteResult>

Inserts documents into the collection.

Source

pub fn update(&self, docs: &[&Doc]) -> Result<WriteResult>

Updates documents in the collection.

Source

pub fn upsert(&self, docs: &[&Doc]) -> Result<WriteResult>

Inserts or updates documents (upsert).

Source

pub fn delete(&self, pks: &[&str]) -> Result<WriteResult>

Deletes documents by primary keys.

Source

pub fn delete_by_filter(&self, filter: &str) -> Result<()>

Deletes documents matching a filter expression.

Source

pub fn query(&self, query: &SearchQuery) -> Result<Vec<Doc>>

Performs a vector similarity search.

Source

pub fn multi_query(&self, query: &MultiQuery) -> Result<Vec<Doc>>

Performs a multi-query that combines several sub-queries with a rerank strategy (RRF or weighted).

Source

pub fn fetch(&self, pks: &[&str]) -> Result<Vec<Doc>>

Fetches documents by primary keys, returning all fields including vectors.

Source

pub fn fetch_with_options( &self, pks: &[&str], output_fields: Option<&[&str]>, include_vector: bool, ) -> Result<Vec<Doc>>

Fetches documents by primary keys with control over which fields to return.

Source

pub fn iter(&self) -> Result<DocIterator<'_>>

Creates an iterator over all documents in the collection using default options (all scalar fields, vectors included).

The iterator traverses an isolated snapshot taken at creation time; documents written afterwards are not visible.

Source

pub fn iter_with_options( &self, output_fields: Option<&[&str]>, include_vector: bool, ) -> Result<DocIterator<'_>>

Creates an iterator over all documents with control over which fields to return.

  • output_fields: scalar fields to return; None returns all fields. An empty slice returns no scalar fields (primary key only).
  • include_vector: whether to include vector fields.

The iterator traverses an isolated snapshot taken at creation time; documents written afterwards are not visible. While the iterator is open, schema changes (create/drop index, add/alter/drop column) and destroy are rejected by the C library.

Source

pub fn create_index(&self, field_name: &str, params: &IndexParams) -> Result<()>

Creates an index on a field.

Source

pub fn drop_index(&self, field_name: &str) -> Result<()>

Drops an index from a field.

Source

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

Optimizes the collection (rebuild indexes, merge segments, etc.).

Source

pub fn add_column( &self, field_schema: &FieldSchema, default_expr: Option<&str>, ) -> Result<()>

Adds a column to the collection.

Source

pub fn drop_column(&self, name: &str) -> Result<()>

Drops a column from the collection.

Source

pub fn close(self) -> Result<()>

Closes the collection explicitly.

Trait Implementations§

Source§

impl Drop for Collection

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Collection

Source§

impl Sync for Collection

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.