Collection¶
Zvec::Collection is the primary interface for storing and querying documents. Collections are persistent on-disk databases that hold a schema, vector indexes, and forward storage.
Shared Pointer Wrapper
Rice wraps shared_ptr<Collection> as Std::SharedPtr<zvec::Collection>. Ruby convenience methods (like query_vector) are mixed into this wrapper class automatically.
Class Methods¶
Collection.create_and_open¶
Create a new collection on disk and return an open handle.
| Parameter | Type | Description |
|---|---|---|
path |
String | File system path for the collection |
schema |
CollectionSchema |
Schema defining the collection's fields |
options |
CollectionOptions |
Optional open settings |
Raises Zvec::AlreadyExistsError if the path already exists.
Collection.open¶
Open an existing collection.
Raises Zvec::NotFoundError if the path doesn't exist.
Instance Methods¶
Metadata¶
| Method | Returns | Description |
|---|---|---|
path |
String | Collection's file system path |
schema |
CollectionSchema |
The collection's schema |
stats |
CollectionStats |
Document count and index completeness |
options |
CollectionOptions |
Current collection options |
Write Operations¶
insert(docs)¶
Insert new documents. Returns an array of Status objects.
upsert(docs)¶
Insert or replace documents by primary key.
update(docs)¶
Update existing documents.
delete(pks)¶
Delete documents by primary key. Returns an array of Status objects.
delete_by_filter(filter)¶
Delete all documents matching a filter expression. Raises on error.
Read Operations¶
fetch(pks)¶
Fetch documents by primary key. Returns a hash { pk_string => Doc }. Missing keys are omitted.
query(vector_query)¶
Execute a VectorQuery. Returns an array of Doc objects sorted by distance.
query_vector (convenience)¶
results = col.query_vector(field_name, vector, top_k:, filter: nil,
include_vector: false, query_params: nil, output_fields: nil)
Build and execute a VectorQuery in one call. See VectorQuery for parameter details.
group_by_query(group_query)¶
Execute a GroupByVectorQuery. Returns an array of GroupResult objects.
Lifecycle¶
flush¶
Persist buffered writes to disk.
destroy!¶
Permanently delete the collection and all data from disk.
Schema Modification¶
add_column(field_schema, expression: "", concurrency: 0)¶
Add a new column to the collection.
drop_column(name)¶
Remove a column from the collection.
alter_column(name, rename: "", new_schema: nil, concurrency: 0)¶
Rename or modify a column.
Index Management¶
create_index(column, params, concurrency: 0)¶
Create an index on an existing column.
drop_index(column)¶
Remove an index from a column.
optimize(concurrency: 0)¶
Compact and rebuild indexes.
Module Method¶
Zvec.open_collection¶
Block-form open that yields the collection and flushes on block exit.