Building a Production-Grade Email AI Assistant Using RAG and Multi-Stage Retrieval

shortwave · Tech · 2023 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Production email assistant over personal inbox history

Shortwave wanted an AI executive assistant inside email that could answer personalized questions, compose in a user's voice, cite sources, and search an entire inbox despite heterogeneous data, ambiguous conversational context, prompt limits, privacy constraints, and low-latency product expectations.

Constraints:

Architecture

Shortwave built a four-step assistant around GPT-4 and modular tools. A tool-selection LLM chooses zero, one, or multiple tools based on the query and app context. Tools retrieve data in parallel, with the EmailHistory/AI Search tool running query reformulation, feature extraction, full-text/metadata search, embedding search through Pinecone, heuristic re-ranking, and MS Marco MiniLM cross-encoder re-ranking on Shortwave GPUs. The final answer is generated by a single GPT-4 call with selected context, followed by rich-text conversion, citations, and suggested actions.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  shortwave-app[Shortwave app] --> tool-selection-llm[Tool selection LLM]
  tool-selection-llm --> tool-registry[Tool registry]
  tool-registry --> ai-search-tool[AI Search tool]
  ai-search-tool --> query-reformulator[Query reformulator]
  query-reformulator --> feature-extractors[Feature extractors]
  feature-extractors --> traditional-search-infrastructure[Traditional search infrastructure]
  feature-extractors --> pinecone-vector-database[Pinecone vector database]
  traditional-search-infrastructure --> heuristic-re-ranker[Heuristic re-ranker]
  pinecone-vector-database --> heuristic-re-ranker
  heuristic-re-ranker --> cross-encoder-re-ranker[Cross-encoder re-ranker]
  tool-registry --> compose-tool[Compose tool]
  tool-registry --> calendar-and-thread-tools[Calendar and thread tools]
  tool-registry --> final-answer-llm[Final answer LLM]
  final-answer-llm --> post-processing-layer[Post-processing layer]
  post-processing-layer --> shortwave-app
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Shortwave app Email product surface where users ask questions, view threads/drafts, and receive answers/actions. Tool selection LLM, Post-processing layer
Tool selection LLM GPT-4 call that determines which data tools are needed for the user's question. Shortwave app, Tool registry
Tool registry Modular set of tools for current thread, email history, compose, calendar, current draft, and other app data. Tool selection LLM, AI Search tool, Compose tool, Calendar and thread tools, Final answer LLM
AI Search tool EmailHistory retrieval system that finds and ranks relevant emails across the user's full email history. Tool registry, Query reformulator, Feature extractors, Traditional search infrastructure, Pinecone vector database, Cross-encoder re-ranker
Query reformulator LLM rewrite step that turns context-dependent questions into standalone search queries. AI Search tool, Feature extractors
Feature extractors Parallel fast-LLM extractors for dates, people, keywords, email addresses, labels, recency, and confidence scores. AI Search tool, Traditional search infrastructure, Pinecone vector database, Heuristic re-ranker
Traditional search infrastructure Full-text and metadata search path for precise keyword, date, contact, and label matching. AI Search tool, Heuristic re-ranker
Pinecone vector database Per-user namespace vector store for email embeddings produced by the Instructor embedding model. AI Search tool, Heuristic re-ranker
Heuristic re-ranker Fast local ranking phase combining semantic similarity with extracted dates, contacts, labels, recency, and email category signals. AI Search tool, Cross-encoder re-ranker
Cross-encoder re-ranker MS Marco MiniLM model running on Shortwave GPUs to score selected email fragments for relevance. Heuristic re-ranker, AI Search tool
Compose tool Tool that loads style descriptions and example emails for write-in-your-voice drafting. Tool registry, Final answer LLM
Calendar and thread tools Tools that add calendar, current-thread, current-draft, and visible app state context when relevant. Tool registry, Final answer LLM
Final answer LLM GPT-4 call that generates the final user-facing answer from the selected context and instructions. Tool registry, Post-processing layer
Post-processing layer Rich-text conversion, source citation attachment, and action suggestion layer. Final answer LLM, Shortwave app

Data flow

A user asks Shortwave AI a question. GPT-4 selects the necessary data tools from app state, conversation history, current thread, drafts, calendar, and email history. Selected tools run in parallel; EmailHistory reformulates the query, extracts search features, combines traditional search with Pinecone vector search, narrows and re-ranks fragments, and returns ordered context. Shortwave then sends the original question plus tool context to GPT-4 for one final answer, post-processes the output, adds citations, and suggests actions.

4 supporting quotes
“At a high level, our AI Assistant responds to a question in four steps: tool selection, tool data retrieval, question answering, and post processing.”article, stated
“When you ask the Shortwave AI a question, it immediately passes that query to an LLM. The purpose of this LLM call, though, is not to answer the question, but to determine the types of data that we need to gather in order to answer the question. We call this step “tool selection”.”article, stated
“Once we know what tools we need, we have all of the tools retrieve their data in parallel. Each tool is different. Some are very simple (ie. the “summarize” tool is just custom instructions we include in the prompt) while others are backed by complex distributed systems.”article, stated
“create a prompt containing the original user question and all the context information fetched using various tools, and pass it along to an LLM (GPT-4 in our case)”article, stated

Why this architecture

Shortwave chose a modular tool architecture because email questions require different data sources, but kept the final reasoning in one large GPT-4 call because long LLM chains lost information and accumulated errors. The heavy retrieval complexity lives inside AI Search, which uses hybrid retrieval and two-stage re-ranking to squeeze a user's email history down to a few useful fragments fast enough for a product interaction.

4 supporting quotes
“all reasoning about how to answer a question should be handled by the LLM itself. Our job, was to find the right data and stuff it into the prompt.”article, stated
“In our experience, long LLM call chains introduced data loss and errors at each stage leading to low quality responses. Instead, we settled on a design where the response is generated using a single LLM that includes all context needed to answer the question in one large prompt.”article, stated
“Each type of data (i.e. calendar, email history, draft, etc) would be sourced from a different tool, and the tool would be responsible internally for deciding what specific data to add to the final prompt.”article, stated
“The job of AI search is to find emails that are relevant to answering the user's question from across their entire email history”article, stated

Models used: GPT-4 · GPT-3 · Instructor · MS Marco MiniLM · fast LLM feature extractors

Scale

Alternatives considered (roads not taken)

Break reasoning into long chains of LLM calls

Rejected because: Shortwave found long chains introduced data loss and errors, so the final answer comes from one GPT-4 call with all selected context.

“While we saw other teams building assistants using long chains of LLM calls, with reasoning broken out into stages, we found this approach impractical.”article, stated
“In our experience, long LLM call chains introduced data loss and errors at each stage leading to low quality responses. Instead, we settled on a design where the response is generated using a single LLM that includes all context needed to answer the question in one large prompt.”article, stated

Include all app data in every LLM call

Rejected because: Real-world context windows and loading latency required careful selection of what data to include.

“If we had an LLM with an infinite context window and perfect reasoning, and if loading data from our backend was instantaneous, we could just include all info in every LLM call.”article, stated
“If we had an LLM with an infinite context window and perfect reasoning, and if loading data from our backend was instantaneous, we could just include all info in every LLM call. In a real-world system, however, we have to be very smart about what data we include and what we do not.”article, stated

Use traditional search infrastructure alone

Rejected because: Earlier attempts to turn email history into an actionable knowledge base with traditional search were underwhelming.

“We had always wanted Shortwave to help you turn your email history into an actionable knowledge base, but all of our attempts so far using traditional search infrastructure had been underwhelming. LLMs could change that.”article, stated
“In many cases, keyword and metadata-based searches are not enough to find the emails we are looking for. Fortunately, we have a more powerful semantic-aware search technique that can help us in those cases: vector embedding search.”article, stated

Trust semantic similarity score alone

Rejected because: Semantic scores miss metadata concerns like labels, dates, contacts, recency, and embedding-model inconsistencies.

“However, the semantic similarity score is solely a representation of the knowledge contained within the email content. It does not capture other metadata-specific concerns such as labels, dates, and contacts, while the user question may mention some of them.”article, stated
“It does not capture other metadata-specific concerns such as labels, dates, and contacts, while the user question may mention some of them. Semantic similarity scores are also sensitive to the various inconsistencies that may be inherent within our embedding model.”article, stated

Run the expensive cross-encoder over every retrieved email

Rejected because: The cross-encoder is smarter but slow, so Shortwave first narrows candidates with fast heuristics.

“The model is smarter than our heuristics, but it is also slow. We therefore take only the top-ranked email thread fragments from the previous step, and process them through a cross-encoder model.”article, stated
“We therefore take only the top-ranked email thread fragments from the previous step, and process them through a cross-encoder model.”article, stated

Patterns

tool-use-orchestration (assistant-architecture)

GPT-4 selects which modular tools are needed for a user question, allowing zero, one, or multiple sources such as current thread, email history, calendar, compose, or drafts.

“The purpose of this LLM call, though, is not to answer the question, but to determine the types of data that we need to gather”article, stated
“We allow the tool selection to return zero, one or multiple relevant tools.”article, stated

rag-retrieval (email-search)

AI Search retrieves and ranks relevant email fragments from the user's full history so GPT-4 can answer with grounded inbox context.

“we built an AI assistant for our email app using Retrieval Augmented Generation (RAG).”article, stated
“find emails that are relevant to answering the user's question from across their entire email history”article, stated

query-rewriting (retrieval-preprocessing)

Context-dependent user questions are rewritten into standalone queries before retrieval.

“Query reformulation solves this problem. It takes a query that lacks needed context, and rewrites it using an LLM so that it makes sense on its own.”article, stated
“query reformulation would turn that into “Find emails similar to this email about my flight to Phoenix”.”article, stated

hybrid-search (retrieval)

Shortwave combines full-text/metadata search with embedding-based semantic search and extracted features.

“AI Search throws a huge amount of CPU and GPU horsepower at every question you ask, and uses a combination of both non-AI and AI infrastructure”article, stated
“LLMs, embeddings, vector DBs, full text search, metadata-based search, cross encoding models, and rule-based heuristics.”article, stated

retrieval-ranking (retrieval)

Retrieved emails are narrowed through heuristic scoring and then cross-encoder relevance scoring before being included in the final prompt.

“We re-rank emails in two phases: the first phase uses fast heuristics”article, stated
“The cross-encoder takes our reformulated query and the pre-selected email fragments as input.”article, stated

latency-optimization (production-performance)

The system uses parallel tool retrieval, parallel feature extraction, small-batch loading, streaming, pipelining, and GPU compute to hit 3-5 second latency.

“we have all of the tools retrieve their data in parallel.”article, stated
“The system makes heavy use of concurrency, streaming, and pipelining to pull this off.”article, stated

Tradeoffs

Centralize final reasoning in one large GPT-4 call

Chose single final-answer prompt with selected context over multi-stage LLM reasoning chains.

Rationale: The team trusted GPT-4's reasoning and context window more than brittle chained summaries that could lose data.

“This approach relied on an extremely capable large model and a large context window to work. Fortunately, GPT-4 met the mark.”article, stated
“long LLM call chains introduced data loss and errors at each stage leading to low quality responses.”article, stated

Use modular tools for data sourcing

Chose calendar, email history, draft, compose, and current-thread tools over one monolithic assistant data loader.

Rationale: Tool boundaries made heterogeneous data sources easier to reason about, test, and evolve independently.

“To make our system modular and easier to reason about, we introduced an abstraction called a “Tool”.”article, stated
“Tool selection gives us a simple and structured architecture to build and iterate on.”article, stated

Run embeddings on Shortwave GPU servers and store them in Pinecone

Chose self-hosted Instructor embeddings plus per-user Pinecone namespaces over outsourcing all embedding computation or using a non-namespaced vector store.

Rationale: Self-hosting improved performance, security, and cost; Pinecone namespacing matched the privacy boundary of user email histories.

“We do this on our own servers with GPU acceleration for improved performance, security, and cost.”article, stated
“Then, we store that embedding in our Vector database (Pinecone), namespaced per-user”article, stated

Use heuristic filtering before ML re-ranking

Chose fast local heuristics followed by cross-encoder scoring over cross-encoding every candidate email.

Rationale: The cross-encoder was more accurate but slow, so cheaper metadata-aware heuristics reduced the set first.

“the first phase uses fast heuristics to very quickly cut the list down from a large number to something more manageable”article, stated
“The model is smarter than our heuristics, but it is also slow.”article, stated

Allocate prompt tokens heuristically across tools

Chose heuristics when retrieved content exceeds prompt limits over trying to include all tool outputs equally.

Rationale: EmailHistory usually produces more content than can fit, so the system needs explicit tradeoffs among tools.

“This step often requires us to make tradeoffs about how to allocate tokens between different tools.”article, stated
“We use heuristics here to make those tradeoffs when needed.”article, stated

Gotchas (what bit them)

Long LLM chains lost information and compounded errors.

Root cause: Breaking reasoning into many LLM stages introduced data loss and mistakes at each step.

Resolution: Shortwave used one GPT-4 final-answer call with all selected context in a large prompt.

“long LLM call chains introduced data loss and errors at each stage leading to low quality responses.”article, stated
“the response is generated using a single LLM that includes all context needed to answer the question in one large prompt.”article, stated

Personalized email questions often lack standalone search meaning.

Root cause: Users ask follow-up questions that depend on chat history, visible thread, or current draft context.

Resolution: The AI Search tool reformulates queries using screen and conversation context before retrieval.

“The last user question here, “What about Jonny?”, makes no sense as a standalone question.”article, stated
“Query reformulation considers anything that is visible on the screen that the user might be referring to”article, stated

Email retrieval can return too many candidates for a prompt.

Root cause: Traditional and embedding searches may produce a thousand or more relevant-looking results.

Resolution: Shortwave uses fast heuristic ranking, small-batch loading, length-capped chunks, and cross-encoder re-ranking to reduce candidates to useful fragments.

“Often, this results in a thousand or more results – far too many to fit into a prompt.”article, stated
“we load the emails in small batches, chunking emails into length-capped fragments as we go”article, stated

Semantic similarity alone misses metadata-intent alignment.

Root cause: Embedding scores represent content similarity but not labels, dates, contacts, recency, or feature confidence.

Resolution: Shortwave re-applies local heuristics before and after cross-encoder scoring.

“It does not capture other metadata-specific concerns such as labels, dates, and contacts”article, stated
“We then re-apply our local heuristics (the same ones used in the previous phase) to the scores produced by the cross-encoder.”article, stated

The smartest re-ranker was too slow to use everywhere.

Root cause: MS Marco MiniLM cross-encoder scoring is more accurate than heuristics but computationally expensive.

Resolution: Only top-ranked fragments from the heuristic phase are passed through the cross-encoder.

“The model is smarter than our heuristics, but it is also slow.”article, stated
“We therefore take only the top-ranked email thread fragments from the previous step”article, stated

Evaluation

The article describes production validation through alpha-user concept testing, correctness of summaries, tool-selection examples, confidence-scored feature extraction, retrieval/re-ranking stages, source citation post-processing, and end-to-end latency measurement.

Metrics: almost all questions answered within 3-5 seconds · confidence scores for extracted features · semantic similarity scores · cross-encoder relevance scores · source citations in final output · retrieval narrowed from 1000+ results to a few dozen useful fragments

4 supporting quotes
“After testing many concepts with alpha users, we settled on a simple mental model”article, stated
“Each extracted feature is also assigned a confidence score, indicating how certain we are about the results.”article, stated
“adds source citations, and suggests actions to the user”article, stated
“optimized it to be able to answer almost all questions within 3-5 seconds.”article, stated

Outcomes

The system operates over entire user inbox histories, often narrows 1000+ retrieved results to prompt-sized fragments, and hits 3-5 second latency through concurrency, streaming, pipelining, beefy servers, and high-end GPU clusters.

4 supporting quotes
“AI search is what enables our assistant to have full knowledge of your email history.”article, stated
“post-processing step converts the LLM's output to rich text, adds source citations, and suggests actions to the user”article, stated
“The system makes heavy use of concurrency, streaming, and pipelining to pull this off.”article, stated
“What you see here is our v1. Our team is continuing to iterate rapidly on our design”article, stated