Cart Autofill

One click prefills the basket with the customer's predicted weekly purchases. Used in grocery; same pattern works for B2B reorder flows.

Cart Autofill: screenshot from the Grocery demo
πŸ› GroceryπŸ›’ E-commerce_predict_queryE-commerce
Measured on real dataOne click prefills the basket with the customer's predicted weekly purchases, in grocery. On a real wholesaler's orders (UCI Online Retail II), for buyers with one or two earlier orders, Aito's top suggestion was in their next order 31 % of the time, against 15 % for the strongest of five classical baselines; for buyers with three or more orders the two tie.

The problem

Recurring purchase flows are the most predictable interaction in commerce. The grocery shopper buys roughly the same basket every week. The B2B office manager reorders supplies on a monthly cadence. The pet owner refills food and treats on a stable schedule. Every one of these flows is currently a manual exercise β€” the shopper opens the cart, scrolls through past orders, adds the regulars one by one, scrolls through the catalog for the occasional new item.

The pattern the shopper is reproducing manually IS a predictive query. "What are this customer's likely next purchases?" Aito returns the answer; one button on the cart populates the basket; the shopper reviews and checks out.

How it works

_predict products on the customer's purchase history with exclusiveness false returns the top-N likely next purchases. The cart-autofill UI fires that query when the user clicks the button; the result populates the cart with predicted quantities derived from the customer's typical order shape.

The user reviews the prefilled cart before checkout. Add items not in the prediction; remove items that aren't needed this week. Every adjustment flows back as a signal; the next prediction reflects it. Over time the prefill accuracy improves until the user's typical adjustment is one or two items.

{
  "from": "purchases",
  "where": {
    "customer": "alice@example.com"
  },
  "predict": "productIds",
  "exclusiveness": false,
  "limit": 15
}

For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application. For the whole picture, see predictive e-commerce.

See it live

This use case runs in 2 live demos today, the πŸ› Grocery and πŸ›’ E-commerce demos. Each link opens the view that shows it, where you can inspect the queries that produce the result.

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.

Cart autofill: a prompt for Claude Code
Add cart autofill to this codebase using Aito, a predictive database. The feature: prefill a returning customer's cart with the products they are most likely to order next, from their own order history and what similar customers ordered.

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/cart-autofill/
4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/uci_reorder_service.py and https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/shop_suggestions.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 cart-autofill handle one-off purchases (not part of the regular basket)?

One-off purchases get low confidence in the prediction and stay out of the prefill. The shopper adds them manually in the same session. Over time, if the one-off becomes regular, the conditional probability picks it up and it enters the prefill automatically.

What about seasonal items (Christmas, summer barbecue, back-to-school)?

Conditional on the time window, seasonal items have predictable patterns. _predict with month or season as a condition surfaces them at the right time. The shopper doesn't have to think about "when do I usually order X"; the system surfaces it.

Can cart-autofill work for B2B reorder flows?

Yes β€” the pattern is identical. Office manager prefills the monthly supplies cart; clinic prefills the medical-supply order; warehouse prefills the inventory replenishment. Same _predict, different table.

Does this reduce manual catalog browsing too much?

It reduces the manual reorder of regulars; it doesn't replace catalog browsing for new items. The shopper still browses for discovery; cart-autofill handles the repetitive part. The two compose β€” autofill handles the predictable 80%, browsing handles the new 20%.

How quickly does the prefill adapt to new shopping patterns?

Three observations of a new product in the customer's basket reaches stable prediction. The first new-item purchase is exploratory; by the third, the system has reliable signal that this is part of the pattern.