indexers.VectorStore.search
indexers.VectorStore.search(query, n_results=10, batch_size=None)Queries the vectors attribute for the most similar documents.
Queries are processed in batches of batch_size, with each batch embedded using vectoriser.transform() and scored against all stored document embeddings via dot-product similarity (equivalent to cosine similarity when embeddings are L2-normalised). The top n_results documents are returned for each query, ordered by descending score.
Any preprocessing hooks set on the instance are applied to the input before searching, and any postprocessing hooks are applied to the output before it is returned.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| query | VectorStoreSearchInput | The input object containing the text query or list of queries to search for, with ids. | required |
| n_results | int | Number of top results to return for each query. Defaults to 10. | 10 |
| batch_size | int | The batch size for processing queries. Defaults to the batch_size set during initialisation. | None |
Returns
| Name | Type | Description |
|---|---|---|
| VectorStoreSearchOutput | VectorStoreSearchOutput | The output object containing search results with columns for query_id, query_text, doc_label, doc_text, rank, score, and any associated metadata columns. |
Raises
| Name | Type | Description |
|---|---|---|
| DataValidationError | Raised if invalid arguments are passed. | |
| ConfigurationError | Raised if the VectorStore is not initialised. |
|
| HookError | Raised if user-defined hooks fail. | |
| ClassifaiError | Raised if there is a package-specific error during the search operation. | |
| VectorisationError | Raised if query embedding fails. |