Skip to main content
Once you’ve added items to an encrypted index, you can query the index to retrieve the items that match a given query. This is done via query():

Query Parameters

You can specify additional parameters for the query, such as:
  • top_k: the number of results to return. Default: 100.
  • n_probes: the number of clusters to search for each query vector. Default: None (auto-determined by server).
  • filters: metadata filters to apply to the query (dictionary format). Default: None.
  • include: item fields to return (e.g., ["distance", "metadata"]). Default: [] (only id is returned). Note: id is always included.
  • greedy: whether to use faster approximate search. Default: None (server default: false).

Batched Queries

It’s also possible to perform batch queries by passing multiple query vectors to query():

Querying with Metadata Filters

You can filter query results based on metadata fields. For example, to filter items where the age field is greater than 18, you can use the following filter:
This filter will return items where the age field is greater than 18. You can also use other comparison operators such as $lt, $gte, $lte, $eq, and $ne. For more details on metadata filters, see the Metadata Filtering guide.

Automatic Embedding Generation

To use automatic embedding generation, use the Docker Service or install with pip install "cyborgdb-service[embeddings]"
If you provided an embedding_model during index creation, you can automatically generate embeddings for queries by providing query_contents to the query() call:
This feature allows you to perform semantic search using natural language queries. The service will automatically generate embeddings for your query text using the specified embedding model.

Hybrid Search (BM25 + Vector)

If the index was created with at least one full_text metadata field, passing text alongside query_vectors turns the query into a hybrid query: BM25 full-text ranking is fused with the vector ranking, and each result carries a score (fused relevance, larger = better) instead of a distance:
Adding filters on top composes a three-way query (vector + BM25 + metadata). The filter is resolved first, and both legs rank only its survivors:
A query with text set accepts only filters the metadata index can resolve exactly — $regex on a non-pattern field, or any predicate on a filterable: false field, is rejected once text is present.
For full-text search without a vector, field designation at index creation, tuning knobs (alpha, rrf_k, window_mult), and constraints, see the Full-Text and Hybrid Search guide.

Retrieving Items Post-Query

In certain applications, such as RAG, it may be desirable to retrieve matching items after a query. This is possible via get(), which retrieves and decrypts item added via upsert(). For more details, see the Get Items guide.

Index Training for Optimal Performance

Training improves query speed and accuracy. The CyborgDB service trains your index automatically once it holds enough vectors (more than 65,536 by default) and retrains it as it grows, so you usually don’t need to train it yourself. Until the index is trained, queries use exhaustive search, which is fine for small datasets. You can also train explicitly, for example to choose training parameters. For more details, see Training an Encrypted Index.

API Reference

For more information on querying encrypted indexes, refer to the API reference:

REST API Reference

REST API reference for /v1/vectors/query

Python SDK Reference

API reference for query() in Python

JS/TS SDK Reference

API reference for query() in JavaScript/TypeScript

Go SDK Reference

API reference for Query() in Go