Cart Completion

Given what is already in the basket, the products this shopper is most likely to add: the Shop's "Picked for you" re-ranks with _recommend, with the cart's categories as context, as items go in.

Cart Completion: screenshot from the E-commerce demo
🛒 E-commerce_recommendE-commerce
In the demoIn the e-commerce demo's Shop, adding a product to the cart re-asks one _recommend over impressions with the cart's and the last order's categories as context; products the cart lifts carry the reason "Goes with your cart".

The problem

A checkout page has one chance to raise the order value, and it has to decide from the whole basket, not from one product. Product-to-product "bought together" lists answer a narrower question; the basket as a whole is the better signal of what the shopper is missing.

How it works

The basket's categories go into the where clause as context.basket_categories, together with the categories of the shopper's last order, and _recommend over past impressions ranks the products by the chance this shopper buys them when shown. The cart's own items are left out. The $why names what lifted each product, and a product the cart lifts is shown with "Goes with your cart".

It replaces the demo's earlier Cart Completion view, which ran _relate over past baskets' categories; category pairs by lift are on Patterns.

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 the 🛒 E-commerce 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.

Cart completion: a prompt for Claude Code
Add cart completion to this codebase using Aito, a predictive database. The feature: rank the products this shopper is most likely to add, with what is already in the cart and their last order as context, from our past product showings.

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-completion/
4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/shop_ranking.py and https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/shop_context.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.