Single Query
Retrieves the nearest neighbors for a given query vector. Passingtext alongside query_vectors turns this into a hybrid query that fuses BM25 full-text ranking with the vector ranking (see Full-text and hybrid search).
Parameters
If embedding auto-generation is enabled (by setting the
embedding_model parameter in create_index(), then the query_contents parameter can be used instead of query_vectors.Hybrid queries still require a query vector — including at
alpha=0, where it only fixes the batch shape. For text search with no vector at all, use query_metadata(text=...).Hybrid queries narrow which filters are accepted.
$regex on a non-pattern field, and any predicate on an explicitly non-filterable field, work in a pure query() but are rejected once text is set, because the text leg can only be filtered on fields resolvable from the encrypted metadata index. Move the filter to a pattern / filterable field or drop text.Returns
List[Dict[str, Union[int, float, Dict[]]]]: List of results for the query vector. Each result is a list of top_k dictionaries, each containing id (always included), and optionally distance (pure vector query), score (hybrid query — fused BM25 + vector relevance, larger = more relevant), and metadata based on include. A hybrid result carries score in place of distance — never both, since a text-only match has no vector distance. When include is empty (the default), only id is returned.
Exceptions
ValueError
ValueError
- Throws if the query vector has incompatible dimensions with the index.
- Throws if the index was not created or loaded yet.
- Throws if
textis passed but the index has nofull_textfield. - Throws if
text_fieldsnames a field that is notfull_text. - Throws if any
text_*knob is set without a non-emptytext. - Throws if
rrf_k <= 0orwindow_mult < 1is passed explicitly (passNonefor defaults). - Throws if a filter references a field the index cannot resolve when
textis set (e.g.$regexon a non-patternfield, or any predicate on an explicitly non-filterablefield). - Throws if the query could not be executed.
Example Usage
Single Query with Distances:full_text field (see Full-text and hybrid search).
r['id'], r['distance'], r['metadata']):
Index key
index_key is required on every call. Pass the same 32-byte index KEK you used with create_index() / load_index(). For an RBAC user, pass the user’s KEK as index_key= together with their user_id=:
Batched Queries
Retrieves the nearest neighbors for one or more query vectors.Parameters
Batched queries accept the same BM25 keyword-only params as the single-query form (
text, text_fields, text_field_weights, require_all_terms, alpha, rrf_k, window_mult); the same text value applies to every row in the batch.Returns
List[List[Dict[str, Union[int, float, Dict[]]]]]: List of results for each query vector. Each result is a list of top_k dictionaries, each containing id (always included), and optionally distance (pure vector query), score (hybrid query), and metadata based on include. When include is empty (the default), only id is returned.
Exceptions
ValueError
ValueError
- Throws if the query vectors have incompatible dimensions with the index.
- Throws if the index was not created or loaded yet.
- Throws if the query could not be executed.
Example Usage
Batch Query with Distances:NumPy Query
A high-performance query variant that returns only integer IDs as a NumPy array. This is optimized for performance-critical workloads where metadata and distances are not needed.Parameters
Returns
np.ndarray: A NumPy array of integer IDs for the nearest neighbors. For a single query, returns a 1D array of shape (top_k,). For batch queries, returns a 2D array of shape (num_queries, top_k). Slots beyond the number of results found, and IDs that cannot be converted to integers, are set to -1.
Exceptions
ValueError
ValueError
- Throws if the query vectors have incompatible dimensions with the index.
- Throws if the index was not created or loaded yet.
- Throws if the query could not be executed.
TypeError
TypeError
- Throws if the
query_vectorsformat does not match thebatchparameter.
Example Usage
query_numpy is a high-performance variant that returns only integer IDs. Use the standard query() method if you need distances, metadata, or string IDs.