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
: The reference vector for similarity comparison.sparse_vector
: The sparse vector value to query.data
: A string for text-based queries (mutually exclusive with vector).include_metadata
: A boolean flag indicating whether to include metadata in the query results.include_vector
: A boolean flag indicating whether to include vectors in the query results.include_data
: A boolean flag indicating whether to include data in the query results.top_k
: The number of top matching vectors to retrieve.filter
: Metadata filtering of the vector is used to query your data based on the filters and narrow down the query results.namespace
: The namespace to use. When not specified, the default namespace is used.weighting_strategy
: Weighting strategy to be used for sparse vectors.fusion_algorithm
: Fusion algorithm to use while fusing scores from hybrid vectors.query_mode
: Query mode for hybrid indexes with Upstash-hosted embedding models.max_idle
: The maximum idle time for the query in seconds.
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.
Example
Was this page helpful?