
The problem
Market-basket analysis is one of the oldest questions in retail data: when a basket holds A, how often does it also hold B? The classic answer is a batch job (Apriori, FP-growth) that writes a frozen rule table. The table is stale the day after it is built, and somebody has to own the job that rebuilds it.
The rules are also directional, which a plain co-occurrence count hides. The share of A baskets that also hold B is usually not the share of B baskets that also hold A, and a cross-sell or shelf decision depends on which way the rule points.
How it works
For each anchor category, one _relate over the orders whose basket contains the anchor returns the related categories with the counts behind the lift. Confidence (the share of anchor baskets that also hold B) and support come from the same counts. Rules whose lift interval clears 1 at 95 %, held across all the pairs tested, are ranked by lift, so the table is a query over the current orders rather than a stored artifact.
Pattern Explorer and Basket Rules are one view in the demo now: Patterns › Baskets sweeps the anchors and shows each rule's confidence in both directions and its support, and the anchor filter narrows it to the one anchor you pick.
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.
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.
Add market-basket rules to this codebase using Aito, a predictive database. The feature: mine directional basket rules (when a basket holds A, how often it also holds B) live from our orders, with confidence, lift and support for each rule. 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/basket-rules/ 4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/basket_pairs.py and https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/schema.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. Check the numbers before building the view: compare a few of them against a direct count over the same rows (SQL or a short script), and report any that differ. 7. In the UI, show the evidence behind each number (the counts, the interval or $why), and leave out patterns with too little data behind them. Ask me before changing anything outside the new feature.



