query():
Query Parameters
You can specify additional parameters for the query, such as:top_k: the number of results to return.n_probes: the number of clusters to search for each query vector.filters: metadata filters to apply to the query (dictionary format).include: item fields to return (e.g.,["distance", "metadata"]).greedy: whether to perform a greedy search (higher recall but slower).
Batched Queries
It’s also possible to perform batch queries by passing multiple query vectors toquery():
Querying with Metadata Filters
You can filter query results based on metadata fields. For example, to filter items where theage field is greater than 18, you can use the following filter:
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
If you provided anembedding_model during index creation, you can automatically generate embeddings for queries by providing query_contents to the query() call:
Retrieving Items Post-Query
In certain applications, such as RAG, it may be desirable to retrieve matching items after a query. This is possible viaget(), which retrieves and decrypts item added via upsert(). For more details, see the Get Items guide.
Index Training for Optimal Performance
For optimal query performance, you should train your index after adding a significant amount of data (typically more than 50,000 vectors). The CyborgDB service supports index training to improve query speed and accuracy. Queries will initially use exhaustive search, which is fine for small datasets. Once you have a substantial amount of data, train the index for better performance. 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/queryPython SDK Reference
API reference for
query() in PythonJS/TS SDK Reference
API reference for
query() in JavaScript/TypeScriptGo SDK Reference
API reference for
Query() in Go