Field notes
A RAG pipeline that survives real documents
Before changing the embedding model, inspect the extracted text, chunk boundaries and sources that reach the answer.
RAG demos use clean markdown. Real work arrives as a scanned purchase order at a slight angle, a 400-page contract with a table spanning eleven pages, and a spreadsheet somebody exported to PDF.
Before changing the embedding model, inspect extraction and chunking. Errors introduced there can leave retrieval searching incomplete or misleading text.
Read your chunks. Today.
Before any other work, dump fifty random chunks from your index and read them as text. Not metrics. The actual strings.
What people find: page numbers and running headers in every chunk, sentences cut mid-clause, table rows flattened into unreadable runs of numbers, footnote markers glued to words, and the same legal boilerplate occupying a third of the index.
Extraction is the real project
Documents fall into three classes and each needs a different path. Trying to use one parser for all three is the root cause of most bad indexes.
- Born-digital text. Extract with a layout-aware parser, keep the reading order, drop the furniture.
- Scans and images. Needs OCR, and needs deskewing and quality checks first. Track a confidence score per page and route low confidence pages to a human or a vision model rather than indexing garbage silently.
- Tables and forms. Do not flatten them into prose. Emit structured rows, then generate a short natural-language description per row group for the embedding, while keeping the structured version for answers.
That last technique is the one that most improved my numbers on financial and legal corpora. Embed a sentence a human would say. Answer from the structured data.
Chunk on structure, not on character count
Fixed-window chunking is convenient and wrong for documents with sections. Split on headings and paragraph boundaries, then merge small pieces up to a target window and split oversized ones at sentence boundaries.
- Target roughly 300 to 800 tokens, with modest overlap.
- Prefix every chunk with its document title and section path. This alone fixes a surprising share of "the retrieval found the right page but the answer was wrong" cases.
- Never let a chunk begin or end mid-sentence. It costs nothing to avoid and hurts measurably when you do not.
- Store metadata: source, section, page, effective date, document type. Cheap to add, and it enables filtered retrieval later.
Retrieve hybrid, then rerank
Vector-only retrieval fails on exactly the queries business users care about: an invoice number, a part code, a specific clause name. Keyword-only fails on paraphrase. Run both and fuse.
- Retrieve 20 to 40 candidates from vector search and from keyword search in parallel.
- Fuse the ranked lists, then rerank with a cross-encoder or a small model.
- Pass the top three to five to the model, with citations attached.
- Apply metadata filters before search, not after. Filtering post-hoc throws away candidates you paid for.
Passing fewer, better passages is also a context and cost decision, which connects directly to context engineering and spend control.
Grounding, or the whole thing is theater
Require every factual claim in the answer to carry a citation to a retrieved chunk, and validate that programmatically. Uncited claims get stripped or the answer gets flagged.
This does two things. It gives users a way to verify, which is what makes the system trustworthy in a legal or financial setting. And it gives you a hallucination metric that needs no judge model, which becomes a first-class signal in your eval suite.
Their embedding model was fine. Every chunk started with the same eleven-word confidentiality header, so everything was similar to everything.
Evaluate retrieval separately from generation
A single end-to-end score cannot tell you which half is broken. Measure them apart.
- Retrieval. For a set of real questions with known source passages, measure whether the right passage appears at all, and where it ranks.
- Generation. Given the correct passages, is the answer right and fully cited.
Measure retrieval and answer quality separately so a failure in one layer does not lead to changes in the other without evidence.
Operational details that decide whether it lasts
- Incremental reindexing keyed on content hash, so reprocessing a corpus is not an all-night job.
- Versioned pipelines. Store which extractor and embedding version produced each chunk. Without this, mixed-quality indexes become unfixable.
- Permission filtering at query time, enforced in the database rather than in the prompt. Retrieval is a data access path and must respect the same rules as any other.
- Freshness. Carry effective dates and prefer current documents, or you will confidently answer from a superseded contract.
The order to work in
- Read fifty chunks. Fix extraction until they read like documents.
- Rechunk on structure with title and section prefixes.
- Add keyword search alongside vectors and fuse.
- Add a reranker and cut what you pass to three to five passages.
- Enforce citations and measure grounding.
- Split retrieval and generation evals, then iterate on the weak one.
Use the sequence to isolate the part of the pipeline that needs work, then compare changes against the same questions. If you have a stalled product build that has to work for a real customer, pilot, or launch, send the project brief. Scope and price are agreed before work starts.
Frequently asked
Why does my RAG pipeline return irrelevant results?
Usually the extraction step, not the embedding model. If your parser emits page headers, broken tables, and mid-sentence chunk boundaries, no retrieval strategy recovers. Read your chunks before tuning anything downstream.
What chunk size should I use?
Chunk on structure rather than on character count. Sections and paragraphs, with a target of roughly 300 to 800 tokens and a small overlap. Fixed-size chunking is what produces fragments that mean nothing on their own.
Do I need hybrid search?
For real business documents, yes. Vector search misses exact identifiers, part numbers, and rare terms. Keyword search misses paraphrase. Run both, fuse the results, then rerank.
Is a reranker worth the latency?
Test reranking against your own question set. For example, retrieve 30 candidates and compare selecting the top 4 with your existing approach, including latency and cost.
Have a stalled product build?
I help founders turn stalled product builds into software ready for a real customer, pilot, or launch.
Show me what exists, what is stuck, and what needs to work. I take ownership of the implementation, test the agreed user journey, and document the handoff.
New field notes also go out on my newsletter. Subscribe on Substack.

Written by
Alex Cinovoj, TechTide AI
Founder & CTO, TechTide AI · CTO & Co-Founder, CPG Playbook. I’m based in Columbus, Ohio, and spent 13 years in IT across support, systems, cloud, architecture, and engineering, and the last 2 years on AI implementation. I’m a Lovable Senior Champion, an earned Discord community-support volunteer role, with 9 Anthropic Academy course completions. Logs over vibes. Production over theater.
More on Production reality
AI agent security, what actually breaks
Agent security includes the credentials, permissions and logs around each tool call. Check what a mistaken or repeated action can reach.
AI agent memory, what to persist
Separate scratchpad, task state, durable facts and audit history. Give each a source, an update path and a retention rule.
AI agent observability, what to log
Record the calls, decisions and outcomes needed to investigate a failed run. Use trace IDs to connect the steps.