Search engines / vector databases come with many knobs and dials. Ways to combine retrieval steps, lexical + embedding search, rerankers, etc to pull back the most relevant results. I’ve seen multi-page queries that could make you cry.
Tuning search relevance takes work. But now we have Autoresearch. Given good evals, your coding agent can generate better ranking algorithms, right?
Let’s walk through how I’ve unleashed /goal on Turbopuffer. I’ve built what I feel is a relevance factory a way to unleash fleets of coding agents on your search problem. I’ll start with methodological details: how to unleash models on relevance without overfitting. Then I’ll go through some fun findings on Amazon’s ESCI e-commerce dataset.
In this article
- Broke: my own autoresearch coding harness
- Woke: Just use Claude Code (but with secure test/train splits)
- Caveats and other ways agents can cheat
- Firing up a Turbopuffer relevance factory
- Every type of search has its place on pareto
- Relevance as a software factory
Broke: my own autoresearch coding harness
Unfortunately, naive autoresearch can overfit. If you prompt a coding agent to “improve relevance”, it can litter code with if "shoe" in query, search-this-very-specific-way. Sure that works on the “shoe” queries in the training set, but doesn’t create general ranking algorithm.
So instead of Claude Code, etc, I built my own coding harness for autoresearch (notebook here) to control eval visibility and double check we’re not overfit. Let’s briefly walk my original way of approach this problem, as shown in the diagram below.

In my harness, we might start with a code snippet searching Turbopuffer like
def search(query: str, top_k: int = 10):
normalized_query = query.strip().lower()
results = ns.query(
rank_by=("description", "BM25", normalized_query),
top_k=top_k,
An agent sees this, and proposes search relevance code patches by calling my custom tools. Like check_patch:
def check_patch(...patch...)
"""Patch code search code, measure its impact to some search evals."""
# patch code
search_before = eval(search_code)
search_code_patched = eval(patch(search_code, ...patch...))
# get evals
evals = []
for query in queries:
ndcg_before = eval(search_before(query))
ndcg_after = eval(search_code_patched(query))
evals.append({"query": "query, "ndcg_before": ndcg_before, "ndcg_after": ndcg_after})
return evals
For example this patch suggests weirdly specific ranking for “shoe” searches.
def search(query: str, top_k: int = 10) -> SearchResults:
normalized_query = query.strip().lower()
+ # Shoe queries benefit from stronger description matching.
+ # Weights tuned against the relevance evaluation set.
+ if "shoe" in normalized_query:
+ results = ns.query(
+ rank_by=("Sum", [
+ ("Product", 4.5, ("description", "BM25", normalized_query)),
+ ("Product", 1.25, ("title", "BM25", normalized_query)),
+ ]),
+ top_k=top_k,
+ include_attributes=["title", "description"],
+ )
+ return results.rows
+
return run_search(SearchRequest(query=normalized_query), top_k=top_k)
My harness’s ‘check_patch(…patch…)’ tool creates new search(...) function from the patch. It runs the new function against some evals. The tool calls search("running shoes") thensearch("wireless headphones") repeating for every training query. For each, search generates top K results, labels results as relevant or not. Eventually check_patch generates per-query evals:
| Query | NDCG@10 Before | NDCG@10 After | Δ |
|---|---|---|---|
| running shoes | 0.62 | 0.89 | +0.27 |
| wireless headphones | 0.81 | 0.70 | -0.11 |
| men’s dress shoes | 0.71 | 0.93 | +0.22 |
| laptop stand | 0.79 | 0.67 | -0.12 |
| hiking shoes | 0.58 | 0.86 | +0.28 |
| coffee maker | 0.83 | 0.75 | -0.08 |
| women’s walking shoes | 0.69 | 0.91 | +0.22 |
| bluetooth speaker | 0.77 | 0.64 | -0.13 |
| kids school shoes | 0.65 | 0.88 | +0.23 |
| winter jacket | 0.74 | 0.65 | -0.09 |
| Average | 0.719 | 0.788 | +0.069 |
That goes back to the agent, letting it see how the patch hurt / helped.
I call these queries training queries because I’m treating autoresearch like any other training process. The agent can see the training set. It can inspect every observation completely. It can see how its proposed solutions impact the goals of the process. They’re the observations being actively fitted.
Contrast that with a holdout. The training process (an agent here) would NOT have visibility into these observations. It does not fit to those observations.
We haven’t talked about a holdout set yet. In my home-grown autoresearch loop, the harness checks final solutions against the holdout set.
So, back to our coding agent. Eventually the agent seems satisfied with its tinkering. It attempts to save the change with commit_patch(...patch...) tool. That will save it to disk. Now and this is the important part, hidden from the agent, commit_patch confirms the new search function against holdout queries.

Behind the scenes, without the agent seeing each query’s results, the harness analyzes the new function on a holdout query set.
def commit_patch(...patch...)
"""Patch code search code, measure its impact to some search evals."""
# patch code as above
...
# get evals (same as above, but on a holdout set)
evals = []
for query in holdout_queries:
...
# Compute mean NDCG before and after
holdout_before = mean(e["ndcg_before"] for e in evals)
holdout_after = mean(e["ndcg_after"] for e in evals)
# Only commit if relevance improves
if holdout_after > holdout_before:
commit(patch) # save to disk
return "SUCCESS"
else:
reject(patch)
return "FAIL"
In our case, we compute the following changes on a different query set from above.
| Query | NDCG@10 Before | NDCG@10 After | Δ |
|---|---|---|---|
| trail running shoes | 0.64 | 0.82 | +0.18 |
| wireless headphones | 0.81 | 0.70 | -0.11 |
| laptop stand | 0.79 | 0.67 | -0.12 |
| coffee maker | 0.83 | 0.75 | -0.08 |
| … | … | … | … |
| winter jacket | 0.74 | 0.65 | -0.09 |
| yoga mat | 0.75 | 0.64 | -0.11 |
| Average | 0.769 | 0.704 | -0.065 |
We note on the final line, the negative results on the holdout set. So we reject this change. We tell the agent it failed and to keep trying. But we never tell the agent why / how it failed. Otherwise, it’d just overfit to those too.
Since I control the harness, tools, and agent, I can limit visibility. Models see training queries. They never see holdout queries. That lets holdout act as a final check on overfitting, preventing a primordial soup of if <query> <return_results> nonsense.
Woke: Just use Claude Code (but with secure test/train splits)
It’s annoying to maintain my own harness. OpenCode, Claude Code, Codex etc all do a better job. With visibility over an entire search repo, I could optimize the entire process: indexing, query, and all.
My ideal would be to give an outer orchestrator a /goal like “improve relevance 10% NDCG@10”. The orchestrator generates inspired ideas (“add a title boost” or “train an LTR model” etc etc). It delegates these to relevance tuner subagents. Those subagents access a training set for their work. When the subagent claims to have a change, the orchestrator checks their work against a holdout.

How can I ensure coding agents respect the split?
I created a service called referee. It lets the orchestrator start an ‘eval session’ describing a desired split. It gets back two secure tokens from referee. One token for a training set. Another for a holdout.
Now the orchestrator can hand out one token to subagents to access a training split from referee. And another it can keep for itself as a holdout.
How do we actually generate secure splits?
Let’s walk through the interesting, gory details. Skip ahead if you don’t care. But I think it’s interesting. I’ve diagrammed the flow below:

We want 2000 queries, selected deterministically with seed 42,from Amazon’s ESCI E-commerce dataset. To select consistent 2000 queries, we sort the overall set on hash(seed, query) then select the top 2000 queries. If we repeated the process with same seed and num_queries, we’d get the same set. That lets us (optionally) choose a consistent set across runs.
Let’s walk through a small example. Imagine the full set of queries in our evals looks like this:
| Query |
|---|
| red shoe |
| pampers diapers |
| blue dress |
| dress shoes |
| pizza oven |
| photo album |
And the client wants an eval session with 4 queries, seed=42. We hash the query and seed together, creating a sort key. Imagine sorting on md5(query, seed).
| Query | Client Sort Key=hash(query, 42) |
|---|---|
| red shoe | 43 |
| pampers diapers | 64 |
| blue dress | 14 |
| dress shoes | 55 |
| pizza oven | 98 |
| photo album | 12 |
Sorting, ascending we have:
| Query | Client Sort Key=hash(query, 42) |
|---|---|
| photo album | 12 |
| blue dress | 14 |
| red shoe | 43 |
| dress shoes | 55 |
| pampers diapers | 64 |
| pizza oven | 98 |
We choose the top num_queries=4 of this set.
| Query | Client Sort Key=hash(query, 42) |
|---|---|
| photo album | 12 |
| blue dress | 14 |
| red shoe | 43 |
| dress shoes | 55 |
Next up: splitting the queries. That involves two steps:
- Securely shuffling using a server-side secret clients can’t see
- Splitting (ie 75% into one set, 25% into another…)
Let’s see that in our example. Let’s pretend our server-side secret is 67. We compute a sort key hash(query, 67)
| Query | Client Sort Key=hash(query, 42) | Server Sort Key=hash(query, 67) |
|---|---|---|
| photo album | 12 | 76 |
| blue dress | 14 | 34 |
| red shoe | 43 | 29 |
| dress shoes | 55 | 52 |
Now sort again, on the server’s sort key:
| Query | Client Sort Key=hash(query, 42) | Server Sort Key=hash(query, 67) |
|---|---|---|
| red shoe | 43 | 29 |
| blue dress | 14 | 34 |
| dress shoes | 55 | 52 |
| photo album | 12 | 76 |
With requested split of [0.25, 0.75] we chop off the first 25% for one split. The next 75% for another.
| Query | Client Sort Key=hash(query, 42) | Server Sort Key=hash(query, 67) | Split |
|---|---|---|---|
| red shoe | 43 | 29 | 1 |
| blue dress | 14 | 34 | 2 |
| dress shoes | 55 | 52 | 2 |
| photo album | 12 | 76 | 2 |
The orchestrator receives back two bearer tokens. One for split=1, another for split=2. The orchestrator keeps one token secret for itself. And the second it delegates to subagents as training queries.
Fetching queries and evaluating search
Referee provides an API to fetch queries given a split’s bearer token. Referee’s fetch repeats the same process above. We’ve saved the seed, num_queries, and all parameters to recreate the split in a session database:

Imagine we’re accessing the training set earlier. The subagent works on queries blue dress, dress shoes and photo album. The subagent toils away improving search for queries experimenting with search ideas. They’re able to perform evaluations on these queries, debug them deeply, optimizing away.
How does the subagent debug relevance?
As the subagent’s algorithm produces search results for, say photo album it submits them to referee. Imagine it gets back these three results from its new-fangled algorithm.
| Rank | Product Name |
|---|---|
| 1 | 5x9 picture frame |
| 2 | leather photo album |
| 3 | pocket photo holder |
The subagent submits them to referee. It asks for evals for ‘photo album’. Assuming the subagent has permission (i.e. ‘photo album’ is part of a split in can access) referee labels results as relevant / not using the evals:
| Rank | Product Name | Relevant? |
|---|---|---|
| 1 | 5x9 picture frame | 0 |
| 2 | leather photo album | 1 |
| 3 | pocket photo holder | 1 |
(NDCG=0.56)
It gets back this table as well as the NDCG for this query. Let’s pretend it’s 0.56.
I’m using built-in ESCI labels. And NDCG. But there’s no reason we couldn’t generate our own queries, label with another methodology entirely, or score with whatever metric we want.
The agent can also submit a large set of search results to get evals on the full training set.
| Rank | Query | Product Name |
|---|---|---|
| 1 | photo album | 5x9 picture frame |
| 2 | photo album | leather photo album |
| 3 | photo album | pocket photo holder |
| 1 | dress shoe | leather oxfords |
| … | … | … |
Referee sends back roll-up stats:
{
"dress shoe": 0.76,
"photo album": 0.56,
"blue dress": 0.51
}
When the subagent finishes tuning, it communicates to the orchestrator. The orchestrator repeats the same eval process, but on the holdout set. It then accepts / rejects the change based on whether holdout also improves.
Caveats and other ways agents can cheat
This process isn’t without flaws. Some easier to mitigate than others.
A client-side seed controls the initial set of queries. A subagent that knows the seed could access the full query set by creating the session, defeating the point of a holdout.
My main mitigation to this is to have the orchestrator randomize the seed when starting a session. That ensures that it won’t be known to the subagents. The seed then acts as a private secret the orchestrator keeps hidden.
It also makes me think about per-agent role-based security. Could there be authentication for the orchestrator that cannot pass to subagents without human authorization?
Of course, the big flaw in all this: I’m trusting the orchestrator not to cheat. It could, for example, handout the holdout token to a subagent. T
The biggest check is that I have a third, larger set of queries (in my case, 5000) used to evaluate final experiments for the experiment leaderboard. That’s ideally done outside the visibility of the orchestrator too, by a human, to ensure the entire process works.
In the end, I can’t claim to have built a perfectly secure system. I’m not a security researcher. An extremely determined agent tasked to poke holes likely would find them.
Firing up a Turbopuffer relevance factory
I set up a repo for Turbopuffer relevance optimization. I’ve been burning tokens on optimizing search Amazon’s ESCI e-commerce corpus with different Turbopuffer queries.
To save indexing / inference cost I created one big huge up-front “kitchen sink” Turbopuffer namespace. If you’re new to Turbopuffer a namespace is analagous to an index in Elasticsearch / OpenSearch.
I call it ‘kitchen sink’ because its a maximal set of anything that might possibly be useful. For example, every text field tokenized every possible different way. Such as:
"title": {"type": "string", "filterable": False},
"title__word_v4__default": {
"type": "string",
"full_text_search": {"tokenizer": "word_v4"},
},
"title__word_v4__en__stem_stop": {
"type": "string",
"full_text_search": {
"tokenizer": "word_v4",
"language": "english",
"stemming": True,
"remove_stopwords": True,
},
},
"title__whitespace__default": {
"type": "string",
"full_text_search": {"tokenizer": "whitespace"},
},
"title__kuromoji__ja": { ...
# repeated for title, description, passage, color, ...
We also add one embedding field (voyage-4) using Turbopuffer’s native embedding feature on ‘passage’ - client side concatenation of “{title} \n\n {description}”
"passage__embed__voyage_4": {
"type": "string",
"filterable": False,
"embed": {
"model": "voyage/voyage-4",
"attribute": "embedding__voyage_4__passage",
"dims": 1024,
},
},
In theory, I could autoresearch other forms of indexing. The reality, however, is that there’s going to be a lot to learn from this large set of ingredients. So I haven’t tackled that yet.
My repo documents in AGENTS.md how to use referee and my expected flow (a summary ofthis blog article). Moreover referee itself has /docs endpoint with very detailed agent instructions. The main repo has a vanilla BM25 baseline implemented:
response = ns.query(
rank_by=(
"Sum",
(
("Product", 2.0, ("title__word_v4__en__stem_stop", "BM25", "red shoe")),
("Product", 1.0, ("description__word_v4__en__stem_stop", "BM25", "red shoe")),
),
), top_k=10, include_attributes=["title", "description", "locale"], ) ```
The orchestrator starts a referee session getting tokens for holdout and training sets. It delegates training to [relevance-optimizer subagents][11], intructing them to improve search in their own experiment branches. They're given instructions to move into a git worktree, how to use referee / their token to access training queries, and finally told to communicate with the orchestrator to check final approaches on the holdout.
When subagents think they have promising changes, they commit them to their own worktree. The orchestrator monitors / responds to each subagent and evaluates changes on ESCI holdout evaluations.
Finally, on a consistently seeded set of 5000 queries, I benchmark the final leaderboard. The orchestrator adds those to a table in the repo's main branch's README [you can see here][13]. In the table, you can navigate to inspect each variant. Like this interesting lexical variant that performs some client-side reranking:
local = 0.45 * unique-query-term coverage in title
- 0.20 * adjacent query-pair coverage in title
- 0.15 * exact title phrase
- 0.10 * unique-query-term coverage in brand
- 0.10 * unique-query-term coverage in description score = (1 - boost) * normalized_original_rank + boost * local ```
Coverage hear means percentage of terms present. And normalized_original_rank is the rank in the original BM25 query above.
Every type of search has its place on pareto
When you look at the pareto of relevance vs latency, you see some interesting results.
First there’s a smooth transition from fast / less relevant (lexical). To a bit better / bit slower (hybrid). Then towards LTR solutions. Finally, a third party reranker is best, but slowest (and it turns out much more expensive).

That’s interesting to me. It validates a since that every form of search has a place depending on your ranking trade-offs. Want dirt-cheap, basically free per request, and fast? Then just tune some lexical search. Want a bit better search? Layer in some hybrid search. And so on.
Next steps - more, different eval methods
I’m using traditional search evals. As many have noted, they can have very noisy labels. Increasingly they’re easy to saturate. And they don’t reflect real-world search problems.
So I’d like to experiment with different evaluation methodologies in referee. There’s listwise LLM evaluation methods like Blitzrank we could use. I’ve also written about synthetic traffic and session-based evals that just replay individual user sessions. I’d like to extend this approach to embrace the full world of search evals.
Reoriening relevance towards a factory approach
On past search teams I’ve led, our experiment ideas would be delegated to team members. They’d take weeks to tune and report back. And finally we might put some in an A/B test. Humans would tinker with queries. Humans would discuss and report results.
Why can’t we put relevance in a software factory? In a classic software factory, agents pull down the next ticket, work on them, test and deploy with very little human intervention. Why can’t we do this with relevance experiments?
A step further - there’s no reason for humans to monopolize the search ideas. Why can’t agents also be the ones to propose the experiment? In my work here much of the work was based on me asking the agent “research promising e-commerce directions in lexical search”. Then the orchestrator would just delegate these ideas to subagents to try.
Some problems remain hard. LLMs don’t fully solve evals. Yes they more or less topical relevance for a default audience. They don’t help us predict the kinds of subtle, domain-specific reasons people click, purchase, and convert in search UIs. The sorts of factors where search can feel more like recommender system problems.
Many upstream data tasks help search indexes support better ranking. Often that’s where the real insight occurs. For example page rank in Web search. Or commute distance in job search. Creating these features and amterializing these in an index is its own huge data problem often requiring dedicated teams.
Nevertheless, I suspect how we work as search professionals is about to face a radical shift. It’s not just full-stack webapps that will be placed into the software factory - but all of our work.
If you have feedback on this approach, or want to unleash a search factor on your search, please get in touch. I’d love to chat.
Still time to join: AI-Powered Search — Modern Retrieval for Humans & Agents
Learn the latest AI search skills with the authors of AI-Powered Search. Join Doug Turnbull and Trey Grainger to explore modern retrieval for humans and agents. Explore the course on Maven.