High-level API for zvec collections.
Example
schema =
Zvec.Schema.new("test")
|> Zvec.Schema.add_vector("vec", 4, index: %{type: :hnsw, metric_type: :cosine})
{:ok, col} = Zvec.Collection.create_and_open("/tmp/mydb", schema)
:ok = Zvec.Collection.insert(col, [Zvec.Doc.new("pk1", %{"vec" => vec_binary})])
:ok = Zvec.Collection.optimize(col)
{:ok, results} = Zvec.Collection.query(col, Zvec.Query.vector("vec", [0.1, 0.2, 0.3, 0.4], topk: 1))
Summary
Functions
Create a new collection and open it.
Create an index on a column.
Delete documents by primary keys.
Delete documents matching a filter expression.
Destroy the collection (deletes data on disk).
Drop an index from a column.
Fetch documents by primary keys.
Flush pending writes to disk.
Insert documents into the collection.
Open an existing collection.
Optimize the collection (build ANN indexes, compact segments).
Execute a vector similarity query.
Get the collection schema.
Get collection statistics.
Upsert documents (insert or update if pk exists).
Types
@type ref() :: reference()
Functions
@spec create_and_open(String.t(), Zvec.Schema.t(), keyword()) :: {:ok, ref()} | {:error, {atom(), String.t()}}
Create a new collection and open it.
Options
:read_only- open read-only (default:false):enable_mmap- enable memory mapping (default:true):max_buffer_size- write buffer size in bytes (default: 64MB)
Create an index on a column.
Delete documents by primary keys.
Delete documents matching a filter expression.
Destroy the collection (deletes data on disk).
Drop an index from a column.
@spec fetch(ref(), [String.t()]) :: {:ok, [Zvec.Doc.t()]} | {:error, {atom(), String.t()}}
Fetch documents by primary keys.
Flush pending writes to disk.
@spec insert(ref(), [Zvec.Doc.t()]) :: :ok | {:error, {atom(), String.t()}}
Insert documents into the collection.
Returns :ok if all documents were inserted successfully.
Open an existing collection.
Optimize the collection (build ANN indexes, compact segments).
@spec query(ref(), map()) :: {:ok, [Zvec.Doc.t()]} | {:error, {atom(), String.t()}}
Execute a vector similarity query.
Returns {:ok, results} where each result is a Zvec.Doc with :pk, :score, and :fields.
Get the collection schema.
Get collection statistics.
@spec upsert(ref(), [Zvec.Doc.t()]) :: :ok | {:error, {atom(), String.t()}}
Upsert documents (insert or update if pk exists).
Returns :ok if all documents were upserted successfully.