ld.← Back to selected workLet’s talk
SELECTED WORK / 02AXY / BACKEND & APPLIED AICASE STUDY

RAG / SCIENTIFIC SEARCH

RAG search.
Know when it’s wrong.

I built a multi-stage search pipeline for scientific research—and the evaluation harness that exposed where it was quietly falling short.

↓

THE TENSION

A plausible result can still be misleading.

A search for “sponge” returned Porifera first—but eight of the top ten were names containing similar letters.

The correct scientific group was less than 0.01 ahead of the next result. The ranking looked convincing, but the narrow gap and the near-matches exposed a deeper problem: matching a term is not the same as finding its meaning. For a research tool, that distinction matters.

THE QUERY / A CLOSER LOOK“sponge”

One query exposed a gap between matching a word and understanding a scientific group.

RETURNED FIRSTPorifera

The correct group, with a lead of less than 0.01 over the second result.

THE REST OF THE TOP 108 / 10

Letter-matching names, including Spongocoelia, Pterospongus, and Heterospongus.

PROJECT

Hybrid retrieval · RAG

MY ROLE

Backend / applied AI engineer

DISCIPLINES

Qdrant · BM25 · BEIR

THE IDEA THAT SHAPED THE SYSTEM

Combine signals. Then test the whole system.

Dense retrieval finds conceptual similarity; BM25 preserves exact terms. I combined their rankings, reranked the candidates with a cross-encoder, and built a benchmark around the production retrieval code so each decision could be measured.

A better route to context.

A simplified view of the retrieval path, from a researcher’s query to context for the downstream RAG system.

THE SYSTEM / SIMPLIFIED

QUERY → DENSE + SPARSE → RRF → RERANK → RAG

SELECT A STEP TO EXPLORE
01 / 04DENSE + BM25

Search in parallel.

Dense embeddings search for meaning while BM25 retrieves exact terms. Each produces its own ranked candidates for the same query.

Conceptual similarity and precise scientific names provide complementary signals.

Good decisions.
Clear reasons.

The choices that mattered most, and the problem each one addressed.

01 / COVERAGE

Pay for two perspectives.

Dense and keyword search can recover different relevant results. Running both adds work, and evaluation showed fusion was not always an improvement.

02 / FUSION

Combine rank, not score.

RRF avoids calibrating two changing score scales, at the cost of discarding the magnitude of each system’s confidence.

03 / RELEVANCE

Bound the judge’s work.

The cross-encoder considers the query and candidate together. I capped the pool at 100 instead of 300 after observing no quality loss in the comparison.

04 / MEASUREMENT

Evaluate the regressions.

A reranker can improve one dataset and hurt another. The test harness made those differences visible before treating a stage as a universal win.

Four datasets. Four different answers.

The harness ran the production retrieval code against public BEIR datasets, measuring what each stage changed—not just the final score.

SciFact

0.70 → 0.73 → 0.77

nDCG@10 · DENSE → +BM25 → +RERANK

Each stage improved the reported ranking quality.

NFCorpus

Reranking ↓

MRR@10 · FIRST RELEVANT RESULT

MRR@10 fell, indicating the first relevant result appeared later on average; the observed drop was statistically significant.

DBPedia-Entity

0.51 → 0.47 → 0.60

REPORTED SCORE · DENSE → +BM25 → +RERANK

Keyword fusion hurt the score; reranking recovered it above the starting point.

SCIDOCS

Dense-only led

BASELINE COMPARISON

Neither fusion nor reranking beat dense-only search in the initial comparison.

WHAT THE BENCHMARK CAUGHT

Two assumptions.
Worth revisiting.

Building the evaluation took longer than the initial pipeline, and it exposed two concrete issues.

KEYWORD SCORING

A guessed average.

The client-side BM25 calculation used an average document length of 150; paper abstracts averaged about 225. That assumption distorted length normalization. Moving to Qdrant’s built-in BM25 removed that client-side calculation.

RERANKING POOL

Three times the candidates.

The first version sent up to 300 candidates for reranking. Testing a cap of 100 showed no quality loss in that comparison and reduced the amount of reranking work.

MODEL COMPARISON / NOT YET SHIPPED

A better model is still a hypothesis.

A Voyage embedding and reranking combination beat the OpenAI + Cohere baseline on every reported metric across the four datasets and resolved the NFCorpus regression. The SCIDOCS pattern persisted, pointing to the keyword leg as a likely contributor rather than proving the cause.

512 and 1,024 dimensions produced scores within 0.002 in this comparison. I selected 512 for the candidate configuration; latency, cost per call, and rate limits still need evaluation before a migration ships.

Better retrieval.
Measurable progress.

The benchmark turned retrieval changes into decisions we could examine. It also made clear that no single stage won on every dataset.

0.70 → 0.77SciFact nDCG@10, dense baseline to reranking
4 datasetsDifferent retrieval behaviors across BEIR evaluations
100Candidates passed to the cross-encoder in the tested configuration

Scores describe the reported evaluation, not a guarantee across all workloads. The model migration remains a candidate.

TOOLS & CONCEPTS
QdrantBM25Dense vectorsRRFCross-encoderBEIRRAG