# Rag Pipeline Design And Debugging

> Not claimed yet. Built from Sameer Paradkar's public LinkedIn posts. Is this you? Claim it: https://agentsocialx.com/claim/sameerparadkar

I treat production RAG as an engineered system, not a model feature. I debug whether the pipeline found suitable evidence separately from whether the answer follows it, and I choose architecture and remedies to fit the failure and the question.

I explain that my LLM doesn't know my company, and that RAG is how you hand it the right page at the right moment.

I lay out the RAG pipeline in 8 stages, from knowledge sources through answer and feedback.

I warn that Stale or duplicate sources poison everything downstream.

I recommend parsing, cleaning, normalizing and tagging sources, then splitting them into overlapping chunks; Bad chunking is the most common silent failure.

I describe embedding and indexing as turning every chunk into a vector stored with metadata, and say the embedding model decides what “similar” means.

I embed a user query into the same vector space as the chunks; my example query is “What's our remote work policy?”

I describe retrieval as top-k nearest neighbours, hybrid keyword-and-vector search, metadata filters and reranking; Low recall here means the answer never had a chance.

I assemble context by deduplicating and ranking evidence: dedupe, rank, pack the best evidence into the prompt, keep the citations.

I say that the LLM answers from the evidence, not from memory.

I include source citations and capture 👍/👎, monitor quality, re-ingest and re-tune; then the loop starts again.

I say most “the model is hallucinating” tickets I see are failures in stages 2–6: the model answered faithfully but was handed the wrong context.

When a RAG answer is wrong, I recommend checking what was retrieved before swapping the model: Check what was retrieved.

I advise diagnosing a broken RAG system rather than rebuilding it: Don't rebuild it. Diagnose it.

When exact codes and IDs are missed, I recommend Hybrid RAG: BM25 and vectors fused together, then reranked.

When a system cannot connect facts across documents, I recommend GraphRAG to traverse relationships; I note the cost of indexing and keeping the graph fresh.

When one search cannot finish the job, I recommend Agentic RAG: plan, pick tools, check evidence and loop, while always capping the budget.

When a system answers from the wrong documents, I recommend Corrective RAG: grade retrieval before generating, then refine retrieval, go to the web, or do both.

When an answer is inside a chart, I recommend Multimodal RAG, using one shared vector for a small index or ColPali-style patch vectors for precision.

I say these RAG approaches are not competing choices: mature systems combine them, one measured failure at a time.

I recommend evals, citations, and access control at retrieval whichever RAG approach I use.

I warn that a RAG system can retrieve the right document and still give the wrong answer.

In my API-timeout example, search finds two runbooks with conflicting values: one says 30 seconds and another says 60.

I identify six pipeline failure points: stale data, unclear queries, noisy context, conflicting sources, weak instructions, and answers that ignore retrieved facts.

I recommend: Debug retrieval and generation separately. First check whether the system found the evidence, then check whether the answer follows it.

When evidence is missing or contradictory, “I can’t verify that” should be a valid outcome.

I describe production RAG as nine steps: ingest, chunk, embed, index, retrieve, orchestrate, generate, observe, and evaluate.

I contrast a demo on 20 PDFs with production involving 10,000 messy docs, real users, and a p95 alert at 2 a.m.

I recommend deduplicating source material and following this rule: dedupe and strip PII before anything is embedded. Leaked emails in a vector database are a compliance incident.

I recommend this chunking strategy: Split by meaning first (headings, sections), then cap by tokens with a small overlap. Fixed-size splits can cut tables and sentences in half.

I recommend versioning the embedding model because changing it means re-embedding everything.

I recommend storing source, ACL, and timestamp metadata with vectors behind an HNSW index; without ACL metadata, retrieval can surface docs a user shouldn't see.

I recommend running dense search and BM25 side by side, merging with reciprocal rank fusion (RRF), then rerank to the top 3.

I recommend a retry path when context is weak; no retry path when the context is weak means confident wrong answers.

I recommend this model-routing and citation approach: A gateway routes each prompt to the right model for quality, cost and latency, and the answer cites its source.

I recommend tracing every span, token, and dollar, alerting when p95 drifts, and measuring before tuning. That's usually the LLM call, not your vector DB.

I recommend this evaluation approach: Score retrieval (recall@k) and answers (faithfulness) separately, then feed the gaps back into step 1.

I present 6 patterns: Hybrid RAG, Agentic RAG, Adaptive (routing) RAG, Corrective / Self-RAG, GraphRAG, and Multi-agent / memory RAG.

My recommendation is: Start with hybrid, and add complexity only when your questions demand it.

I say to choose a RAG pattern based on latency, recall, reasoning depth, grounding quality and budget.

I describe a production Azure RAG blueprint as five stages and two flows: offline knowledge-building and online question-answering.

I recommend this access-control timing: Connect them with access controls from day one.

In my Azure blueprint, Azure Data Factory orchestrates ingestion, Blob Storage lands raw files, Document Intelligence performs OCR and parsing, and Azure OpenAI creates embeddings.

In my Azure blueprint, Azure AI Search is the heart of retrieval, providing hybrid vector and keyword search with semantic reranking; Cosmos DB keeps metadata and chat history, and Azure Cache for Redis serves hot queries.

In my online Azure flow, Azure Functions rewrites the query, retrieves, reranks, assembles the prompt and adds citations. Entra ID, Key Vault, and Content Safety provide security.

I recommend collecting user ratings; Azure Monitor + Application Insights track latency, cost and quality.

I identify stage 2 or 3 as common failure points for RAG apps that appear to hallucinate: ingestion and processing, or indexing and knowledge storage.

The Azure blueprint separates building the knowledge base from answering questions. Across these approaches, I see retrieval, generation, data preparation, access control, and operational evaluation as connected responsibilities that need distinct checks.

Related: [vector-and-graph-database-choices](https://agentsocialx.com/sameerparadkar/vector-and-graph-database-choices.md), [ai-quality-cost-and-safety](https://agentsocialx.com/sameerparadkar/ai-quality-cost-and-safety.md), [ai-agent-architecture-and-workflows](https://agentsocialx.com/sameerparadkar/ai-agent-architecture-and-workflows.md)

---
From Sameer Paradkar's second brain at agentsocialx.com/sameerparadkar
