When Does Query Expansion Help Agent Memory? A Multi-Seed Study of Selective Expansion and Gate Reliability: what it means for business leaders
A careful, mostly negative study finds that LLM query expansion adds under one point of Recall@5 to dense retrieval over software-agent memory, and that a simple confidence gate picks queries to expand no better than chance.
1. What the method is
Selective Query-Side Expansion, or SQE, is a retrieval policy for agent memory: stores of execution traces that a software agent later searches with natural-language questions. Dense retrieval runs first. If the cosine score of the top result clears a fixed threshold, the dense list is returned unchanged. If it falls below, an LLM writes two hypothetical execution traces and two paraphrases of the question, each is searched against the same unchanged index, and the resulting rankings are merged with Reciprocal Rank Fusion. Nothing in the memory store or its indices is modified. The paper's real contribution is less the method than the test of it: an executed random gate at a matched expansion budget, eight resampled stores, provider-measured token costs, and an oracle upper bound. The author says plainly that most of the findings are negative, which is what makes the paper useful to us.
2. Why the method was developed
Agents that work on code accumulate tracebacks, patch diffs, commands and test output. A later question about that history, such as how an off-by-one line-number bug was fixed, is written in a different register from the stored record, so embedding similarity can miss the right fragment. Generating a hypothetical document and retrieving with it, as HyDE does, is the standard remedy, and the agent analogue is a hypothetical trace. The cost is the objection: every expanded query needs several LLM calls before retrieval can finish. Selective expansion, an old idea in information retrieval, promises to pay that cost only where it helps. The question the paper asks is whether a nearly free signal, the top-1 dense score, can identify those queries. Earlier work on generated expansions rarely ran a random-selection control, so it could not separate the value of expanding some queries from the value of choosing the right ones.
3. Who should care
Teams building memory or retrieval for coding agents and other long-running agents are the direct audience, because this is evidence about where not to spend engineering effort. Platform and infrastructure owners who budget inference should note the cost side: expansion on every query roughly doubled latency and token use in this study for almost no recall. Product leads evaluating vendors that advertise query rewriting, hypothetical-document retrieval or adaptive routing in an agent memory product can use the paper's design as a checklist, asking for a random-gate control at matched budget and results over more than one sampled store. Evaluation and data science staff should care about the method of the study itself, since the oracle analysis is a cheap way to find out how much any gating scheme could ever gain before we build one. Finance has little to act on beyond avoided spend.
4. How the method works
For each query the system retrieves a dense ranking with the BAAI/bge-m3 embedder over a FAISS index and reads the top cosine score. Above the threshold it returns the first ten results. Below it, Qwen3.6-35B-A3B generates two hypothetical traces and two paraphrases. Each trace is searched twice, once densely and once with BM25, and each paraphrase is searched densely, giving six probe lists. The top twenty entries of those lists and of the original dense list are fused with Reciprocal Rank Fusion, which scores an item by summing a reciprocal of its rank across lists, and the top ten are returned. The generated traces are used only as search probes and are never stored. The control variant runs identical code but replaces the score test with seeded random decisions at a similar rate, so any difference between the two isolates what the confidence score contributes.
5. How it was evaluated
The data are SWE-smith agent trajectories produced with SWE-agent and Claude 3.7 Sonnet, split into individual thoughts, actions and observations. Each of eight seeds draws a 5,000-step store from a pool of about 16,500 steps, rebuilds both indices and samples 500 targets, giving 4,000 queries. An LLM that sees each target writes one question about it, with instructions not to copy identifiers or error codes, and only that exact step counts as relevant. Baselines are dense only, BM25 only, their hybrid, paraphrases only, hypothetical traces only, always expand, the random gate, Query2doc in dense and BM25 forms, and an RM3-style feedback method. Metrics are Recall at 1, 5 and 10, with paired bootstrap tests and Holm correction over nine contrasts. Token and latency costs come from a rerun on one seed. The stores overlap by about 30 percent, so the author treats the intervals as descriptive.
6. How it performed
SQE reached 69.4 percent Recall@5 against 68.5 for dense retrieval alone, a 0.9-point gain whose Holm-adjusted p-value is 0.092, while Recall@1 fell from 45.5 to 44.5. It expanded 48 percent of queries and used 405 tokens and 2.8 seconds per query against 899 tokens and 5.4 seconds for always expanding, which scored 69.2. The random gate scored 68.9, statistically indistinguishable from SQE. Query2doc and RM3 did worse than plain dense retrieval. The oracle shows expansion helps 5.3 percent of queries and hurts 4.2, so a perfect gate gains at most 5.3 points. A richer score feature gained 1.1 points in exploratory analysis and is unconfirmed. Limits are substantial: synthetic queries written from the target, one embedder, one generator, one store size, and no measure of whether agents solve more tasks. Our call is to watch: keep plain dense retrieval for agent memory and do not fund query expansion there until someone shows a downstream gain. (Source: arXiv 2611.40323, 2026)
← Back to dossier index