Programmer.ie Book Published

Retrieval From First Principles

How a system discovers, ranks, filters, and selects evidence from a larger information world, and how to establish whether that evidence improved the outcome.

A search engine can tell us what matched. It cannot tell us what should be trusted, what should be excluded, or whether the choice helped.

Retrieval is the missing link between the much larger information world and the small set of evidence an AI system is allowed to use. It is not embedding, memory, context assembly, generation, or evaluation; those are neighbouring boundaries. Retrieval owns discovery, ranking, filtering, fusion, reranking, and selection of candidate evidence under policy and budget constraints.

Why this book exists

A large corpus can contain the right passage, yet a request can still fail: the term the user used did not match the document vocabulary, the retriever returned a near-duplicate, the passage was topically close but operationally useless, a restriction was applied after the wrong stage, or a persuasive answer was generated from evidence that should never have been admitted. The question is not only whether search found something plausible, but whether it found the right evidence, excluded the wrong evidence, and changed the outcome.

The central distinction

The book keeps these stages separate:

  1. Available information — everything the system could potentially inspect.
  2. Retrieved evidence — what the search process found.
  3. Eligible evidence — what the request’s scope and policy permit.
  4. Selected evidence — what the retrieval budget allows through.
  5. Admitted context — what the model actually receives.
  6. Used evidence — what we can establish the output relied on.
  7. Helpful evidence — what improves independently checked task behaviour under a declared comparison.

A high similarity score is not admissibility. A plausible answer is not proof that the retrieved evidence was used. Each transition has to be justified separately.

The cumulative experiment

The book builds one retrieval system progressively. It starts with a deterministic lexical search over a tiny frozen corpus, then adds identities, chunking, semantic retrieval, filters, fusion, reranking, evidence budgets, complex retrieval controllers, evaluation, and finally a local consumer application with read-only retrieval tools.

Its constructed collections include exact identifiers and jargon, paraphrases, multi-fact questions, contradictions and stale revisions, access-restricted material, and declared absent-evidence requests. External collections add independently prepared judgements and task references, with their sampling and model-exposure limits retained. Measurements are linked to frozen corpora, query splits, configurations and artefacts.

Chapter plan

The thirty-chapter manuscript spans six parts:

Part Chapters Focus
I. Finding Information 01-05 Lexical search, document identity, inverted index, BM25, first baseline
II. Semantic Retrieval 06-10 Parsing and chunking, dense retrieval, ANN and index choice, filters, failure analysis
III. Combining Evidence 11-15 Candidate pipeline, hybrid search, learned sparse and multi-vector, rerankers, budgets
IV. Complex Retrieval 16-21 Routing, rewriting, decomposition, hierarchy, graph retrieval, bounded adaptive stopping
V. Evaluating Retrieval 22-26 Judgments, metrics, experiments, operations, downstream task effects
VI. Complete System 27-30 Reference contract, defensive boundary, real workflow, final proof

Chapters are generated individually or in explicitly approved connected batches. Drafts receive independent technical and editorial review before the author decides readiness.

Build the capstone

The practical trail ends in What We Can Now Prove with a local Pi retrieval extension. Six executable milestones connect the lexical baseline, pinned dense representations, candidate fusion, parent expansion, bounded control and source-qualified tool delivery. Checkpoints in The First Search Baseline, Semantic Failure Analysis and Hard Negatives, Diversity, Coverage, and Evidence Budgets, Graph and Structured Retrieval and Latency, Cost, and Operational Reliability explain what to run and inspect along the way.

The extension searches two named local collections: the thirty chapters and an original teaching fixture. It exposes search, exact-reference opening and observable retrieval traces. Its installed Pi loader and real tools have executed; a model-driven Pi answer remains untested. These demonstrations establish working retrieval plumbing, not generated-answer correctness or a general advantage for hybrid search.

Status

All thirty chapters are present. The research enhancement has assessed the complete manuscript, with consolidated independent review still to follow. Constructed challenges retain same-author visible labels and shared task families; external judgements do not remove sampling or model-exposure uncertainty. The final local consumer ran, but all 140 task-condition outputs failed its frozen format contract. Semantic correctness, causal evidence use and helpfulness remain not measured. Writer and Improve remain not integrated. All thirty chapter flags remain draft = false by author instruction; those flags do not establish scientific or production readiness.

See /solutions/retrieval/ for the eventual applied home of this work.

Contents

Chapters

03

Building an Inverted Index

Find lexical candidates through postings while preserving exact references and the eligible collection view.

04

BM25: Ranking with Terms

Derive an inspectable BM25 variant from term counts, rarity and passage length, then test its limits.

05

The First Search Baseline

Freeze queries and passage judgements, compare lexical methods, and retain failures without confusing ranking with usefulness.

09

Filters, Scope, and Freshness

Gate stale-index candidates against a trusted current view and expose the cost of filtering after a bounded search.

14

Rerankers and Cross-Encoders

Measure a pinned local cross-encoder while preserving the candidate ceiling, input limits and actual cost.

17

Query Rewriting and Expansion

Expose every query transformation and measure gains, uncertainty and extra search work without changing the information need.

21

Bounded Adaptive Retrieval: When to Stop

Decide from observed evidence whether to stop or run one more search within a fixed budget, and distinguish a justified continuation from a successful outcome.

28

Defending the Retrieval Boundary

Keep untrusted source content separate from caller authority, and test exact reference, permission, admission and output boundaries.

30

What We Can Now Prove

Reconstruct the executable system, retain its negative results and state the precise limits of the book's evidence.