QueryDescriptor
class provides a fluent interface for building and configuring vector search queries. It allows you to combine vector-based similarity search with traditional filtering, specify result formatting, and execute searches against your indexed data.
Constructor
Parameters
The vector index to query against.
The schema object that defines the data structure being queried.
Optional list of query clauses that define the search criteria.
Optional user configuration for query execution behavior.
Properties
The collection of query clauses that define the search criteria.
The vector index being queried.
User configuration settings for the query.
The schema object for the data being queried.
Whether to include metadata in the query results.
Core Query Methods
similar()
Add a similarity clause to find items similar to a given input.The space or field set to search within.
The query parameter - can be a fixed value or a Param placeholder for later substitution.
The weight to apply to this similarity clause.
QueryDescriptor
- The query object for method chaining.
Raises:
InvalidInputException
- If the space is already bound in the queryInvalidInputException
- If the schema is not in the similarity field’s schema types
with_vector()
Add a clause to use an existing stored vector for similarity search.The schema object the vector originates from.
The ID parameter - the ID of the vector to use in the query.
Weight for the retrieved vector. Can be fine-tuned with space-wise weighting.
QueryDescriptor
- The query object for method chaining.
Filtering Methods
filter()
Add filtering criteria to limit results based on field values.The comparison operation defining the filter criteria.
QueryDescriptor
- The query object for method chaining.
Filter Examples
The original documentation shows these filter patterns:filter(color_schema.color == "blue")
filter(color_schema.color == Param("color_param"))
filter(color_schema.color != "red")
filter(color_schema.rating > 3)
filter(color_schema.rating >= 3)
filter(color_schema.rating < 3)
filter(color_schema.rating <= 3)
filter((color_schema.color == "blue") | (color_schema.color == "red"))
filter(color_schema.categories.contains(["bright", "matte"]))
- returns both bright and matte colorsfilter(color_schema.categories.not_contains(["bright", "matte"]))
- returns colors that are non-bright and non-mattefilter(color_schema.categories.contains_all(["bright", "blue"]))
- returns colors that are bright and blue at the same time
Result Configuration Methods
limit()
Set the maximum number of results to return.The maximum number of results. If None, -1 will be used (not handled by all databases).
QueryDescriptor
- The query object for method chaining.
radius()
Set a radius for the search to limit results by distance.The maximum distance from the query vector. Valid range is 0-1. A radius of 0.05 means minimum cosine similarity of 0.95.
QueryDescriptor
- The query object for method chaining.
Raises: InvalidInputException
- If the radius is not between 0 and 1.
select()
Select specific fields to return in the results.The fields to select. Can be SchemaField objects, field names as strings, or Param objects.
The spaces identifying the requested vector parts.
QueryDescriptor
- The query object for method chaining.
Raises:
InvalidInputException
- If multiple Param objects are provided or Param is mixed with other field typesTypeException
- If any fields are of unsupported typesFieldException
- If any schema fields are not part of the schemaInvalidInputException
- If any spaces in metadata is not a Space
select_all()
Select all fields from the schema to be returned.The spaces identifying the requested vector parts.
QueryDescriptor
- The query object for method chaining.
Metadata and Configuration
include_metadata()
Include per-item metadata in query results.QueryDescriptor
- The query object for method chaining.
space_weights()
Set custom weights for different vector spaces.Mapping of spaces to their weights.
QueryDescriptor
- The query object for method chaining.
Natural Language Query Support
with_natural_query()
Enable natural language query processing to automatically fill parameter values.Query containing desired characteristics in natural language.
Client configuration to initialize the OpenAI client.
Custom system prompt to use for the query.
QueryDescriptor
- The query object for method chaining.
nlq_suggestions()
Get suggestions for improving natural language query parameters.Additional feedback to help generate more targeted suggestions.
QuerySuggestionsModel
- Model containing improvement suggestions and clarifying questions.
The original documentation shows this example usage:
InvalidInputException
- If with_natural_query()
has not been called before this method.
Advanced Configuration
override_now()
Override the current timestamp for time-based queries.The timestamp to use as “now” for time-based calculations.
QueryDescriptor
- The query object for method chaining.
replace_user_config()
Replace the current query user configuration.The new configuration to use for this query.
QueryDescriptor
- A new query descriptor with the updated configuration.