How Instacart Uses LLMs to Make People Buy More
Instacart structures product search into three core stages: query understanding (QU), retrieval, and ranking, with QU directly informing downstream steps. Their initial approach relied on separate machine learning systems, including a FastText category classifier and a session-mining query rewriter, which created significant maintenance overhead and produced conflicting query interpretations. Furthermore, training these models using behavioral signals like clicks and purchases resulted in noisy data, while rare long-tail queries lacked sufficient historical examples. Consequently, Instacart sought a unified architecture to provide consistent, accurate query understanding across their catalog. While general large language models possess extensive real-world knowledge, they lack specific awareness of Instacart's product catalog and customer behavior. To address this limitation, the Instacart engineering team employs three core techniques: context engineering via retrieval-augmented generation (RAG), post-processing output validation guardrails, and fine-tuning smaller models on proprietary examples. These methods provide business context in prompts, ensure catalog compatibility, and permanently adapt model weights for domain-specific tasks. Instacart upgraded its search classification architecture by transitioning from flat category labels to hierarchical category paths. The new system operates in three stages: candidate generation using historical post-query purchase data, candidate interpretation and re-ranking via a Large Language Model (LLM), and relevance filtering using an embedding-based guardrail. This pipeline allows Instacart to capture complex world knowledge and discard low-confidence, irrelevant category predictions.
Read the original ↗Contents
- 01The Problem With Instacart’s Initial Approach
- 02How a General LLM Becomes Useful for Instacart
- 03How Instacart Knows What the Query Is About
- 04How Instacart Makes The Queries Stronger
- 05Extracting Search Tags from the Query
- 06Teaching the Smaller Model
- 07How Instacart Made the Model Fast For Live Search
- 08Conclusion
The Problem With Instacart’s Initial Approach
Instacart structures product search into three core stages: query understanding (QU), retrieval, and ranking, with QU directly informing downstream steps. Their initial approach relied on separate machine learning systems, including a FastText category classifier and a session-mining query rewriter, which created significant maintenance overhead and produced conflicting query interpretations. Furthermore, training these models using behavioral signals like clicks and purchases resulted in noisy data, while rare long-tail queries lacked sufficient historical examples. Consequently, Instacart sought a unified architecture to provide consistent, accurate query understanding across their catalog.
- Product search is divided into three sequential phases: Query Understanding (QU), retrieval, and ranking.
- Instacart's QU stage produces three key outputs: product categories, alternative queries (rewrites), and structured tags.
- Behavioral data (clicks and purchases) serves as noisy training signals, as purchase decisions do not consistently align with original search intent.
- Long-tail, specific search phrases suffer from limited historical data, whereas broad search queries require handling category ambiguity.
- Maintaining disparate, task-specific pipelines—such as a FastText classifier and session-mined query rewrites—resulted in high operational overhead and contradictory query interpretations.
How a General LLM Becomes Useful for Instacart
While general large language models possess extensive real-world knowledge, they lack specific awareness of Instacart's product catalog and customer behavior. To address this limitation, the Instacart engineering team employs three core techniques: context engineering via retrieval-augmented generation (RAG), post-processing output validation guardrails, and fine-tuning smaller models on proprietary examples. These methods provide business context in prompts, ensure catalog compatibility, and permanently adapt model weights for domain-specific tasks.
- General LLMs already understand broad concepts and ingredient substitutions without task-specific training examples.
- Instacart bridges domain gaps by supplying catalog records and historical patterns via RAG and context engineering.
- Post-processing guardrails validate model outputs against Instacart's catalog to ensure compatibility and suitability.
- Instacart fine-tunes smaller models on high-quality proprietary data rather than relying solely on prompt-based domain guidance.
How Instacart Knows What the Query Is About
Instacart upgraded its search classification architecture by transitioning from flat category labels to hierarchical category paths. The new system operates in three stages: candidate generation using historical post-query purchase data, candidate interpretation and re-ranking via a Large Language Model (LLM), and relevance filtering using an embedding-based guardrail. This pipeline allows Instacart to capture complex world knowledge and discard low-confidence, irrelevant category predictions.
- Instacart catalogs items using hierarchical category paths (e.g., Meat → Beef → Beef Ribs → Short Ribs) to pinpoint catalog locations.
- The legacy classification system treated categories as flat label collections, failing to capture relationships between hierarchical levels.
- The updated system utilizes a three-stage pipeline: candidate generation, LLM interpretation, and guardrail filtering.
- Historical purchase data proposes initial candidate categories based on user behavior following a query.
- An LLM re-ranks candidate categories based on the query and context, enabling understanding of indirect queries like 'vegan roast'.
- An embedding-based guardrail compares semantic similarity between the query and the predicted category path, discarding predictions that fall below a similarity threshold.
How Instacart Makes The Queries Stronger
Instacart improved its search capability by overhauling its query rewriting pipeline using large language models. The previous session-pattern-based system covered only about 50% of search traffic, and initial generic LLM prompting yielded unhelpful variations. To resolve this, Instacart categorized rewrites into synonyms, broader queries, and product substitutes, designing dedicated prompts with guidance and examples for each. Combined with post-processing checks and semantic filters, this task-specific strategy increased rewrite coverage to over 95% with precision exceeding 90%.
- Instacart's original session-based query rewriting system only covered around 50% of search traffic.
- Generic LLM prompting for query rewriting failed because it lacked guidance on what kind of alternative queries were useful.
- Instacart divided query rewriting into three distinct categories: synonym rewrites, broader rewrites, and substitute rewrites.
- Each rewrite category uses a dedicated prompt with specific instructions, reasoning guidance, and examples.
- Outputs undergo post-processing checks and semantic filtering.
- The new rewriting framework increased query rewrite coverage to over 95% with greater than 90% precision across all three rewrite types.
Extracting Search Tags from the Query
Instacart implements semantic role labeling (SRL) to extract structured concepts like products, brands, and attributes from customer search queries to support retrieval, ranking, and filtering. To maintain fast and cost-effective search, the system precomputes and caches tags for frequent head queries. Tail and unseen queries are handled using a teacher-student model architecture. An offline LLM-based teacher pipeline leverages catalog and business context to generate high-quality tags, which both populate the cache and train a smaller, low-latency student model for real-time inference.
- Semantic role labeling (SRL) identifies structured concepts like products, brands, and attributes from user queries to enhance search ranking and filtering.
- Frequent head queries are processed in advance, and their extracted tags are cached to reduce live search latency and computational cost.
- An offline teacher pipeline uses a powerful LLM combined with catalog evidence to generate and validate high-quality query tags.
- Teacher pipeline outputs serve a dual purpose: populating the tag cache and creating training data for a smaller student model.
- Live queries check the cache first, falling back to the fine-tuned smaller student model when cached tags are unavailable.
Teaching the Smaller Model
For its real-time semantic role labeling (SRL) system, Instacart fine-tuned the 8-billion-parameter Llama-3 8B model. The adaptation was performed using LoRA (Low-Rank Adaptation), which trains a small set of parameters while freezing base weights to minimize training requirements. The process leveraged knowledge distillation, training the student model on outputs from a larger frontier teacher model. Analysis revealed that the student model produced fewer incorrect tags, though it missed slightly more correct tags.
- Instacart fine-tuned Llama-3 8B for its real-time SRL system.
- Training was carried out using LoRA, keeping base weights fixed to reduce computational overhead.
- The workflow used knowledge distillation, where the student model learned from outputs produced by a larger teacher model.
- The fine-tuned student model produced fewer incorrect tags but missed slightly more correct tags.
How Instacart Made the Model Fast For Live Search
Instacart optimized its search model serving latency to reach low hundreds of milliseconds, reducing it from an initial 700 ms on an A100 GPU down to their 300 ms target. They achieved this primarily by merging the LoRA adapter directly into the base model weights, cutting latency by 30%, and upgrading to H100 GPUs. Although FP8 quantization provided an additional 10% latency reduction, Instacart chose not to deploy it to maintain result quality and avoid a decline in recall. Furthermore, they implemented caching so that only 2% of queries required live inference, combined with GPU autoscaling to optimize infrastructure costs.
- Instacart's initial model serving setup took roughly 700 milliseconds on an A100 GPU.
- Merging the LoRA adapter into the base model weights eliminated separate inference computation and reduced latency by about 30%.
- Combining the LoRA adapter merge with an upgrade to H100 GPUs allowed Instacart to hit its 300-millisecond latency target.
- FP8 quantization lowered latency by another 10% but caused a slight decline in recall, leading the team to deploy the unquantized model instead.
- Only 2% of live queries required real-time model inference due to effective caching of search tags.
- Instacart implemented GPU autoscaling to reduce compute usage and run fewer GPUs during low-traffic periods.
Conclusion
Instacart evaluated its real-time semantic role labeling (SRL) system using A/B testing on search queries. The system achieved a 6% reduction in average scroll depth and a 50% drop in user complaints regarding poor search results for tail queries, accompanied by only a marginal latency increase. Handling millions of cold-start queries weekly without historical or precomputed data, the architecture uses improved classification, query rewrites, and tags to enhance product discovery. Moving forward, Instacart plans to build upon this foundation to capture a broader view of the shopper's overall journey.
- Instacart's real-time SRL system reduced average scroll depth for tail queries by 6% in A/B testing.
- User complaints concerning poor search results for tail queries dropped by 50% with only a marginal latency increase.
- The system successfully processes millions of cold-start queries every week that lack query-specific history or precomputed answers.
- Enhanced classification, query rewrites, and tags enable shoppers to discover relevant items more quickly.
- Instacart intends to extend the current foundation toward understanding the shopper's broader journey.