{
  "schema_version": 2,
  "id": "develop/ai/search-and-query/advanced-concepts/autocomplete",
  "title": "Autocomplete with Redis",
  "url": "https://redis.io/docs/latest/develop/ai/search-and-query/advanced-concepts/autocomplete/",
  "summary": "Learn how to use the autocomplete feature of Redis for efficient prefix-based suggestion retrieval.",
  "aliases": [
    "/develop/interact/search-and-query/advanced-concepts/autocomplete",
    "/interact/search-and-query/advanced-concepts/autocomplete/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-11T15:33:04+01:00",
  "page_type": "content",
  "content_hash": "3ee50e0362f3ffccab007d9b2231731063810f96137450c6de0843fc46d07f7e",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Redis Search provides an autocomplete feature using suggestions that are stored in a [trie-based](https://en.wikipedia.org/wiki/Trie) data structure.\nThis feature allows you to store and retrieve ranked suggestions based on user input prefixes, making it useful for applications like search boxes, command completion, and chatbot responses.\n\nThis guide covers how to use the [`FT.SUGADD`](https://redis.io/docs/latest/commands/ft.sugadd), [`FT.SUGGET`](https://redis.io/docs/latest/commands/ft.sugget), [`FT.SUGDEL`](https://redis.io/docs/latest/commands/ft.sugdel), and [`FT.SUGLEN`](https://redis.io/docs/latest/commands/ft.suglen) commands to implement autocomplete, and some examples of how you can use these commands with [`FT.SEARCH`](https://redis.io/docs/latest/commands/ft.search)."
    },
    {
      "id": "add-autocomplete-suggestions",
      "title": "Add autocomplete suggestions",
      "role": "content",
      "text": "To add phrases or words to a suggestions dictionary, use the [`FT.SUGADD`](https://redis.io/docs/latest/commands/ft.sugadd) command.\nYou will assign a score to each entry, which determines its ranking in the results.\n\n[code example]\n\nInteger scores were used in the above examples, but the scores argument is described as being floating point.\nInteger scores are converted to floating point internally.\nAlso, \"`autocomplete`\" in the above examples is just the name of the key; you can use any key name you wish."
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "The `FT.SUGADD` command can take two optional arguments:\n\n* `INCR`: increments the existing entry of the suggestion by the given score instead of replacing the score. This is useful for updating the dictionary based on user queries in real time.\n* `PAYLOAD`: saves a string with the suggestion, which can be fetched by adding the `WITHPAYLOADS` argument to `FT.SUGGET`."
    },
    {
      "id": "retrieve-suggestions",
      "title": "Retrieve suggestions",
      "role": "content",
      "text": "To get autocomplete suggestions for a given prefix, use the [`FT.SUGGET`](https://redis.io/docs/latest/commands/ft.sugget) command.\n\n[code example]\n\nIf you wish to see the scores, use the `WITHSCORES` option:\n\n[code example]"
    },
    {
      "id": "enable-fuzzy-matching",
      "title": "Enable fuzzy matching",
      "role": "content",
      "text": "If you want to allow for small spelling mistakes or typos, use the `FUZZY` option. This option performs a fuzzy prefix search, including prefixes at a [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) of 1 from the provided prefix.\n\n[code example]"
    },
    {
      "id": "optional-arguments-1",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "There are three additional arguments you can use with `FT.SUGGET`:\n\n* `MAX num`: limits the results to a maximum of `num`. The default for `MAX` is 5.\n* `WITHSCORES`: returns the score of each suggestion.\n* `WITHPAYLOADS`: returns optional payloads saved with the suggestions. If no payload is present for an entry, a `nil` reply is returned.\n    [code example]"
    },
    {
      "id": "delete-suggestions",
      "title": "Delete suggestions",
      "role": "content",
      "text": "To remove a specific suggestion from the dictionary, use the `FT.SUGDEL` command.\n\n[code example]\n\nAfter deletion, running `FT.SUGGET autocomplete hell FUZZY` will no longer return \"help me\"."
    },
    {
      "id": "check-the-number-of-suggestions",
      "title": "Check the number of suggestions",
      "role": "content",
      "text": "To get a count of the number of entries in a given suggestions dictionary, use the `FT.SUGLEN` command.\n\n[code example]"
    },
    {
      "id": "use-autocomplete-with-search",
      "title": "Use autocomplete with search",
      "role": "content",
      "text": "A common approach is to:\n\n1. Use FT.SUGGET to suggest query completions as users type in a text field.\n1. Once the user selects a suggestion, run FT.SEARCH using the selected term to get full search results.\n\nExample workflow\n\n1. Get suggestions for a given user input.\n\n    [code example]\n1. Capture the user's selection.\n1. Use the selected suggestion in a full-text search.\n\n    [code example]"
    },
    {
      "id": "when-to-use-autocomplete-versus-full-text-search",
      "title": "When to use autocomplete versus full-text search",
      "role": "content",
      "text": "* Use `FT.SUGGET` when you need fast, real-time prefix-based suggestion retrieval.\n* Use `FT.SEARCH` when you need document retrieval, filtering, and ranking based on relevance."
    },
    {
      "id": "autocomplete-use-cases",
      "title": "Autocomplete use cases",
      "role": "content",
      "text": "The autocomplete feature in Redis Search is useful for:\n\n- **Search box suggestions**: providing live suggestions as users type.\n- **Command completion**: offering autocompletion for CLI tools.\n- **Product search**: suggesting product names in e-commerce applications.\n- **Chatbot responses**: recommending common phrases dynamically."
    }
  ],
  "examples": [
    {
      "id": "add-autocomplete-suggestions-ex0",
      "language": "plaintext",
      "code": "FT.SUGADD autocomplete \"hello world\" 100\nFT.SUGADD autocomplete \"hello there\" 90\nFT.SUGADD autocomplete \"help me\" 80\nFT.SUGADD autocomplete \"hero\" 70",
      "section_id": "add-autocomplete-suggestions"
    },
    {
      "id": "retrieve-suggestions-ex0",
      "language": "plaintext",
      "code": "redis> FT.SUGGET autocomplete \"he\"\n1) \"hero\"\n2) \"help me\"\n3) \"hello world\"\n4) \"hello there\"",
      "section_id": "retrieve-suggestions"
    },
    {
      "id": "retrieve-suggestions-ex1",
      "language": "plaintext",
      "code": "redis> FT.SUGGET autocomplete \"he\" WITHSCORES\n1) \"hero\"\n2) \"40.414520263671875\"\n3) \"help me\"\n4) \"32.65986251831055\"\n5) \"hello world\"\n6) \"31.62277603149414\"\n7) \"hello there\"\n8) \"28.460498809814453\"",
      "section_id": "retrieve-suggestions"
    },
    {
      "id": "enable-fuzzy-matching-ex0",
      "language": "plaintext",
      "code": "redis> FT.SUGGET autocomplete hell FUZZY\n1) \"hello world\"\n2) \"hello there\"\n3) \"help me\"",
      "section_id": "enable-fuzzy-matching"
    },
    {
      "id": "optional-arguments-1-ex0",
      "language": "plaintext",
      "code": "redis> FT.SUGADD autocomplete hero 70 PAYLOAD \"you're no hero\"\n    (integer) 4\n    redis> FT.SUGGET autocomplete \"hr\" FUZZY WITHPAYLOADS\n    1) \"hero\"\n    2) \"you're no hero\"\n    3) \"help me\"\n    4) (nil)\n    5) \"hello world\"\n    6) (nil)\n    7) \"hello there\"\n    8) (nil)",
      "section_id": "optional-arguments-1"
    },
    {
      "id": "delete-suggestions-ex0",
      "language": "plaintext",
      "code": "redis> FT.SUGDEL autocomplete \"help me\"\n(integer) 1",
      "section_id": "delete-suggestions"
    },
    {
      "id": "check-the-number-of-suggestions-ex0",
      "language": "plaintext",
      "code": "redis> FT.SUGLEN autocomplete\n(integer) 3",
      "section_id": "check-the-number-of-suggestions"
    },
    {
      "id": "use-autocomplete-with-search-ex0",
      "language": "plaintext",
      "code": "FT.SUGGET autocomplete \"hel\"",
      "section_id": "use-autocomplete-with-search"
    },
    {
      "id": "use-autocomplete-with-search-ex1",
      "language": "plaintext",
      "code": "FT.SEARCH index \"hello world\"",
      "section_id": "use-autocomplete-with-search"
    }
  ]
}
