Practical Challenges in Building Production RAG Systems

prolego · Tech · year n/a · source Agentic: no · promotional bias: low · source-backed · 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 systems for enterprise documents

Prolego needed to explain why production RAG systems are much harder than tutorial examples: real client data arrives in messy formats, document hierarchy carries meaning, retrieval quality dominates answer quality, and evaluation must test faithfulness to retrieved context rather than only answer correctness.

Constraints:

Architecture

The proposed production RAG architecture parses heterogeneous enterprise documents into a flat but hierarchy-preserving representation, creates chunks whose IDs retain document location, embeds both chunks and user queries, retrieves only the most relevant material, optionally enriches retrieval with summaries, query expansion, metadata, rules, heuristics, or fine-tuned adapters, and sends retrieved context into a generative LLM. The team evaluates not only answer correctness but also whether answers are faithful to the provided context.

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

flowchart LR
  Enterprise_document_sources["Enterprise document sources"] --> Document_parser["Document parser"]
  Document_parser --> Hierarchy_preserving_chunk_store["Hierarchy-preserving chunk store"]
  Hierarchy_preserving_chunk_store --> Embedding_model["Embedding model"]
  Query_expansion_step["Query expansion step"] --> Embedding_model
  Embedding_model --> Retrieval_system["Retrieval system"]
  Hierarchy_preserving_chunk_store --> Retrieval_system
  Summarization_step["Summarization step"] --> Retrieval_system
  Retrieval_system --> Generative_LLM["Generative LLM"]
  Generative_LLM --> Evaluation_workflow["Evaluation workflow"]
  Retrieval_system --> Evaluation_workflow
  User_guidance_layer["User guidance layer"] --> Generative_LLM
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Enterprise document sources Provide policies, procedures, regulations, emails, wikis, PDFs, slides, tables, and other source material. Document parser
Document parser Uses file-type-specific libraries and heuristics to extract text, tables, layout, headings, and document structure. Hierarchy-preserving chunk store
Hierarchy-preserving chunk store Stores flattened chunks with keys or metadata that map back to file, chapter, section, subsection, and paragraph context. Embedding model, Retrieval system
Embedding model Converts chunks and user queries into vector representations for similarity search. Retrieval system
Query expansion step Uses an LLM to rewrite the user question with different vocabulary before retrieval. Embedding model, Retrieval system
Retrieval system Selects relevant chunks using embeddings, metadata, rules, heuristics, summaries, or fine-tuned adapters. Generative LLM, Evaluation workflow
Generative LLM Produces an answer from the user query and retrieved context. Evaluation workflow
Summarization step Condenses source documents or retrieved documents to improve signal-to-noise and fit more useful content in context. Retrieval system, Generative LLM
Evaluation workflow Measures correctness, faithfulness, hallucination risk, and sensitivity to query difficulty. Generative LLM, Retrieval system
User guidance layer Constrains user behavior or adds reasonableness checks when a small process intervention reduces evaluation burden. Generative LLM

Data flow

Enterprise policy, procedure, regulation, email, wiki, slide, PDF, and table sources are parsed with file-type-specific libraries and heuristics. The parser extracts elements, sorts them by page position, identifies headings and structure from fonts or colors, and stores each element in a flat list or dictionary whose key encodes hierarchy. Chunks or summaries are embedded; a user query may be rephrased several ways before embedding; similarity search, metadata filters, rules, or adapters retrieve relevant context; the generator receives only the selected context; and a separate evaluation process checks faithfulness, answer quality, and prompt difficulty.

4 supporting quotes
“we begin with thousands of pages of employe policy documents in emails wikis PDFs basically whatever we have”transcript, stated
“we then split them into chunks of text and then we use an embedding llm to convert them into embeddings”transcript, stated
“we would find an embedding in similar meeting that discusses pets and workplace policies we find find the ones that are most similar take those embeddings convert them back to text”transcript, stated
“send them into the prompt just as I showed you with chat GPT and it generates the response”transcript, stated

Why this architecture

The architecture puts disproportionate effort into parsing, chunking, retrieval, and evaluation because production RAG fails when the right context is lost before generation. Preserving hierarchy keeps exceptions and qualifiers attached to their rules; retrieval experimentation is necessary because chunks that are too small or too large both degrade embeddings; query expansion and summaries improve recall under vocabulary mismatch and context limits; and faithfulness evaluation ensures the final answer is actually supported by retrieved enterprise data rather than by the model’s general knowledge.

4 supporting quotes
“the first challenge that we typically have to overcome is how we parse the documents and parse them in a way that retains important document structure”transcript, stated
“if you get this wrong then the text generation step is going to be based on incorrect information”transcript, stated
“so instead of just a general cosine similarity score between the embeddings”transcript, stated
“faithfulness would show whether it was answering that question correctly based on information that it actually got in its context”transcript, stated

Models used: GPT-4 · ChatGPT · embedding LLMs

Scale

Alternatives considered (roads not taken)

Naively split documents into sentences, paragraphs, or subsections

Rejected because: Chunking without hierarchy can detach exceptions, qualifiers, and negations from the rules they modify.

“if you just naively chunk that into say sentences or even paragraphs or even subsections you may be missing something that's important”transcript, stated
“missing that does not have that's a that's a gamebreaking detail that you can't leave out”transcript, stated

Flatten documents without preserving hierarchy

Rejected because: The team argues for a flat machine-learning-friendly representation whose keys still encode the original document structure.

“usually you want to have some kind of flat representation so even if your document is a hierarchy”transcript, stated
“the key or or a part of that element represents the section like or the hierarchy in the document and and also serves as a unique ID”transcript, stated

Rely only on the best embedding model

Rejected because: The speakers treat retrieval as a larger design space involving chunking, summaries, metadata, rules, heuristics, and adapter tuning.

“the retrieval part is potentially a lot more than just like getting the embedding model right”transcript, stated
“there are different techniques like this uh that kind of multiply the number of different things you could try”transcript, stated

Evaluate only answer correctness

Rejected because: A powerful model can answer correctly from its own knowledge even when retrieval failed, so faithfulness must be evaluated separately.

“faithfulness would show whether it was answering that question correctly based on information that it actually got in its context”transcript, stated
“it just might know the answers right even if you even if you're not retrieving the right documents”transcript, stated

Answer any user query without constraining query quality

Rejected because: The speakers note that user vocabulary and difficulty change retrieval performance, and sometimes user guidance or a reasonableness check is cheaper than six months of engineering.

“when it goes to users they ask questions in a different way or they ask questions using different vocabulary or they just ask harder questions”transcript, stated
“if you can knock out some of the worst stuff with a two-minute conversation with the user you don't have to invest six months of engineering work”transcript, stated

Patterns

rag-retrieval (architecture)

The system retrieves organization-specific chunks and injects them into a prompt so a general LLM can answer from enterprise data.

“the generated response is augmented by the data I retrieved retrieval augmented generation hence the name rag”transcript, stated
“take those embeddings convert them back to text and send them into the prompt”transcript, stated

retrieval-ranking (retrieval)

Production quality depends on ranking the right chunks, not simply computing a vector and accepting whatever comes back first.

“we need to do this embedding search this similarity search this relevance search all different ways of saying the same thing”transcript, stated
“make sure we get the ones that are relevant but we don't overload it and have a lot of extraneous or irrelevant information”transcript, stated

query-rewriting (retrieval)

The team recommends asking an LLM to rephrase the user query in several ways to cover vocabulary mismatch before embedding search.

“have the llm rephrase that a couple of times or generate several similar but different queries using different words”transcript, stated
“the more ways you can phrase that up front or at least cover different rephrasing and vocabulary kind of synonyms it'll often help”transcript, stated

hybrid-search (retrieval)

The speakers explicitly point beyond pure embeddings to combinations with metadata, rules, and heuristics.

“is it just using embeddings or do you need embeddings plus metadata or embeddings Plus rules or heuristics”transcript, stated
“anything you can do to get better retrieval is going to give you better results”transcript, stated

eval-driven-development (quality)

They frame production RAG evaluation around correctness, faithfulness, hallucination, context support, and query difficulty.

“what makes rag applications challenging to evaluate it's like you know we get asked this a lot of time before we start a project”transcript, stated
“there's different aspects of evaluation for rag applications so we could say is it faithful or is it accurate”transcript, stated

llm-as-judge (quality)

Faithfulness evaluation is described as prompting another LLM to generate and evaluate statements from question, answer, and context.

“a lot of these evaluations are not straightforward and actually require llms to do the evaluation”transcript, stated
“you given that that sort of tupal of question and answer and context you you make prompts for another llm”transcript, stated

fine-tuning-adaptation (modeling)

The team mentions fine-tuning embedding models or an adapter between query embeddings and cosine similarity for application-specific matching.

“fine-tuning the embedding model is something that people do or fine-tuning an adapter”transcript, stated
“trying to make a better match for your particular application than what the embedding model would have in it”transcript, stated

data-quality-loop (operations)

The first production task is exploratory data work: get documents into the right format, preserve structure, and verify good data before modeling.

“the first thing you do is you get your data you do exploratory data analysis you make sure you have good data going in”transcript, stated
“how do we get the text how do we get the data and get it in the right format”transcript, stated

Tradeoffs

Use flat representations while preserving hierarchy

Chose flat dictionaries or lists with hierarchy encoded in keys over deeply nested document trees or unstructured flattened text.

Rationale: Flat structures support batch ML operations, but keys retain enough document structure to recover context.

“machine learning models and kind of want these flat data sets or you want to be able to process things in batch”transcript, stated
“the key or or a part of that element represents the section like or the hierarchy in the document and and also serves as a unique ID”transcript, stated

Invest most effort in retrieval

Chose retrieval quality and context selection over treating generation/model choice as the main lever.

Rationale: If retrieval is wrong, generation is based on wrong or stale information regardless of how fluent the generator is.

“I would say the retrieval step is the most important part”transcript, stated
“if you get this wrong then the text generation step is going to be based on incorrect information”transcript, stated

Tune chunk size instead of using a fixed universal chunk

Chose application-specific chunk sizes, overlap, and parent context over sentence-level or full-document embeddings.

Rationale: The right chunk must be narrow enough to search and broad enough to retain meaning.

“there's a sweet spot that requires some finess and some tricks sometimes to get the right amount of context in the chunks”transcript, stated
“maybe there needs to be a sliding window or a window that gets a subsection plus the text from the super section”transcript, stated

Use summaries to improve retrieval or fit context

Chose summary embeddings or summaries of retrieved documents over passing full retrieved documents whenever possible.

Rationale: Summarization can reduce fluff, improve signal-to-noise, and fit more useful context into limited windows.

“use llms to summarize the the documents and then you could either calculate embeddings on those summaries and search over summaries”transcript, stated
“the signal the noise ratio is just higher at that point”transcript, stated

Use practical user constraints when they are cheaper than engineering perfection

Chose user guidance and reasonableness checks over six months of engineering to handle every bad prompt.

Rationale: Some failure modes can be reduced by telling users how to ask or by adding a simple pre-check.

“if you can knock out some of the worst stuff with a two-minute conversation with the user you don't have to invest six months of engineering work”transcript, stated
“the reasonabl check comes back and says Charlie appears to be a pet Charlie canot”transcript, stated

Gotchas (what bit them)

The hardest part may be the box that looks easiest in the RAG diagram.

Root cause: Parsing and chunking must preserve document structure, exceptions, negations, tables, and heterogeneous file formats before retrieval can work.

Resolution: Spend time building parsers, heuristics, flat hierarchy-aware keys, and document-specific chunking logic before optimizing generation.

“you're telling me the biggest challenge is actually the thing that looks like it would be the easiest”transcript, stated
“how we parse the documents and parse them in a way that retains important document structure”transcript, stated

Naive chunking can invert or erase the meaning of policies and records.

Root cause: Rules, exclusions, and negations may live in parent sections or preceding words that are separated from the chunk.

Resolution: Represent hierarchy and include parent context or overlapping windows when chunks need surrounding scope.

“you don't know that it's an exclusion to a rule because that statement that this is an exclusion appeared somewhere else in the hierarchy”transcript, stated
“patient does not have cancer diabetes heart disease like that obviously missing that does not have”transcript, stated

Chunks that are too small or too large both damage retrieval.

Root cause: Sentence-level embeddings miss context, while document-level embeddings compress too much meaning into one vector.

Resolution: Experiment with chunk size, overlap, subsection-plus-parent context, and summary-based retrieval.

“if we take really small pieces of text each sentence you know we generate an embedding for it well we're probably going to miss some context”transcript, stated
“On The Other Extreme if we tried to embed an entire document well it's kind of too much information”transcript, stated

RAG can give a high-confidence stale answer with a source attached.

Root cause: The retrieval step may select an older or wrong document, and the generator will still produce confident text from it.

Resolution: Treat retrieval as the most important investment area and evaluate freshness, relevance, and evidence support.

“your retrieval step gets an older document with outdated information then you're going to be uh receiving an outdated answer with a pretty high confidence”transcript, stated
“it might even Source you know where it it came from in which gives you confidence that it's correct but it it might not be”transcript, stated

Correctness metrics can hide retrieval failure.

Root cause: GPT-4-like models may know an answer from pretraining even when the retrieved context does not support it.

Resolution: Measure faithfulness separately from correctness using context-grounded evaluation.

“faithfulness is a measure of as a NE inverse measure of hallucinations”transcript, stated
“it just might know the answers right even if you even if you're not retrieving the right documents”transcript, stated

Offline evaluation can miss real user behavior.

Root cause: Evaluation prompts may be easy and well-phrased, while users ask with different vocabulary and harder phrasing.

Resolution: Test query difficulty and user vocabulary, and consider lightweight product guidance or reasonableness checks.

“if I'm evaluating and I'm always asking it easy questions so that's easy to get the right documents”transcript, stated
“when it goes to users they ask questions in a different way or they ask questions using different vocabulary”transcript, stated

Evaluation

The speakers evaluate RAG systems along multiple axes: whether retrieval selects the right context, whether the final answer is factually correct, whether the answer is faithful to the supplied context, whether prompts are easy or hard, and whether user behavior in production matches evaluation prompts. They also describe LLM-as-judge style faithfulness evaluation over question, answer, and context triples.

Metrics: Answer correctness · Faithfulness to retrieved context · Hallucination rate or inverse faithfulness · Retrieval relevance and freshness · Prompt/query difficulty · Sensitivity to user vocabulary · Multiple-choice benchmark accuracy when applicable

4 supporting quotes
“how do you evaluate well that can be tricky because you have to look at the quality of the response”transcript, stated
“does this generate a response is it supported by the evidence that was given or did it hallucinate”transcript, stated
“how easy or difficult are the input prompts or the input queries”transcript, stated
“a lot of these evaluations are not straightforward and actually require llms to do the evaluation”transcript, stated

Outcomes

This is a practitioner discussion rather than a reported deployment metric. It includes concrete operating context such as thousands of pages, thousand-document context limits, a couple of days of PDF parser setup, five or six query rewrites, and the need to support real enterprise formats such as PDFs, Word documents, SharePoint sites, PowerPoint slides, wikis, emails, and tables.

5 supporting quotes
“the first challenge that we typically have to overcome is how we parse the documents”transcript, stated
“I would say the retrieval step is the most important part”transcript, stated
“faithfulness would show whether it was answering that question correctly based on information that it actually got in its context”transcript, stated
“different techniques may work better or less well”transcript, stated
“yet another example of why we won't be replacing data scientists and programmers with AI anytime”transcript, stated