{
  "id": "query_attributes",
  "title": "Query attributes",
  "url": "https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/query_attributes/",
  "summary": "Learn how to use query attributes",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "cbef15289e5b81b077876b72307259b08a8de9aa92bce6d8cbcd5b9cc0c56479",
  "sections": [
    {
      "id": "query-attributes",
      "title": "Query attributes",
      "role": "overview",
      "text": "As of v1.2.0, you can apply specific query modifying attributes to specific clauses of the query.\n\nThe syntax is `(foo bar) => { $attribute: value; $attribute:value; ...}`:\n\n[code example]\n\nThe supported attributes are:\n\n1. **$weight**: determines the weight of the sub-query or token in the overall ranking on the result (default: 1.0).\n2. **$slop**: determines the maximum allowed slop (space between terms) in the query clause (default: 0).\n3. **$inorder**: whether or not the terms in a query clause must appear in the same order as in the query. This is usually set alongside with `$slop` (default: false).\n4. **$phonetic**: whether or not to perform phonetic matching (default: true). Note: setting this attribute to true for fields which were not created as `PHONETIC` will produce an error.\n\nAs of v2.6.1, the query attributes syntax supports these additional attributes:\n\n* **$yield_distance_as**: specifies the distance field name for clauses that yield some distance metric. This is used for later sorting and/or returning. It is currently supported for vector queries only (both KNN and range).\n* **$shard_k_ratio**: controls how many results each shard retrieves relative to the requested top_k in cluster setups. Value range: 0.1 - 1.0 (default: 1.0). Only applicable to vector KNN queries in Redis cluster environments. See [Cluster-specific query parameters]() for detailed information.\n* **vector query params**: pass optional parameters for [vector queries]() in key-value format."
    }
  ],
  "examples": [
    {
      "id": "query-attributes-ex0",
      "language": "plaintext",
      "code": "(foo bar) => { $weight: 2.0; $slop: 1; $inorder: true; }\n~(bar baz) => { $weight: 0.5; }",
      "section_id": "query-attributes"
    }
  ]
}
