Encrypted Index
Query
Single Query
Retrieves the nearest neighbors for a given query vector.
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
query_vector | List[float] | - | A single query vector as a list of floats (for single query). |
top_k | int | 100 | (Optional) Number of nearest neighbors to return. |
n_probes | int | 1 | (Optional) Number of lists probed during the query; higher values may increase recall but can also reduce performance. |
filters | Dict[str, Any] | None | (Optional) A dictionary of filters to apply to vector metadata, limiting search scope to these vectors. |
include | List[str] | "distance" | (Optional) List of item fields to return. Can include distance , metadata , and vector (vector only for IVFFlat indexes). |
greedy | bool | False | (Optional) Whether to use greedy search (higher recall with same n_probes ). |
If embedding auto-generation is enabled (by setting the
embedding_model
parameter in create_index()
, then the query_string
can be used instead of query_vector
.filters
use a subset of the MongoDB Query and Projection Operators.
For instance: filters: { "$and": [ { "label": "cat" }, { "confidence": { "$gte": 0.9 } } ] }
means that only vectors where label == "cat"
and confidence >= 0.9
will be considered for encrypted vector search.
For more info on metadata, see Metadata Filtering.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
, as well as distance
, metadata
, and vector
based on include
.
Exceptions
Example Usage
Single Query with Distances:
Single Query without Distances:
Single Query with Metadata:
Batched Queries
Retrieves the nearest neighbors for one or more query vectors.
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
query_vectors | np.ndarray or List[List[float]] | - | A 2D NumPy array or list of lists, where each inner list represents a query vector (for batch query). |
top_k | int | 100 | (Optional) Number of nearest neighbors to return. |
n_probes | int | 1 | (Optional) Number of lists probed during the query; higher values may increase recall but can also reduce performance. |
filters | Dict[str, Any] | None | (Optional) A dictionary of filters to apply to vector metadata, limiting search scope to these vectors. |
include | List[str] | "distance" | (Optional) List of item fields to return. Can include distance , metadata , and vector (vector only for IVFFlat indexes). |
greedy | bool | False | (Optional) Whether to use greedy search (higher recall with same n_probes ). |
filters
use a subset of the MongoDB Query and Projection Operators.
For instance: filters: { "$and": [ { "label": "cat" }, { "confidence": { "$gte": 0.9 } } ] }
means that only vectors where label == "cat"
and confidence >= 0.9
will be considered for encrypted vector search.
For more info on metadata, see Metadata Filtering.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
, as well as distance
, metadata
, and vector
based on include
.
Exceptions
Example Usage
Batch Query with Distances:
Was this page helpful?