Troubleshooting and Optimizing RAG Pipelines: Lessons from Production

lemonade · Insurance · 2024 · source Agentic: no · promotional bias: low · summary-only (no fetched source) · extracted with prompt 0.5.6 (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 RAG troubleshooting

Lemonade needed reliable RAG pipelines for customer-facing insurance automation, where failures can come from missing content, retrieval misses, re-ranker mistakes, or output-formatting problems.

Constraints:

Architecture

The production RAG pipeline separates offline indexing from online querying. Documents are chunked, sometimes summarized by an LLM, embedded, and stored in a vector database. Queries are rewritten or embedded, top-k documents are retrieved, a re-ranker narrows them to top-n, and a generator/composer LLM writes the answer. Troubleshooting uses data cleaning, document-processing tools, critic checks, hyperparameter tuning, embedding fine-tuning, and query rewriting.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  knowledge_base["Knowledge base"] --> data_cleaning_and_document_processing["Data cleaning and document processing"]
  data_cleaning_and_document_processing --> chunker["Chunker"]
  chunker --> embedding_model["Embedding model"]
  embedding_model --> vector_database["Vector database"]
  query_rewriting_layer["Query rewriting layer"] --> retriever["Retriever"]
  vector_database --> retriever
  retriever --> re_ranker["Re-ranker"]
  re_ranker --> generator_llm["Generator LLM"]
  generator_llm --> critic_llm["Critic LLM"]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Knowledge base Contains source documents for customer-facing RAG. Data cleaning and document processing, Chunker
Data cleaning and document processing Removes noisy content and improves complex document extraction. Knowledge base, Chunker
Chunker Splits documents into retrievable chunks. Data cleaning and document processing, Embedding model
Embedding model Creates vectors for chunks and possibly queries. Chunker, Vector database
Vector database Stores embeddings and supports retrieval. Embedding model, Retriever
Query rewriting layer Transforms user questions for better retrieval. Retriever
Retriever Fetches top-k candidate documents. Vector database, Re-ranker
Re-ranker Narrows top-k candidates to top-n final context. Retriever, Generator LLM
Generator LLM Composes the final answer from retrieved context. Re-ranker, Critic LLM
Critic LLM Checks whether answers are grounded and informative. Generator LLM

Data flow

Offline, the knowledge base is cleaned, chunked, optionally summarized, embedded, and stored in a vector database. Online, the user question is rewritten or embedded, the retriever fetches top-k documents, the re-ranker selects top-n, and the generator composes the response, with critic checks used to detect ungrounded answers.

3 supporting quotes
“Index Stage (Offline): This involves taking the knowledge base, passing documents through a chunker to create chunks”summary, stated
“Query Stage (Online): When a user asks a question, it goes through query rewriting/embedding, then the retriever fetches the top-k most relevant documents”summary, stated
“A re-ranker then selects the top-n most relevant from those k documents, and finally a generator/composer LLM writes the final response.”summary, stated

Why this architecture

The two-stage architecture makes RAG failures diagnosable: missing content is an indexing problem, retriever/re-ranker misses are retrieval problems, and hallucinated answers require prompt, critic, or context fixes.

“This distinction between the index and query stages is important because different pain points manifest at different stages”summary, stated
“The presentation covered common pain points in RAG systems including missing content, retriever failures, re-ranker issues, and output formatting problems”summary, stated

Models used: embedding model · generator/composer LLM · critic LLM · re-ranker

Scale

Alternatives considered (roads not taken)

Treat every RAG failure as a generator problem

Rejected because: Failures can originate in missing content, retrieval, re-ranking, or formatting.

“different pain points manifest at different stages, and solutions often target one stage or the other specifically.”summary, stated

Return answers without a grounding check

Rejected because: A critic can prevent nonsense or ungrounded answers from reaching customers.

“implementing a "critic" - an additional LLM call that examines the generated answer, the context, and the user's question”summary, stated

Use standard parsers for complex documents

Rejected because: PDFs and tables often require better document processing tools.

“When dealing with complex documents like PDFs containing tables, standard parsers often fail.”summary, stated

Patterns

rag-retrieval (retrieval pipeline)

The system uses a classic offline-index, online-query RAG architecture.

“## RAG Pipeline Architecture”summary, stated

retrieval-ranking (candidate selection)

A re-ranker selects the top-n most relevant documents from retriever top-k results.

“To clarify the terminology: if you have 1,000 documents in your database, the retriever's job is to return the top-k most relevant (e.g., 10), and the re-ranker's job is to narrow those down to the top-n (e.g., 1). The specific numbers depend on the application.”summary, stated

query-rewriting (retrieval improvement)

The query stage includes query rewriting or embedding before retrieval.

“Query Stage (Online): When a user asks a question, it goes through query rewriting/embedding, then the retriever fetches the top-k most relevant documents from the vector database.”summary, stated

llm-as-judge (grounding check)

A critic LLM checks generated answers against question and context.

“Another approach is implementing a "critic" - an additional LLM call that examines the generated answer, the context, and the user's question to determine whether the answer is actually grounded in the context and addresses the question.”summary, stated

Tradeoffs

Add a critic call.

Chose Extra grounding confidence check over Returning every generated answer directly.

Rationale: The critic prevents ungrounded or non-informative responses from reaching customers.

“This provides a confidence score for whether the response is informative, preventing the system from returning nonsense to customers.”summary, stated

Tune retriever parameters.

Chose Grid search over chunk size and k over Default chunking and retrieval settings.

Rationale: Retriever misses are sensitive to chunking and top-k choices.

“Hyperparameter tuning is recommended, specifically mentioning LlamaIndex's "param tuner" CLI tool that performs grid search optimization on both chunk size and the k value for retrieval automatically.”summary, stated

Gotchas (what bit them)

Missing content produces hallucinations or no-answer behavior.

Root cause: The relevant content may not exist in the knowledge base or vector database.

Resolution: Clean data, improve document processing, and add explicit don't-know behavior.

“The first major issue discussed is when the relevant content simply doesn't exist in the knowledge base or vector database. This typically leads to two outcomes: hallucinations (the LLM invents an answer) or, in better cases, the model admits it doesn't know the answer.”summary, stated

Retriever and re-ranker failures require separate tests.

Root cause: The right document can be absent from top-k or lost during top-n re-ranking.

Resolution: Build an evaluation dataset with known query-document matches and test retriever and re-ranker independently.

“The presenter emphasizes that you need a proper evaluation dataset - a list of queries where you know which documents should be retrieved. You can then run just the retriever to verify that the expected documents appear in its top-k results.”summary, stated

Noisy scraped data harms downstream RAG.

Root cause: Real-world data contains contradictions, XML tags, and irrelevant content.

Resolution: Use data cleaning tools and better document parsers.

“Real-world data often contains contradictions, noise, XML tags from web scraping, and other irrelevant content.”summary, stated

Evaluation

Lemonade recommends evaluating RAG with known query-document pairs, retriever top-k checks, re-ranker top-n checks, and critic confidence on generated answers.

Metrics: 50% of claims fully automated. · Two-second claim approval/reimbursement example. · Retriever top-k and re-ranker top-n recall on known query-document pairs.

“The presenter emphasizes that you need a proper evaluation dataset - a list of queries where you know which documents should be retrieved. You can then run just the retriever to verify that the expected documents appear in its top-k results.”summary, stated

Outcomes

Lemonade serves millions of customers and handles 50% of claims fully automatically.

“shared lessons learned from building and optimizing RAG pipelines in production.”summary, stated