Zvec Logo

Single-Vector Search

Single-vector search finds documents most similar to a single query embedding. This is the most common search pattern in vector databases.


Prerequisites

This guide assumes you have opened a collection and have a collection object ready.


VectorQuery

In Zvec, all vector similarity searches are performed by passing one or more VectorQuery objects to the query() method.

Each VectorQuery specifies:

  1. field_name: The name of the vector field to search
  2. Query source (exactly one required):
    • An explicit vector, or
    • a document id (to reuse the stored embedding of an existing document)

    You must provide exactly one of vector or id. Specifying both will raise an error.

  3. param (optional): Index-specific query parameters (e.g., ef for HNSW).


To perform a single-vector similarity search, call the query() method with a single VectorQuery object.

All queries return a list[Doc] containing the top-k most similar documents, sorted by relevance score.

Each Doc object includes:

  1. id: The document identifier.
  2. score: The similarity score.
  3. vectors: A dictionary of vector embeddings.
    This is only populated if include_vector=True is passed in the query.
  4. fields: A dictionary of scalar field values.
    By default, all scalar fields are returned; this can be restricted using the output_fields parameter.

Common Parameters

ParameterDescription
vectorsThe VectorQuery object specifying the query vector and target field.
topkThe number of most similar documents to return.
include_vectorIf True, the returned Doc objects include the full vector embeddings (disabled by default for performance).
output_fieldsAn optional list of scalar field names to include in results. If omitted, all scalar fields are returned.
filterAn optional SQL-like boolean expression to restrict results. See filtered search for details.

The reranker parameter is part of the query() interface but only applies to multi-vector search.
Do not provide it in single-vector queries.

Index-Specific Parameters

You can fine-tune search behavior by passing index-specific query parameters through the param in VectorQuery.

The param option accepts different parameter classes depending on the index type of your vectors — for example,

  • VectorQuery(..., param=HnswQueryParam()) for HNSW indexes,
  • VectorQuery(..., param=IVFQueryParam()) for IVF-based indexes.

The available query options are determined by this index type. If omitted, default values are used.

Each index type exposes its own set of tunable options at query time. For full details:

Mismatched parameter classes will cause an error. For instance, using IVFQueryParam with an HNSW-indexed vector (or vice versa) is not allowed.