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
impl Collection
Sourcepub unsafe fn as_raw(&self) -> *mut zvec_collection_t
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.
Sourcepub unsafe fn from_raw(handle: *mut zvec_collection_t) -> Self
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.
Sourcepub fn create_and_open(
path: &str,
schema: &CollectionSchema,
options: Option<&CollectionOptions>,
) -> Result<Self>
pub fn create_and_open( path: &str, schema: &CollectionSchema, options: Option<&CollectionOptions>, ) -> Result<Self>
Creates a new collection and opens it.
Sourcepub fn open(path: &str, options: Option<&CollectionOptions>) -> Result<Self>
pub fn open(path: &str, options: Option<&CollectionOptions>) -> Result<Self>
Opens an existing collection.
Sourcepub fn schema(&self) -> Result<CollectionSchema>
pub fn schema(&self) -> Result<CollectionSchema>
Returns the collection schema.
Sourcepub fn stats(&self) -> Result<CollectionStats>
pub fn stats(&self) -> Result<CollectionStats>
Returns collection statistics.
Sourcepub fn insert(&self, docs: &[&Doc]) -> Result<WriteResult>
pub fn insert(&self, docs: &[&Doc]) -> Result<WriteResult>
Inserts documents into the collection.
Sourcepub fn update(&self, docs: &[&Doc]) -> Result<WriteResult>
pub fn update(&self, docs: &[&Doc]) -> Result<WriteResult>
Updates documents in the collection.
Sourcepub fn upsert(&self, docs: &[&Doc]) -> Result<WriteResult>
pub fn upsert(&self, docs: &[&Doc]) -> Result<WriteResult>
Inserts or updates documents (upsert).
Sourcepub fn delete(&self, pks: &[&str]) -> Result<WriteResult>
pub fn delete(&self, pks: &[&str]) -> Result<WriteResult>
Deletes documents by primary keys.
Sourcepub fn delete_by_filter(&self, filter: &str) -> Result<()>
pub fn delete_by_filter(&self, filter: &str) -> Result<()>
Deletes documents matching a filter expression.
Sourcepub fn query(&self, query: &SearchQuery) -> Result<Vec<Doc>>
pub fn query(&self, query: &SearchQuery) -> Result<Vec<Doc>>
Performs a vector similarity search.
Sourcepub fn multi_query(&self, query: &MultiQuery) -> Result<Vec<Doc>>
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).
Sourcepub fn fetch(&self, pks: &[&str]) -> Result<Vec<Doc>>
pub fn fetch(&self, pks: &[&str]) -> Result<Vec<Doc>>
Fetches documents by primary keys, returning all fields including vectors.
Sourcepub fn fetch_with_options(
&self,
pks: &[&str],
output_fields: Option<&[&str]>,
include_vector: bool,
) -> Result<Vec<Doc>>
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.
Sourcepub fn iter(&self) -> Result<DocIterator<'_>>
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.
Sourcepub fn iter_with_options(
&self,
output_fields: Option<&[&str]>,
include_vector: bool,
) -> Result<DocIterator<'_>>
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;Nonereturns 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.
Sourcepub fn create_index(&self, field_name: &str, params: &IndexParams) -> Result<()>
pub fn create_index(&self, field_name: &str, params: &IndexParams) -> Result<()>
Creates an index on a field.
Sourcepub fn drop_index(&self, field_name: &str) -> Result<()>
pub fn drop_index(&self, field_name: &str) -> Result<()>
Drops an index from a field.
Sourcepub fn optimize(&self) -> Result<()>
pub fn optimize(&self) -> Result<()>
Optimizes the collection (rebuild indexes, merge segments, etc.).
Sourcepub fn add_column(
&self,
field_schema: &FieldSchema,
default_expr: Option<&str>,
) -> Result<()>
pub fn add_column( &self, field_schema: &FieldSchema, default_expr: Option<&str>, ) -> Result<()>
Adds a column to the collection.
Sourcepub fn drop_column(&self, name: &str) -> Result<()>
pub fn drop_column(&self, name: &str) -> Result<()>
Drops a column from the collection.