Smart Autocomplete

Predict text completions from user history and corpus patterns. Lower-cost than an LLM and conditioned on actual usage.

Smart Autocomplete: screenshot from the Grocery demo
πŸ› Grocery_queryCross-vertical
In shortPredict text completions from user history and corpus patterns β€” lower-cost than an LLM and conditioned on actual usage.

The problem

Autocomplete in product UIs has gone from "prefix match against a static list" to "AI completion via LLM API" in five years. The new approach works but it's expensive (LLM tokens per keystroke), latency-sensitive (each call adds 100-300ms), and uncalibrated (the suggestions feel plausible but aren't grounded in what users actually type).

The data that should drive autocomplete is in the system already. What the user typed last week, what other users in the same segment typed, what search terms produced results that got clicked. The prefix the current user is typing + the available history defines the conditional probability over likely completions.

How it works

_predict on the query corpus conditioned on the user's prefix and segment returns the ranked likely completions. The keystroke fires the query; sub-50ms response; the dropdown updates with the top-N completions. Each completion is a real prior query (or a real navigation target) β€” not a generated string.

The mechanism handles typos via column distribution similarity. The user types "shampu"; the system finds the highest-conditional-probability completions that start similarly β€” "shampoo," "shampoo organic," "shampoo for kids." Each completion is grounded in what users have actually typed, weighted by what produced successful interactions.

{
  "from": "search_queries",
  "where": {
    "query.prefix": "sham",
    "customer.segment": "family"
  },
  "predict": "query.text",
  "select": ["$p", "query.text"],
  "limit": 8
}

For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application.

See it live

This use case runs in the πŸ› Grocery demo today. Click through to the live application and inspect the queries that produce the result.

Open the live demo β†’

Build it with Claude Code

Paste this prompt into Claude Code, or another coding agent, in your own codebase. It runs Aito locally from the Docker image, reads the API docs written for agents, and follows a working reference implementation.

Smart autocomplete: a prompt for Claude Code
Add smart autocomplete to this codebase using Aito, a predictive database. The feature: suggest the most likely values as the user types in our forms, ranked by context.

1. Run Aito locally: `docker pull ghcr.io/aitohq/aito`, then follow https://aito.ai/docker/ to start it with your own API keys (keep them in the environment, never in code).
2. Read https://aito.ai/docs/api/llms.txt for the v2 query shapes before writing any query.
3. Read the use-case guide: https://aito.ai/use-cases/smart-autocomplete/
4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-accounting-demo/blob/main/src/formfill_service.py
5. Find the matching tables in this codebase, design the Aito schema for them (links between tables where we have foreign keys), and load a sample.
6. Measure before wiring the UI: hold out recent rows and report how often the item actually chosen is in the top 3, against the order we show today.
7. In the UI, show the ranking as suggestions, with the reasons where the query gives them. Nothing is applied without the user.

Ask me before changing anything outside the new feature.

Frequently asked

How does this compare to LLM-based autocomplete (OpenAI, Anthropic)?

LLM autocomplete generates plausible-sounding strings; _predict returns real strings from your data. For product or catalog autocomplete, the latter is more accurate because the suggestions are grounded in what users actually typed. For free-text composition (writing email, drafting documents), the LLM approach is better-suited.

Does this work for non-search autocomplete (form fields, address inputs)?

Yes. Any text field with a corpus of prior values works. Address autocomplete on an address-history table; tag autocomplete on a tag-corpus table; product-name autocomplete on the catalog. Same _predict pattern, different corpus.

How fast is the autocomplete (per keystroke)?

Sub-50ms per keystroke in production. The columnar index does the prefix match plus conditional probability in one pass. For high-volume autocomplete (millions of QPS), the same query latency holds; only the infrastructure scaling changes.

Can autocomplete suggestions be ranked by segment or persona?

Yes. The where clause includes the user's segment or persona; the conditional probability scopes to that segment. "sham" autocompletes differently for family-segment than for single-shopper-segment, derived from the data.

Does this learn from accepted vs ignored suggestions?

Yes. The accept/ignore signal enters the index; subsequent predictions reflect it. Suggestions that consistently get accepted rise in rank; suggestions that get ignored despite being shown sink. No retraining; just normal data flow.