jcardena.com Blog My first real RAG prototype, at 44, after 20 years in data
145 posts
EN ES

My first real RAG prototype, at 44, after 20 years in data

AI

Building a production-ready RAG system at 44 taught me that success isn't in the LLM, but in the data pipeline. A practitioner's guide to robust AI architecture.

For twenty years, my world had primary keys. Data had schemas, joins were deterministic, and ambiguity was an error state to be eliminated. When I sat down at 44 to build my first real Retrieval-Augmented Generation (RAG) prototype, I thought the hard part would be the "G" — the strange new world of probabilistic text. I was completely wrong.

The concept, first detailed in a 2020 paper from Lewis et al. titled Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, felt like a departure. But in practice, the real work wasn't wrestling with the model. It was building a robust data pipeline to feed it.

The Lure of the Five-Line Demo

My first attempt felt like a superpower. With a library like LlamaIndex or LangChain, I had a chatbot answering questions about my documents in twenty lines of Python. It's a powerful illusion. This "Hello, World" of RAG works just well enough to convince you the problem is solved.

The illusion shattered when I tried to build something reliable. When a user asked, "What does the Q3 architecture review say about project Nova?" it pulled a snippet from a Q1 document that also mentioned "Nova." The context was thematically similar but factually wrong. The system was brittle, unpredictable, and I had no idea why.

Unstructured DocsSimple ChunkingVector StoreLLM Prompt
The Deceptive Five-Line RAG Demo

A Data Pipeline in Disguise

My frustration came from treating text like a messy database I just needed to "query" better. The shift happened when I stopped focusing on the LLM and started treating retrieval as the core engineering problem. I reframed it with the instincts I've used to build data systems for two decades.

  • Ingestion is transformation. Naive 1000-character splits are like importing a CSV without handling data types. Real ingestion required semantic chunking—parsing documents to split along logical boundaries like markdown headers (`##`). Critically, I also had to embed not just the text but its source metadata: the document ID, the section title, the last modified date.
  • Indexing needs more than vectors. A vector store alone is not enough. Relying only on cosine similarity is a recipe for retrieving passages that are thematically close but factually wrong. The answer was hybrid search, combining vector search with classic keyword search (like BM25) to catch specific terms. As resources like Pinecone's guide on hybrid search explain, this blend of approaches provides far more relevant results.
  • Retrieval is a multi-stage query plan. The user's question is just the start. The robust plan involves transforming the query for better results, hitting the hybrid index, and then—most importantly—re-ranking the top results before passing them to the LLM. The top 20 vector results are first re-ranked with a more accurate cross-encoder to find the true top 5 for the final context.

From Black Box to Glass Box

In the world of structured data, a wrong report is traceable. You can inspect the SQL query, the upstream tables, the ETL job logs. You can find the bug. The simple RAG demo, by contrast, is a black box. The answer is wrong, and all you have is the final output.

The most important architectural decision I made was building for observability from day one. For every single query, my system now logs:

  1. The original user question.
  2. The transformed query sent to the retrieval system.
  3. The exact chunks of text retrieved, with their source metadata.
  4. The final prompt sent to the LLM, including the retrieved context.
  5. The raw response from the LLM.

This isn't just for debugging. It's the ground truth for evaluation. I can now measure the performance of my retrieval step in isolation. Is it pulling the right documents? That’s a measurable, deterministic engineering problem I can solve.

The Durable Pattern

The hype is focused on the model, but the value is created in the pipeline that feeds it. The LLM is a powerful, world-class synthesizer, but it’s only as good as the information you provide. My job as an architect shifted from trying to coax the right answer out of the model with clever prompts to ensuring the model receives unimpeachable context in the first place.

That means focusing on the boring parts: ingestion validation, metadata strategy, retrieval evaluation, and observability hooks. It’s less about being a "prompt engineer" and more about being a pipeline architect. The work is still about building a reliable, deterministic system to inform a probabilistic one—a pattern that holds up through every platform shift.

SOURCESRaw DocumentsStructuredMetadataAPIsINGESTION AND INDEXINGDocument ParserSemantic ChunkerMetadataEnrichmentHybrid IndexRETRIEVAL AND AUGMENTATIONQuery TransformerHybrid SearchCross-EncoderRe-rankerContext BuilderGENERATION AND SERVINGLLM PromptingAPI EndpointObservability Sink
Production RAG as a Data Pipeline

What I Learned Building It

After wrestling with this first real system, a few principles became very clear. For any data professional stepping into this space, this is what I have learned:

  • Invest the majority of your effort in the 'R'. The Generation model is largely a commodity you call via API. Your unique, defensible value is in the quality and architecture of your Retrieval pipeline.
  • Your chunks are your schema. The strategy for chunking text and embedding metadata is the most important design decision you will make. Treat it with the same rigor you'd use for a database schema.
  • Log the retrieved context, always. Without knowing exactly what information was passed to the LLM for a given query, you are flying blind. It is the most critical piece of data for debugging.
  • Evaluate retrieval and generation separately. Build a test suite to measure retrieval quality (precision, recall). A good retrieval score is a leading indicator of a good final answer. Frameworks like RAGAs provide a rigorous way to do this.

The magic of these systems is real. But making that magic hold up in production, at 3am when something breaks, required me to fall back on the hard-won lessons of data engineering. The future here isn’t just about better models; it’s about better pipelines to inform them.

JC
Juan Cardena
Enterprise Architect, Data & AI

Enterprise architect with 25 years across web, software, data, and AI. MIT CDAO ’25. Writing on agentic AI in production.