Layered Anytime Retrieval
A retrieval engine that delivers signals, not answers. Many independent layers, one shared contract, one agent that decides.
1. Purpose
This thesis defines a multi-layer, incremental retrieval engine for agent-driven knowledge work. It serves heterogeneous corpora (source code, scientific papers, prose, tool outputs, external APIs) through a single, agnostic interface.
The engine does one thing: it returns well-tagged evidence about where something is. Interpretation, aggregation, ranking policy, and the final conclusion belong to the calling agent, which holds the most context at the latest possible moment.
2. Thesis
- Retrieval answers one question: where does something about X stand? Everything else (answer form, relations, aggregation, negation, conditions) is a property of the query and the reader, not of the index.
- The meaningful design axis is where understanding happens: at indexing time, at query time, or in the agent. The engine should not anticipate what the agent can do better with full query context.
- Retrieval methods are not competing categories. They are layers: independent signal producers with different cost, granularity, and characteristics, composed additively under a time budget set by the caller.
- A retriever is a weaker model than the agent that uses it. Its role is to widen and order the field of view, never to replace judgment.
- Cheap, deterministic, always-current layers come first. Expensive, learned layers refine, correct, and extend, and they are built lazily from actual use.
3. Guiding Principles
| Principle | Meaning | |---|---| | Signals, not conclusions | The engine tags evidence. The agent weighs it. | | Additive layers | A layer can only add information. A missing, partial, or stale layer contributes less, never something wrong. | | Understanding as late as possible | Interpretation is shifted toward query time and toward the agent (late interaction, probing, iterative search). | | Agnostic composition | Layers share only storage, orchestration, and change detection. Chunking, granularity, model, and index format are private to each layer. | | Usage-driven materialization | Layers are built lazily, prioritized by what the agent actually touches. | | Caller-defined quality | The caller sets timebox, target set size, and recall/precision emphasis. | | Incremental updates over retrieval speed | Cheap, granular, abortable updates outrank index compression and lookup latency. | | Lossless by reference | Full outputs stay cached. Reductions are views, never deletions. |
4. The Argument Chain
4.1 A continuum, not categories
Static embeddings, dense bi-encoders, multi-vector late interaction, and cross-encoders are points on shared knobs:
- Granularity: document, section, sentence, token.
- Vectors per unit: one, k, or one per token (adjustable through chunk size, pooling, pruning).
- Capacity per vector: dimension, quantization, Matryoshka truncation.
- Encoder context: isolated lookup, per-chunk encoding, whole-document encoding followed by pooling (late chunking).
- Interaction: none, late (MaxSim), early (cross-encoder).
These knobs trade pre-computation, static share, index size, and query-time interaction against each other. A generic pipeline exposes the knobs instead of committing to one method. Switching along the continuum by fit and threshold (margin, disagreement between signals) is a natural extension.
4.2 Where understanding happens
One axis organizes the whole space:
`` raw text + terms → embeddings, doc2query, type annotations → extracted facts, graphs, summaries → agent as index (no understanding (some interpretation (relations precomputed, (all understanding in the index) precomputed) queries become lookups) at query time) ``
Pre-computed conclusions amortize across many queries but freeze assumptions. Query-time understanding adapts to each question and sees the full context. Raw text is the only lossless end; the agent is the only component that can answer questions nobody foresaw at indexing time.
4.3 Two levels that must not be mixed
- Level 1, the single call: precision, compactness, and speed of the returned material.
- Level 2, the whole prompt: navigability. The tool must be steerable over several calls.
Level 2 is why the project works with multi-vector signals. MaxSim decomposes a score into contributions per query token, each with a concrete counterpart in the document. This yields, without extra machinery:
- Span localization: which sentences carry the match, so chunks can be trimmed.
- State information: which part of the query is covered and which is not.
- Steerable breadth: query-token weights can be changed or zeroed at search time to widen or narrow the result, with no re-indexing.
4.4 The retriever is the weaker model
Dense embeddings fail on private jargon unless trained for it. The agent does not: it learns the vocabulary during the search (a first hit shows the internal term in context, the next query uses it), which is pseudo-relevance feedback with a model as evaluator.
Plain text search with fuzzy matching already imitates multi-vector behavior. Per aspect, the agent runs one search, receives fragments, and combines the findings. That is late interaction with a learned, context-sensitive aggregator instead of a fixed sum. The agent filters with more intent and context than any retrieval model could anticipate, which is the same reason agentic search with grep has displaced vector RAG in coding agents.
4.5 The two-stage pattern
Tool outputs (list, grep, bash, context7, OpenAlex, Exa, and others) are cached. A deterministic filter reduces the signal and returns an ID-associated view. Only a second call retrieves details.
- Smaller turn-over-turn context reduces KV-cache reads in prefill and in every decode step, which directly lowers latency and cost.
- Lossless by reference: the full output stays in the cache. Whether something was filtered or never requested makes no difference to the agent.
- Requesting more is the natural retrieval flow. The extra turn is cheap compared with carrying raw output through every following turn.
- Generic: the same filter works for any tool, and it has not hit a worst case in practice.
5. Architecture
5.1 Overview
`` ┌──────────────────────────────┐ │ Agent │ │ sets timebox, targets, scope │ └──────────────┬───────────────┘ │ status / search / fetch ┌──────────────▼───────────────┐ │ Orchestrator │ │ scope · timebox · tagging · │ │ layer protocol │ └─┬────┬────┬────┬────┬────┬───┘ fast / always current │ │ │ │ │ │ slow / lazily built ▼ ▼ ▼ ▼ ▼ ▼ glob text tri- BM25 AST embeddings … late interaction search gram ┌──────────────────────────────┐ │ Shared: file index · cache · │ │ change detection │ └──────────────────────────────┘ ``
5.2 What is shared, what is private
Shared
- Storage (the file system, plus a central file index).
- The orchestrator.
- Change detection and the extraction cache.
Private to each layer
- Chunking and granularity.
- Model, encoder, and index format.
- Tokenization, normalization, and query language.
- Derived artifacts (summaries, generated questions, descriptions).
5.3 Coordinate system
The only common coordinate is the file: