{
  "id": "query",
  "title": "Query",
  "url": "https://redis.io/docs/latest/develop/ai/redisvl/0.8.2/api/query/",
  "summary": "",
  "content": "\n\nQuery classes in RedisVL provide a structured way to define simple or complex\nqueries for different use cases. Each query class wraps the `redis-py` Query module\n[https://github.com/redis/redis-py/blob/master/redis/commands/search/query.py](https://github.com/redis/redis-py/blob/master/redis/commands/search/query.py) with extended functionality for ease-of-use.\n\n## VectorQuery\n\n### `class VectorQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, ef_runtime=None, normalize_vector_distance=False)`\n\nBases: `BaseVectorQuery`, `BaseQuery`\n\nA query for running a vector search along with an optional filter\nexpression.\n\n* **Parameters:**\n  * **vector** (*List* *[* *float* *]*) – The vector to perform the vector search with.\n  * **vector_field_name** (*str*) – The name of the vector field to search\n    against in the database.\n  * **return_fields** (*List* *[* *str* *]*) – The declared fields to return with search\n    results.\n  * **filter_expression** (*Union* *[* *str* *,* [*FilterExpression*]() *]* *,* *optional*) – A filter to apply\n    along with the vector search. Defaults to None.\n  * **dtype** (*str* *,* *optional*) – The dtype of the vector. Defaults to\n    \"float32\".\n  * **num_results** (*int* *,* *optional*) – The top k results to return from the\n    vector search. Defaults to 10.\n  * **return_score** (*bool* *,* *optional*) – Whether to return the vector\n    distance. Defaults to True.\n  * **dialect** (*int* *,* *optional*) – The RediSearch query dialect.\n    Defaults to 2.\n  * **sort_by** (*Optional* *[* *str* *]*) – The field to order the results by. Defaults\n    to None. Results will be ordered by vector distance.\n  * **in_order** (*bool*) – Requires the terms in the field to have\n    the same order as the terms in the query filter, regardless of\n    the offsets between them. Defaults to False.\n  * **hybrid_policy** (*Optional* *[* *str* *]*) – Controls how filters are applied during vector search.\n    Options are \"BATCHES\" (paginates through small batches of nearest neighbors) or\n    \"ADHOC_BF\" (computes scores for all vectors passing the filter).\n    \"BATCHES\" mode is typically faster for queries with selective filters.\n    \"ADHOC_BF\" mode is better when filters match a large portion of the dataset.\n    Defaults to None, which lets Redis auto-select the optimal policy.\n  * **batch_size** (*Optional* *[* *int* *]*) – When hybrid_policy is \"BATCHES\", controls the number\n    of vectors to fetch in each batch. Larger values may improve performance\n    at the cost of memory usage. Only applies when hybrid_policy=\"BATCHES\".\n    Defaults to None, which lets Redis auto-select an appropriate batch size.\n  * **ef_runtime** (*Optional* *[* *int* *]*) – Controls the size of the dynamic candidate list for HNSW\n    algorithm at query time. Higher values improve recall at the expense of\n    slower search performance. Defaults to None, which uses the index-defined value.\n  * **normalize_vector_distance** (*bool*) – Redis supports 3 distance metrics: L2 (euclidean),\n    IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.\n    COSINE distance returns a value between 0 and 2. IP returns a value determined by\n    the magnitude of the vector. Setting this flag to true converts COSINE and L2 distance\n    to a similarity score between 0 and 1. Note: setting this flag to true for IP will\n    throw a warning since by definition COSINE similarity is normalized IP.\n* **Raises:**\n  **TypeError** – If filter_expression is not of type redisvl.query.FilterExpression\n\n#### `NOTE`\nLearn more about vector queries in Redis: [https://redis.io/docs/interact/search-and-query/search/vectors/#knn-search](https://redis.io/docs/interact/search-and-query/search/vectors/#knn-search)\n\n#### `dialect(dialect)`\n\nAdd a dialect field to the query.\n\n- **dialect** - dialect version to execute the query under\n\n* **Parameters:**\n  **dialect** (*int*)\n* **Return type:**\n  *Query*\n\n#### `expander(expander)`\n\nAdd a expander field to the query.\n\n- **expander** - the name of the expander\n\n* **Parameters:**\n  **expander** (*str*)\n* **Return type:**\n  *Query*\n\n#### `in_order()`\n\nMatch only documents where the query terms appear in\nthe same order in the document.\ni.e. for the query \"hello world\", we do not match \"world hello\"\n\n* **Return type:**\n  *Query*\n\n#### `language(language)`\n\nAnalyze the query as being in the specified language.\n\n* **Parameters:**\n  **language** (*str*) – The language (e.g. chinese or english)\n* **Return type:**\n  *Query*\n\n#### `limit_fields(*fields)`\n\nLimit the search to specific TEXT fields only.\n\n- **fields**: A list of strings, case sensitive field names\n\nfrom the defined schema.\n\n* **Parameters:**\n  **fields** (*List* *[* *str* *]*)\n* **Return type:**\n  *Query*\n\n#### `limit_ids(*ids)`\n\nLimit the results to a specific set of pre-known document\nids of any length.\n\n* **Return type:**\n  *Query*\n\n#### `no_content()`\n\nSet the query to only return ids and not the document content.\n\n* **Return type:**\n  *Query*\n\n#### `no_stopwords()`\n\nPrevent the query from being filtered for stopwords.\nOnly useful in very big queries that you are certain contain\nno stopwords.\n\n* **Return type:**\n  *Query*\n\n#### `paging(offset, num)`\n\nSet the paging for the query (defaults to 0..10).\n\n- **offset**: Paging offset for the results. Defaults to 0\n- **num**: How many results do we want\n\n* **Parameters:**\n  * **offset** (*int*)\n  * **num** (*int*)\n* **Return type:**\n  *Query*\n\n#### `query_string()`\n\nReturn the query string of this query only.\n\n* **Return type:**\n  str\n\n#### `return_fields(*fields)`\n\nAdd fields to return fields.\n\n* **Return type:**\n  *Query*\n\n#### `scorer(scorer)`\n\nUse a different scoring function to evaluate document relevance.\nDefault is TFIDF.\n\nSince Redis 8.0 default was changed to BM25STD.\n\n* **Parameters:**\n  **scorer** (*str*) – The scoring function to use\n  (e.g. TFIDF.DOCNORM or BM25)\n* **Return type:**\n  *Query*\n\n#### `set_batch_size(batch_size)`\n\nSet the batch size for the query.\n\n* **Parameters:**\n  **batch_size** (*int*) – The batch size to use when hybrid_policy is \"BATCHES\".\n* **Raises:**\n  * **TypeError** – If batch_size is not an integer\n  * **ValueError** – If batch_size is not positive\n\n#### `set_ef_runtime(ef_runtime)`\n\nSet the EF_RUNTIME parameter for the query.\n\n* **Parameters:**\n  **ef_runtime** (*int*) – The EF_RUNTIME value to use for HNSW algorithm.\n  Higher values improve recall at the expense of slower search.\n* **Raises:**\n  * **TypeError** – If ef_runtime is not an integer\n  * **ValueError** – If ef_runtime is not positive\n\n#### `set_filter(filter_expression=None)`\n\nSet the filter expression for the query.\n\n* **Parameters:**\n  **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]* *,* *optional*) – The filter\n  expression or query string to use on the query.\n* **Raises:**\n  **TypeError** – If filter_expression is not a valid FilterExpression or string.\n\n#### `set_hybrid_policy(hybrid_policy)`\n\nSet the hybrid policy for the query.\n\n* **Parameters:**\n  **hybrid_policy** (*str*) – The hybrid policy to use. Options are \"BATCHES\"\n  or \"ADHOC_BF\".\n* **Raises:**\n  **ValueError** – If hybrid_policy is not one of the valid options\n\n#### `slop(slop)`\n\nAllow a maximum of N intervening non matched terms between\nphrase terms (0 means exact phrase).\n\n* **Parameters:**\n  **slop** (*int*)\n* **Return type:**\n  *Query*\n\n#### `sort_by(field, asc=True)`\n\nAdd a sortby field to the query.\n\n- **field** - the name of the field to sort by\n- **asc** - when True, sorting will be done in asceding order\n\n* **Parameters:**\n  * **field** (*str*)\n  * **asc** (*bool*)\n* **Return type:**\n  *Query*\n\n#### `timeout(timeout)`\n\noverrides the timeout parameter of the module\n\n* **Parameters:**\n  **timeout** (*float*)\n* **Return type:**\n  *Query*\n\n#### `verbatim()`\n\nSet the query to be verbatim, i.e. use no query expansion\nor stemming.\n\n* **Return type:**\n  *Query*\n\n#### `with_payloads()`\n\nAsk the engine to return document payloads.\n\n* **Return type:**\n  *Query*\n\n#### `with_scores()`\n\nAsk the engine to return document search scores.\n\n* **Return type:**\n  *Query*\n\n#### `property batch_size: int | None`\n\nReturn the batch size for the query.\n\n* **Returns:**\n  The batch size for the query.\n* **Return type:**\n  Optional[int]\n\n#### `property ef_runtime: int | None`\n\nReturn the EF_RUNTIME parameter for the query.\n\n* **Returns:**\n  The EF_RUNTIME value for the query.\n* **Return type:**\n  Optional[int]\n\n#### `property filter: str | `[`FilterExpression`]()` `\n\nThe filter expression for the query.\n\n#### `property hybrid_policy: str | None`\n\nReturn the hybrid policy for the query.\n\n* **Returns:**\n  The hybrid policy for the query.\n* **Return type:**\n  Optional[str]\n\n#### `property params: Dict[str, Any]`\n\nReturn the parameters for the query.\n\n* **Returns:**\n  The parameters for the query.\n* **Return type:**\n  Dict[str, Any]\n\n#### `property query: BaseQuery`\n\nReturn self as the query object.\n\n## VectorRangeQuery\n\n### `class VectorRangeQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', distance_threshold=0.2, epsilon=None, num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, normalize_vector_distance=False)`\n\nBases: `BaseVectorQuery`, `BaseQuery`\n\nA query for running a filtered vector search based on semantic\ndistance threshold.\n\n* **Parameters:**\n  * **vector** (*List* *[* *float* *]*) – The vector to perform the range query with.\n  * **vector_field_name** (*str*) – The name of the vector field to search\n    against in the database.\n  * **return_fields** (*List* *[* *str* *]*) – The declared fields to return with search\n    results.\n  * **filter_expression** (*Union* *[* *str* *,* [*FilterExpression*]() *]* *,* *optional*) – A filter to apply\n    along with the range query. Defaults to None.\n  * **dtype** (*str* *,* *optional*) – The dtype of the vector. Defaults to\n    \"float32\".\n  * **distance_threshold** (*float*) – The threshold for vector distance.\n    A smaller threshold indicates a stricter semantic search.\n    Defaults to 0.2.\n  * **epsilon** (*Optional* *[* *float* *]*) – The relative factor for vector range queries,\n    setting boundaries for candidates within radius \\* (1 + epsilon).\n    This controls how extensive the search is beyond the specified radius.\n    Higher values increase recall at the expense of performance.\n    Defaults to None, which uses the index-defined epsilon (typically 0.01).\n  * **num_results** (*int*) – The MAX number of results to return.\n    Defaults to 10.\n  * **return_score** (*bool* *,* *optional*) – Whether to return the vector\n    distance. Defaults to True.\n  * **dialect** (*int* *,* *optional*) – The RediSearch query dialect.\n    Defaults to 2.\n  * **sort_by** (*Optional* *[* *str* *]*) – The field to order the results by. Defaults\n    to None. Results will be ordered by vector distance.\n  * **in_order** (*bool*) – Requires the terms in the field to have\n    the same order as the terms in the query filter, regardless of\n    the offsets between them. Defaults to False.\n  * **hybrid_policy** (*Optional* *[* *str* *]*) – Controls how filters are applied during vector search.\n    Options are \"BATCHES\" (paginates through small batches of nearest neighbors) or\n    \"ADHOC_BF\" (computes scores for all vectors passing the filter).\n    \"BATCHES\" mode is typically faster for queries with selective filters.\n    \"ADHOC_BF\" mode is better when filters match a large portion of the dataset.\n    Defaults to None, which lets Redis auto-select the optimal policy.\n  * **batch_size** (*Optional* *[* *int* *]*) – When hybrid_policy is \"BATCHES\", controls the number\n    of vectors to fetch in each batch. Larger values may improve performance\n    at the cost of memory usage. Only applies when hybrid_policy=\"BATCHES\".\n    Defaults to None, which lets Redis auto-select an appropriate batch size.\n  * **normalize_vector_distance** (*bool*) – Redis supports 3 distance metrics: L2 (euclidean),\n    IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.\n    COSINE distance returns a value between 0 and 2. IP returns a value determined by\n    the magnitude of the vector. Setting this flag to true converts COSINE and L2 distance\n    to a similarity score between 0 and 1. Note: setting this flag to true for IP will\n    throw a warning since by definition COSINE similarity is normalized IP.\n* **Raises:**\n  **TypeError** – If filter_expression is not of type redisvl.query.FilterExpression\n\n#### `NOTE`\nLearn more about vector range queries: [https://redis.io/docs/interact/search-and-query/search/vectors/#range-query](https://redis.io/docs/interact/search-and-query/search/vectors/#range-query)\n\n#### `dialect(dialect)`\n\nAdd a dialect field to the query.\n\n- **dialect** - dialect version to execute the query under\n\n* **Parameters:**\n  **dialect** (*int*)\n* **Return type:**\n  *Query*\n\n#### `expander(expander)`\n\nAdd a expander field to the query.\n\n- **expander** - the name of the expander\n\n* **Parameters:**\n  **expander** (*str*)\n* **Return type:**\n  *Query*\n\n#### `in_order()`\n\nMatch only documents where the query terms appear in\nthe same order in the document.\ni.e. for the query \"hello world\", we do not match \"world hello\"\n\n* **Return type:**\n  *Query*\n\n#### `language(language)`\n\nAnalyze the query as being in the specified language.\n\n* **Parameters:**\n  **language** (*str*) – The language (e.g. chinese or english)\n* **Return type:**\n  *Query*\n\n#### `limit_fields(*fields)`\n\nLimit the search to specific TEXT fields only.\n\n- **fields**: A list of strings, case sensitive field names\n\nfrom the defined schema.\n\n* **Parameters:**\n  **fields** (*List* *[* *str* *]*)\n* **Return type:**\n  *Query*\n\n#### `limit_ids(*ids)`\n\nLimit the results to a specific set of pre-known document\nids of any length.\n\n* **Return type:**\n  *Query*\n\n#### `no_content()`\n\nSet the query to only return ids and not the document content.\n\n* **Return type:**\n  *Query*\n\n#### `no_stopwords()`\n\nPrevent the query from being filtered for stopwords.\nOnly useful in very big queries that you are certain contain\nno stopwords.\n\n* **Return type:**\n  *Query*\n\n#### `paging(offset, num)`\n\nSet the paging for the query (defaults to 0..10).\n\n- **offset**: Paging offset for the results. Defaults to 0\n- **num**: How many results do we want\n\n* **Parameters:**\n  * **offset** (*int*)\n  * **num** (*int*)\n* **Return type:**\n  *Query*\n\n#### `query_string()`\n\nReturn the query string of this query only.\n\n* **Return type:**\n  str\n\n#### `return_fields(*fields)`\n\nAdd fields to return fields.\n\n* **Return type:**\n  *Query*\n\n#### `scorer(scorer)`\n\nUse a different scoring function to evaluate document relevance.\nDefault is TFIDF.\n\nSince Redis 8.0 default was changed to BM25STD.\n\n* **Parameters:**\n  **scorer** (*str*) – The scoring function to use\n  (e.g. TFIDF.DOCNORM or BM25)\n* **Return type:**\n  *Query*\n\n#### `set_batch_size(batch_size)`\n\nSet the batch size for the query.\n\n* **Parameters:**\n  **batch_size** (*int*) – The batch size to use when hybrid_policy is \"BATCHES\".\n* **Raises:**\n  * **TypeError** – If batch_size is not an integer\n  * **ValueError** – If batch_size is not positive\n\n#### `set_distance_threshold(distance_threshold)`\n\nSet the distance threshold for the query.\n\n* **Parameters:**\n  **distance_threshold** (*float*) – Vector distance threshold.\n* **Raises:**\n  * **TypeError** – If distance_threshold is not a float or int\n  * **ValueError** – If distance_threshold is negative\n\n#### `set_epsilon(epsilon)`\n\nSet the epsilon parameter for the range query.\n\n* **Parameters:**\n  **epsilon** (*float*) – The relative factor for vector range queries,\n  setting boundaries for candidates within radius \\* (1 + epsilon).\n* **Raises:**\n  * **TypeError** – If epsilon is not a float or int\n  * **ValueError** – If epsilon is negative\n\n#### `set_filter(filter_expression=None)`\n\nSet the filter expression for the query.\n\n* **Parameters:**\n  **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]* *,* *optional*) – The filter\n  expression or query string to use on the query.\n* **Raises:**\n  **TypeError** – If filter_expression is not a valid FilterExpression or string.\n\n#### `set_hybrid_policy(hybrid_policy)`\n\nSet the hybrid policy for the query.\n\n* **Parameters:**\n  **hybrid_policy** (*str*) – The hybrid policy to use. Options are \"BATCHES\"\n  or \"ADHOC_BF\".\n* **Raises:**\n  **ValueError** – If hybrid_policy is not one of the valid options\n\n#### `slop(slop)`\n\nAllow a maximum of N intervening non matched terms between\nphrase terms (0 means exact phrase).\n\n* **Parameters:**\n  **slop** (*int*)\n* **Return type:**\n  *Query*\n\n#### `sort_by(field, asc=True)`\n\nAdd a sortby field to the query.\n\n- **field** - the name of the field to sort by\n- **asc** - when True, sorting will be done in asceding order\n\n* **Parameters:**\n  * **field** (*str*)\n  * **asc** (*bool*)\n* **Return type:**\n  *Query*\n\n#### `timeout(timeout)`\n\noverrides the timeout parameter of the module\n\n* **Parameters:**\n  **timeout** (*float*)\n* **Return type:**\n  *Query*\n\n#### `verbatim()`\n\nSet the query to be verbatim, i.e. use no query expansion\nor stemming.\n\n* **Return type:**\n  *Query*\n\n#### `with_payloads()`\n\nAsk the engine to return document payloads.\n\n* **Return type:**\n  *Query*\n\n#### `with_scores()`\n\nAsk the engine to return document search scores.\n\n* **Return type:**\n  *Query*\n\n#### `property batch_size: int | None`\n\nReturn the batch size for the query.\n\n* **Returns:**\n  The batch size for the query.\n* **Return type:**\n  Optional[int]\n\n#### `property distance_threshold: float`\n\nReturn the distance threshold for the query.\n\n* **Returns:**\n  The distance threshold for the query.\n* **Return type:**\n  float\n\n#### `property epsilon: float | None`\n\nReturn the epsilon for the query.\n\n* **Returns:**\n  The epsilon for the query, or None if not set.\n* **Return type:**\n  Optional[float]\n\n#### `property filter: str | `[`FilterExpression`]()` `\n\nThe filter expression for the query.\n\n#### `property hybrid_policy: str | None`\n\nReturn the hybrid policy for the query.\n\n* **Returns:**\n  The hybrid policy for the query.\n* **Return type:**\n  Optional[str]\n\n#### `property params: Dict[str, Any]`\n\nReturn the parameters for the query.\n\n* **Returns:**\n  The parameters for the query.\n* **Return type:**\n  Dict[str, Any]\n\n#### `property query: BaseQuery`\n\nReturn self as the query object.\n\n## HybridQuery\n\n### `class HybridQuery(text, text_field_name, vector, vector_field_name, text_scorer='BM25STD', filter_expression=None, alpha=0.7, dtype='float32', num_results=10, return_fields=None, stopwords='english', dialect=2)`\n\nBases: `AggregationQuery`\n\nHybridQuery combines text and vector search in Redis.\nIt allows you to perform a hybrid search using both text and vector similarity.\nIt scores documents based on a weighted combination of text and vector similarity.\n\n```python\nfrom redisvl.query import HybridQuery\nfrom redisvl.index import SearchIndex\n\nindex = SearchIndex.from_yaml(\"path/to/index.yaml\")\n\nquery = HybridQuery(\n    text=\"example text\",\n    text_field_name=\"text_field\",\n    vector=[0.1, 0.2, 0.3],\n    vector_field_name=\"vector_field\",\n    text_scorer=\"BM25STD\",\n    filter_expression=None,\n    alpha=0.7,\n    dtype=\"float32\",\n    num_results=10,\n    return_fields=[\"field1\", \"field2\"],\n    stopwords=\"english\",\n    dialect=2,\n)\n\nresults = index.query(query)\n```\n\nInstantiates a HybridQuery object.\n\n* **Parameters:**\n  * **text** (*str*) – The text to search for.\n  * **text_field_name** (*str*) – The text field name to search in.\n  * **vector** (*Union* *[* *bytes* *,* *List* *[* *float* *]* *]*) – The vector to perform vector similarity search.\n  * **vector_field_name** (*str*) – The vector field name to search in.\n  * **text_scorer** (*str* *,* *optional*) – The text scorer to use. Options are {TFIDF, TFIDF.DOCNORM,\n    BM25, DISMAX, DOCSCORE, BM25STD}. Defaults to \"BM25STD\".\n  * **filter_expression** (*Optional* *[*[*FilterExpression*]() *]* *,* *optional*) – The filter expression to use.\n    Defaults to None.\n  * **alpha** (*float* *,* *optional*) – The weight of the vector similarity. Documents will be scored\n    as: hybrid_score = (alpha) \\* vector_score + (1-alpha) \\* text_score.\n    Defaults to 0.7.\n  * **dtype** (*str* *,* *optional*) – The data type of the vector. Defaults to \"float32\".\n  * **num_results** (*int* *,* *optional*) – The number of results to return. Defaults to 10.\n  * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]* *,* *optional*) – The fields to return. Defaults to None.\n  * **stopwords** (*Optional* *[* *Union* *[* *str* *,* *Set* *[* *str* *]* *]* *]* *,* *optional*) – The stopwords to remove from the\n    provided text prior to searchuse. If a string such as \"english\" \"german\" is\n    provided then a default set of stopwords for that language will be used. if a list,\n    set, or tuple of strings is provided then those will be used as stopwords.\n    Defaults to \"english\". if set to \"None\" then no stopwords will be removed.\n  * **dialect** (*int* *,* *optional*) – The Redis dialect version. Defaults to 2.\n* **Raises:**\n  * **ValueError** – If the text string is empty, or if the text string becomes empty after\n        stopwords are removed.\n  * **TypeError** – If the stopwords are not a set, list, or tuple of strings.\n\n#### `add_scores()`\n\nIf set, includes the score as an ordinary field of the row.\n\n* **Return type:**\n  *AggregateRequest*\n\n#### `apply(**kwexpr)`\n\nSpecify one or more projection expressions to add to each result\n\n### `Parameters`\n\n- **kwexpr**: One or more key-value pairs for a projection. The key is\n  : the alias for the projection, and the value is the projection\n    expression itself, for example apply(square_root=\"sqrt(@foo)\")\n\n* **Return type:**\n  *AggregateRequest*\n\n#### `dialect(dialect)`\n\nAdd a dialect field to the aggregate command.\n\n- **dialect** - dialect version to execute the query under\n\n* **Parameters:**\n  **dialect** (*int*)\n* **Return type:**\n  *AggregateRequest*\n\n#### `filter(expressions)`\n\nSpecify filter for post-query results using predicates relating to\nvalues in the result set.\n\n### `Parameters`\n\n- **fields**: Fields to group by. This can either be a single string,\n  : or a list of strings.\n\n* **Parameters:**\n  **expressions** (*str* *|* *List* *[* *str* *]*)\n* **Return type:**\n  *AggregateRequest*\n\n#### `group_by(fields, *reducers)`\n\nSpecify by which fields to group the aggregation.\n\n### `Parameters`\n\n- **fields**: Fields to group by. This can either be a single string,\n  : or a list of strings. both cases, the field should be specified as\n    @field.\n- **reducers**: One or more reducers. Reducers may be found in the\n  : aggregation module.\n\n* **Parameters:**\n  * **fields** (*List* *[* *str* *]*)\n  * **reducers** (*Reducer* *|* *List* *[* *Reducer* *]*)\n* **Return type:**\n  *AggregateRequest*\n\n#### `limit(offset, num)`\n\nSets the limit for the most recent group or query.\n\nIf no group has been defined yet (via group_by()) then this sets\nthe limit for the initial pool of results from the query. Otherwise,\nthis limits the number of items operated on from the previous group.\n\nSetting a limit on the initial search results may be useful when\nattempting to execute an aggregation on a sample of a large data set.\n\n### `Parameters`\n\n- **offset**: Result offset from which to begin paging\n- **num**: Number of results to return\n\nExample of sorting the initial results:\n\n``\nAggregateRequest(\"@sale_amount:[10000, inf]\")            .limit(0, 10)            .group_by(\"@state\", r.count())\n``\n\nWill only group by the states found in the first 10 results of the\nquery @sale_amount:[10000, inf]. On the other hand,\n\n``\nAggregateRequest(\"@sale_amount:[10000, inf]\")            .limit(0, 1000)            .group_by(\"@state\", r.count()            .limit(0, 10)\n``\n\nWill group all the results matching the query, but only return the\nfirst 10 groups.\n\nIf you only wish to return a *top-N* style query, consider using\nsort_by() instead.\n\n* **Parameters:**\n  * **offset** (*int*)\n  * **num** (*int*)\n* **Return type:**\n  *AggregateRequest*\n\n#### `load(*fields)`\n\nIndicate the fields to be returned in the response. These fields are\nreturned in addition to any others implicitly specified.\n\n### `Parameters`\n\n- **fields**: If fields not specified, all the fields will be loaded.\n\nOtherwise, fields should be given in the format of @field.\n\n* **Parameters:**\n  **fields** (*str*)\n* **Return type:**\n  *AggregateRequest*\n\n#### `scorer(scorer)`\n\nUse a different scoring function to evaluate document relevance.\nDefault is TFIDF.\n\n* **Parameters:**\n  **scorer** (*str*) – The scoring function to use\n  (e.g. TFIDF.DOCNORM or BM25)\n* **Return type:**\n  *AggregateRequest*\n\n#### `sort_by(*fields, **kwargs)`\n\nIndicate how the results should be sorted. This can also be used for\n*top-N* style queries\n\n### `Parameters`\n\n- **fields**: The fields by which to sort. This can be either a single\n  : field or a list of fields. If you wish to specify order, you can\n    use the Asc or Desc wrapper classes.\n- **max**: Maximum number of results to return. This can be\n  : used instead of LIMIT and is also faster.\n\nExample of sorting by foo ascending and bar descending:\n\n``\nsort_by(Asc(\"@foo\"), Desc(\"@bar\"))\n``\n\nReturn the top 10 customers:\n\n``\nAggregateRequest()            .group_by(\"@customer\", r.sum(\"@paid\").alias(FIELDNAME))            .sort_by(Desc(\"@paid\"), max=10)\n``\n\n* **Parameters:**\n  **fields** (*str*)\n* **Return type:**\n  *AggregateRequest*\n\n#### `with_schema()`\n\nIf set, the schema property will contain a list of [field, type]\nentries in the result object.\n\n* **Return type:**\n  *AggregateRequest*\n\n#### `property params: Dict[str, Any]`\n\nReturn the parameters for the aggregation.\n\n* **Returns:**\n  The parameters for the aggregation.\n* **Return type:**\n  Dict[str, Any]\n\n#### `property stopwords: Set[str]`\n\nReturn the stopwords used in the query.\n:returns: The stopwords used in the query.\n:rtype: Set[str]\n\n## TextQuery\n\n### `class TextQuery(text, text_field_name, text_scorer='BM25STD', filter_expression=None, return_fields=None, num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, params=None, stopwords='english')`\n\nBases: `BaseQuery`\n\nTextQuery is a query for running a full text search, along with an optional filter expression.\n\n```python\nfrom redisvl.query import TextQuery\nfrom redisvl.index import SearchIndex\n\nindex = SearchIndex.from_yaml(index.yaml)\n\nquery = TextQuery(\n    text=\"example text\",\n    text_field_name=\"text_field\",\n    text_scorer=\"BM25STD\",\n    filter_expression=None,\n    num_results=10,\n    return_fields=[\"field1\", \"field2\"],\n    stopwords=\"english\",\n    dialect=2,\n)\n\nresults = index.query(query)\n```\n\nA query for running a full text search, along with an optional filter expression.\n\n* **Parameters:**\n  * **text** (*str*) – The text string to perform the text search with.\n  * **text_field_name** (*str*) – The name of the document field to perform text search on.\n  * **text_scorer** (*str* *,* *optional*) – The text scoring algorithm to use.\n    Defaults to BM25STD. Options are {TFIDF, BM25STD, BM25, TFIDF.DOCNORM, DISMAX, DOCSCORE}.\n    See [https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/scoring/](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/scoring/)\n  * **filter_expression** (*Union* *[* *str* *,* [*FilterExpression*]() *]* *,* *optional*) – A filter to apply\n    along with the text search. Defaults to None.\n  * **return_fields** (*List* *[* *str* *]*) – The declared fields to return with search\n    results.\n  * **num_results** (*int* *,* *optional*) – The top k results to return from the\n    search. Defaults to 10.\n  * **return_score** (*bool* *,* *optional*) – Whether to return the text score.\n    Defaults to True.\n  * **dialect** (*int* *,* *optional*) – The RediSearch query dialect.\n    Defaults to 2.\n  * **sort_by** (*Optional* *[* *str* *]*) – The field to order the results by. Defaults\n    to None. Results will be ordered by text score.\n  * **in_order** (*bool*) – Requires the terms in the field to have\n    the same order as the terms in the query filter, regardless of\n    the offsets between them. Defaults to False.\n  * **params** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]* *,* *optional*) – The parameters for the query.\n    Defaults to None.\n  * **stopwords** (*Optional* *[* *Union* *[* *str* *,* *Set* *[* *str* *]* *]*) – The set of stop words to remove\n    from the query text. If a language like ‘english’ or ‘spanish’ is provided\n    a default set of stopwords for that language will be used. Users may specify\n    their own stop words by providing a List or Set of words. if set to None,\n    then no words will be removed. Defaults to ‘english’.\n* **Raises:**\n  * **ValueError** – if stopwords language string cannot be loaded.\n  * **TypeError** – If stopwords is not a valid iterable set of strings.\n\n#### `dialect(dialect)`\n\nAdd a dialect field to the query.\n\n- **dialect** - dialect version to execute the query under\n\n* **Parameters:**\n  **dialect** (*int*)\n* **Return type:**\n  *Query*\n\n#### `expander(expander)`\n\nAdd a expander field to the query.\n\n- **expander** - the name of the expander\n\n* **Parameters:**\n  **expander** (*str*)\n* **Return type:**\n  *Query*\n\n#### `in_order()`\n\nMatch only documents where the query terms appear in\nthe same order in the document.\ni.e. for the query \"hello world\", we do not match \"world hello\"\n\n* **Return type:**\n  *Query*\n\n#### `language(language)`\n\nAnalyze the query as being in the specified language.\n\n* **Parameters:**\n  **language** (*str*) – The language (e.g. chinese or english)\n* **Return type:**\n  *Query*\n\n#### `limit_fields(*fields)`\n\nLimit the search to specific TEXT fields only.\n\n- **fields**: A list of strings, case sensitive field names\n\nfrom the defined schema.\n\n* **Parameters:**\n  **fields** (*List* *[* *str* *]*)\n* **Return type:**\n  *Query*\n\n#### `limit_ids(*ids)`\n\nLimit the results to a specific set of pre-known document\nids of any length.\n\n* **Return type:**\n  *Query*\n\n#### `no_content()`\n\nSet the query to only return ids and not the document content.\n\n* **Return type:**\n  *Query*\n\n#### `no_stopwords()`\n\nPrevent the query from being filtered for stopwords.\nOnly useful in very big queries that you are certain contain\nno stopwords.\n\n* **Return type:**\n  *Query*\n\n#### `paging(offset, num)`\n\nSet the paging for the query (defaults to 0..10).\n\n- **offset**: Paging offset for the results. Defaults to 0\n- **num**: How many results do we want\n\n* **Parameters:**\n  * **offset** (*int*)\n  * **num** (*int*)\n* **Return type:**\n  *Query*\n\n#### `query_string()`\n\nReturn the query string of this query only.\n\n* **Return type:**\n  str\n\n#### `return_fields(*fields)`\n\nAdd fields to return fields.\n\n* **Return type:**\n  *Query*\n\n#### `scorer(scorer)`\n\nUse a different scoring function to evaluate document relevance.\nDefault is TFIDF.\n\nSince Redis 8.0 default was changed to BM25STD.\n\n* **Parameters:**\n  **scorer** (*str*) – The scoring function to use\n  (e.g. TFIDF.DOCNORM or BM25)\n* **Return type:**\n  *Query*\n\n#### `set_filter(filter_expression=None)`\n\nSet the filter expression for the query.\n\n* **Parameters:**\n  **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]* *,* *optional*) – The filter\n  expression or query string to use on the query.\n* **Raises:**\n  **TypeError** – If filter_expression is not a valid FilterExpression or string.\n\n#### `slop(slop)`\n\nAllow a maximum of N intervening non matched terms between\nphrase terms (0 means exact phrase).\n\n* **Parameters:**\n  **slop** (*int*)\n* **Return type:**\n  *Query*\n\n#### `sort_by(field, asc=True)`\n\nAdd a sortby field to the query.\n\n- **field** - the name of the field to sort by\n- **asc** - when True, sorting will be done in asceding order\n\n* **Parameters:**\n  * **field** (*str*)\n  * **asc** (*bool*)\n* **Return type:**\n  *Query*\n\n#### `timeout(timeout)`\n\noverrides the timeout parameter of the module\n\n* **Parameters:**\n  **timeout** (*float*)\n* **Return type:**\n  *Query*\n\n#### `verbatim()`\n\nSet the query to be verbatim, i.e. use no query expansion\nor stemming.\n\n* **Return type:**\n  *Query*\n\n#### `with_payloads()`\n\nAsk the engine to return document payloads.\n\n* **Return type:**\n  *Query*\n\n#### `with_scores()`\n\nAsk the engine to return document search scores.\n\n* **Return type:**\n  *Query*\n\n#### `property filter: str | `[`FilterExpression`]()` `\n\nThe filter expression for the query.\n\n#### `property params: Dict[str, Any]`\n\nReturn the query parameters.\n\n#### `property query: BaseQuery`\n\nReturn self as the query object.\n\n## FilterQuery\n\n### `class FilterQuery(filter_expression=None, return_fields=None, num_results=10, dialect=2, sort_by=None, in_order=False, params=None)`\n\nBases: `BaseQuery`\n\nA query for running a filtered search with a filter expression.\n\n* **Parameters:**\n  * **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]*) – The optional filter\n    expression to query with. Defaults to ‘\\*’.\n  * **return_fields** (*Optional* *[* *List* *[* *str* *]* *]* *,* *optional*) – The fields to return.\n  * **num_results** (*Optional* *[* *int* *]* *,* *optional*) – The number of results to return. Defaults to 10.\n  * **dialect** (*int* *,* *optional*) – The query dialect. Defaults to 2.\n  * **sort_by** (*Optional* *[* *str* *]* *,* *optional*) – The field to order the results by. Defaults to None.\n  * **in_order** (*bool* *,* *optional*) – Requires the terms in the field to have the same order as the\n    terms in the query filter. Defaults to False.\n  * **params** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]* *,* *optional*) – The parameters for the query. Defaults to None.\n* **Raises:**\n  **TypeError** – If filter_expression is not of type redisvl.query.FilterExpression\n\n#### `dialect(dialect)`\n\nAdd a dialect field to the query.\n\n- **dialect** - dialect version to execute the query under\n\n* **Parameters:**\n  **dialect** (*int*)\n* **Return type:**\n  *Query*\n\n#### `expander(expander)`\n\nAdd a expander field to the query.\n\n- **expander** - the name of the expander\n\n* **Parameters:**\n  **expander** (*str*)\n* **Return type:**\n  *Query*\n\n#### `in_order()`\n\nMatch only documents where the query terms appear in\nthe same order in the document.\ni.e. for the query \"hello world\", we do not match \"world hello\"\n\n* **Return type:**\n  *Query*\n\n#### `language(language)`\n\nAnalyze the query as being in the specified language.\n\n* **Parameters:**\n  **language** (*str*) – The language (e.g. chinese or english)\n* **Return type:**\n  *Query*\n\n#### `limit_fields(*fields)`\n\nLimit the search to specific TEXT fields only.\n\n- **fields**: A list of strings, case sensitive field names\n\nfrom the defined schema.\n\n* **Parameters:**\n  **fields** (*List* *[* *str* *]*)\n* **Return type:**\n  *Query*\n\n#### `limit_ids(*ids)`\n\nLimit the results to a specific set of pre-known document\nids of any length.\n\n* **Return type:**\n  *Query*\n\n#### `no_content()`\n\nSet the query to only return ids and not the document content.\n\n* **Return type:**\n  *Query*\n\n#### `no_stopwords()`\n\nPrevent the query from being filtered for stopwords.\nOnly useful in very big queries that you are certain contain\nno stopwords.\n\n* **Return type:**\n  *Query*\n\n#### `paging(offset, num)`\n\nSet the paging for the query (defaults to 0..10).\n\n- **offset**: Paging offset for the results. Defaults to 0\n- **num**: How many results do we want\n\n* **Parameters:**\n  * **offset** (*int*)\n  * **num** (*int*)\n* **Return type:**\n  *Query*\n\n#### `query_string()`\n\nReturn the query string of this query only.\n\n* **Return type:**\n  str\n\n#### `return_fields(*fields)`\n\nAdd fields to return fields.\n\n* **Return type:**\n  *Query*\n\n#### `scorer(scorer)`\n\nUse a different scoring function to evaluate document relevance.\nDefault is TFIDF.\n\nSince Redis 8.0 default was changed to BM25STD.\n\n* **Parameters:**\n  **scorer** (*str*) – The scoring function to use\n  (e.g. TFIDF.DOCNORM or BM25)\n* **Return type:**\n  *Query*\n\n#### `set_filter(filter_expression=None)`\n\nSet the filter expression for the query.\n\n* **Parameters:**\n  **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]* *,* *optional*) – The filter\n  expression or query string to use on the query.\n* **Raises:**\n  **TypeError** – If filter_expression is not a valid FilterExpression or string.\n\n#### `slop(slop)`\n\nAllow a maximum of N intervening non matched terms between\nphrase terms (0 means exact phrase).\n\n* **Parameters:**\n  **slop** (*int*)\n* **Return type:**\n  *Query*\n\n#### `sort_by(field, asc=True)`\n\nAdd a sortby field to the query.\n\n- **field** - the name of the field to sort by\n- **asc** - when True, sorting will be done in asceding order\n\n* **Parameters:**\n  * **field** (*str*)\n  * **asc** (*bool*)\n* **Return type:**\n  *Query*\n\n#### `timeout(timeout)`\n\noverrides the timeout parameter of the module\n\n* **Parameters:**\n  **timeout** (*float*)\n* **Return type:**\n  *Query*\n\n#### `verbatim()`\n\nSet the query to be verbatim, i.e. use no query expansion\nor stemming.\n\n* **Return type:**\n  *Query*\n\n#### `with_payloads()`\n\nAsk the engine to return document payloads.\n\n* **Return type:**\n  *Query*\n\n#### `with_scores()`\n\nAsk the engine to return document search scores.\n\n* **Return type:**\n  *Query*\n\n#### `property filter: str | `[`FilterExpression`]()` `\n\nThe filter expression for the query.\n\n#### `property params: Dict[str, Any]`\n\nReturn the query parameters.\n\n#### `property query: BaseQuery`\n\nReturn self as the query object.\n\n## CountQuery\n\n### `class CountQuery(filter_expression=None, dialect=2, params=None)`\n\nBases: `BaseQuery`\n\nA query for a simple count operation provided some filter expression.\n\n* **Parameters:**\n  * **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]*) – The filter expression to\n    query with. Defaults to None.\n  * **params** (*Optional* *[* *Dict* *[* *str* *,* *Any* *]* *]* *,* *optional*) – The parameters for the query. Defaults to None.\n  * **dialect** (*int*)\n* **Raises:**\n  **TypeError** – If filter_expression is not of type redisvl.query.FilterExpression\n\n```python\nfrom redisvl.query import CountQuery\nfrom redisvl.query.filter import Tag\n\nt = Tag(\"brand\") == \"Nike\"\nquery = CountQuery(filter_expression=t)\n\ncount = index.query(query)\n```\n\n#### `dialect(dialect)`\n\nAdd a dialect field to the query.\n\n- **dialect** - dialect version to execute the query under\n\n* **Parameters:**\n  **dialect** (*int*)\n* **Return type:**\n  *Query*\n\n#### `expander(expander)`\n\nAdd a expander field to the query.\n\n- **expander** - the name of the expander\n\n* **Parameters:**\n  **expander** (*str*)\n* **Return type:**\n  *Query*\n\n#### `in_order()`\n\nMatch only documents where the query terms appear in\nthe same order in the document.\ni.e. for the query \"hello world\", we do not match \"world hello\"\n\n* **Return type:**\n  *Query*\n\n#### `language(language)`\n\nAnalyze the query as being in the specified language.\n\n* **Parameters:**\n  **language** (*str*) – The language (e.g. chinese or english)\n* **Return type:**\n  *Query*\n\n#### `limit_fields(*fields)`\n\nLimit the search to specific TEXT fields only.\n\n- **fields**: A list of strings, case sensitive field names\n\nfrom the defined schema.\n\n* **Parameters:**\n  **fields** (*List* *[* *str* *]*)\n* **Return type:**\n  *Query*\n\n#### `limit_ids(*ids)`\n\nLimit the results to a specific set of pre-known document\nids of any length.\n\n* **Return type:**\n  *Query*\n\n#### `no_content()`\n\nSet the query to only return ids and not the document content.\n\n* **Return type:**\n  *Query*\n\n#### `no_stopwords()`\n\nPrevent the query from being filtered for stopwords.\nOnly useful in very big queries that you are certain contain\nno stopwords.\n\n* **Return type:**\n  *Query*\n\n#### `paging(offset, num)`\n\nSet the paging for the query (defaults to 0..10).\n\n- **offset**: Paging offset for the results. Defaults to 0\n- **num**: How many results do we want\n\n* **Parameters:**\n  * **offset** (*int*)\n  * **num** (*int*)\n* **Return type:**\n  *Query*\n\n#### `query_string()`\n\nReturn the query string of this query only.\n\n* **Return type:**\n  str\n\n#### `return_fields(*fields)`\n\nAdd fields to return fields.\n\n* **Return type:**\n  *Query*\n\n#### `scorer(scorer)`\n\nUse a different scoring function to evaluate document relevance.\nDefault is TFIDF.\n\nSince Redis 8.0 default was changed to BM25STD.\n\n* **Parameters:**\n  **scorer** (*str*) – The scoring function to use\n  (e.g. TFIDF.DOCNORM or BM25)\n* **Return type:**\n  *Query*\n\n#### `set_filter(filter_expression=None)`\n\nSet the filter expression for the query.\n\n* **Parameters:**\n  **filter_expression** (*Optional* *[* *Union* *[* *str* *,* [*FilterExpression*]() *]* *]* *,* *optional*) – The filter\n  expression or query string to use on the query.\n* **Raises:**\n  **TypeError** – If filter_expression is not a valid FilterExpression or string.\n\n#### `slop(slop)`\n\nAllow a maximum of N intervening non matched terms between\nphrase terms (0 means exact phrase).\n\n* **Parameters:**\n  **slop** (*int*)\n* **Return type:**\n  *Query*\n\n#### `sort_by(field, asc=True)`\n\nAdd a sortby field to the query.\n\n- **field** - the name of the field to sort by\n- **asc** - when True, sorting will be done in asceding order\n\n* **Parameters:**\n  * **field** (*str*)\n  * **asc** (*bool*)\n* **Return type:**\n  *Query*\n\n#### `timeout(timeout)`\n\noverrides the timeout parameter of the module\n\n* **Parameters:**\n  **timeout** (*float*)\n* **Return type:**\n  *Query*\n\n#### `verbatim()`\n\nSet the query to be verbatim, i.e. use no query expansion\nor stemming.\n\n* **Return type:**\n  *Query*\n\n#### `with_payloads()`\n\nAsk the engine to return document payloads.\n\n* **Return type:**\n  *Query*\n\n#### `with_scores()`\n\nAsk the engine to return document search scores.\n\n* **Return type:**\n  *Query*\n\n#### `property filter: str | `[`FilterExpression`]()` `\n\nThe filter expression for the query.\n\n#### `property params: Dict[str, Any]`\n\nReturn the query parameters.\n\n#### `property query: BaseQuery`\n\nReturn self as the query object.\n",
  "tags": [],
  "last_updated": "2026-04-01T08:10:08-05:00"
}

