Resumable Query
The resumable query feature allows you to perform queries that can be resumed to fetch additional results. This is particularly useful for large result sets or when implementing pagination.
Synchronous Usage
Creating a Resumable Query
To create a resumable query, use the resumable_query
method of the Index
class:
Parameters:
- vector: A list of floats representing the query vector.
- data: A string for text-based queries (mutually exclusive with vector).
- top_k: The number of results to fetch initially.
- include_metadata: Whether to include metadata in the results.
- include_vectors: Whether to include vector values in the results.
- max-idle: The maximum idle time for the query in seconds.
- namespace: The namespace to query (optional).
Starting the Query
To start the query and get initial results:
The initial_results will be a list of result objects, each having properties like id and metadata (if included).
Fetching More Results
To fetch additional results:
This method returns a list of additional results. If no more results are available, it returns an empty list.
Stopping the Query
When you’re done with the query, stop it to release resources:
Asynchronous Usage
For asynchronous operations, use the AsyncIndex class:
Creating an Async Resumable Query
Starting the Async Query
Fetching More Results Asynchronously
Stopping the Async Query
Error Handling
After stopping a query, attempting to fetch more results or stop it again will raise a ClientError
:
Example: Fetching All Results Here’s an example of how to fetch all results using a resumable query:
This pattern allows you to efficiently retrieve large result sets without loading everything into memory at once.
Remember to always stop your query when you’re done to release server-side resources.