CustomLabs
Topics

Retrieval & RAG

Retrieval-augmented generationRetrieval-Augmented Generation (RAG) retrieves relevant passages at query time and feeds them into an LLM's context. looks simple in a demo and breaks on real corpora — messy PDFs, thin chunking, and stale embeddingsEmbeddings are numeric vectors that place similar content close together in vector space. all masquerade as model problems. This is our work on making retrieval actually hold up in production.

Start with Context EngineeringContext engineering decides what occupies a model's context window at every step, and in what order. if you're building retrieval or RAG. It's for engineers who need their system to reason over real documents, not a clean demo corpus.

In the Handbook

Guides#

Context Engineering

What occupies a context windowThe context window is the maximum text, measured in tokens, a model can consider at once. at every step of a long run, and how to budget, compact, isolate and measure it before it fails.

37 min read Read

Architectures#

Comparisons#

Insights#

Your RAG Demo Lied to You

Retrieval that looks flawless on ten clean PDFs falls apart on a real corpus. Here's why, and what evaluating retrieval quality actually requires.

7 min read Read

Case studies#

Patterns#

Structure-aware chunking

Chunk boundaries follow the document's own structure: headings, table rows, list items, section boundaries, instead of a fixed token count. Each chunk carries its parent heading or identifying context in its own body. A table row is never separated from its header, and a step is never separated from the procedure it belongs to. The chunk that gets embedded is always a complete unit of meaning, not an arbitrary slice.

Read

Retrieve-then-rerank

A cheap, high-recall first pass pulls a wide candidate set of 50 to 100 documents likely to contain the right answer. It's usually vector search, optionally fused with keyword search. A precision reranker, usually a cross-encoder that scores the query and each candidate jointly, then re-sorts that set. It applies a relevance floor, allowed to return nothing rather than force a weak match to the top.

Read

Change-data-capture ingest

The ingest pipeline subscribes to the actual change events of the source system, such as a webhook, a CMS publish hook, or a database trigger. That replaces re-crawling on a fixed schedule. An edit triggers a re-embed within minutes. A delete writes a tombstone that excludes the old chunks from retrieval immediately, before a full re-index even runs.

Read

Failure modes#

Stale index serves deleted content

Your retrieval index was built once at ingest and never told the source changed. When a document is edited or deleted, nothing re-embeds the new version or tombstones the old chunk. The stale vector keeps scoring well and keeps getting served with confidence, giving the reader no signal that it is out of date.

Read

Chunk boundary splits the answer

The answer exists in the source, but a fixed-size chunker cut it in half at ingest time: a table row split from its header, a procedure split from its trigger condition. Each half scores weakly on its own, the ranker drops both, and retrieval reports nothing when the document plainly contains the answer.

Read

Similarity is not relevance

Cosine similarity rewards topical resemblance, not correctness. It can rank a document about the wrong product, the wrong date, or the negated version of a claim above the one that actually answers the query, because embeddings represent "about the same thing" far more reliably than they represent identifiers, negation, or numbers.

Read

Source: https://customlabs.io/topics/retrieval-rag/

navigate select esc close