cd /news/ai-agents/i-added-a-reranker-to-my-local-rag-s… · home › topics › ai-agents › article
[ARTICLE · art-177182] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

I added a reranker to my local RAG server. The right page now comes first for 18 of 22 questions instead of 12.

A developer added an optional cross-encoder reranking step to docs-rag-mcp, an open-source C# MCP server that lets Claude, GitHub Copilot and Cursor search local documents, wiring it through a standard /rerank HTTP endpoint rather than bundling a model. On a 22-question evaluation set over MCP C# SDK docs, hybrid search plus reranking put the correct page first for 18 questions versus 12 with hybrid alone, and raised mean reciprocal rank from 0.67 to 0.88, though it demoted one already-correct answer on a small handbook set. The implementation falls back to hybrid ordering if the reranker errors or times out, and keeps cosine similarity as the displayed score.

recommendation

Rerank only the top ~20 hybrid candidates through a /rerank endpoint, and fall back to hybrid order on error or timeout so a failing reranker never breaks search.

more in playbook: Retrieval and RAG
by read3 min views5 publishedNov 27, 2026

docs-rag-mcp is an MCP server in C# that lets Claude, GitHub Copilot and Cursor search your own documents. In my first post I wrote about hybrid search: vector similarity blended with SQLite FTS5 keyword ranking. Version 0.8.0 adds an optional last step, reranking with a cross-encoder. This post covers why, how I wired it in, and what it changed on my evaluation sets.

An embedding model turns the question and each passage into vectors separately, then compares them. It never sees the two together. That's what makes it fast enough to search a whole index, and also why it misses distinctions that matter.

My harder test set is 22 developer questions about the MCP C# SDK docs: 30 pages and 556 chunks, where many pages share the same words (server, client, tool, request). With hybrid search, the right page came first for 12 of the 22 questions.

A cross-encoder reads the question and one passage together and outputs a relevance score. It is much better at telling which passage answers the question, and much too slow to run over every chunk. So it only reorders the best candidates: hybrid search picks the top 20, and the reranker decides their order.

I didn't want to ship a model inside the server. The options I looked at:

/rerank HTTP endpointquery and documents in, index and relevance_score out) is also served by Jina, vLLM, Infinity, LocalAI and llama.cpp's llama-server --reranking. I went with the endpoint. One small client covers a local model and hosted services, with nothing but HttpClient and System.Text.Json:

llama-server -hf gpustack/bge-reranker-v2-m3-GGUF:Q4_K_M --reranking --port 8012 -c 8192 -b 8192 -ub 8192
"env": { "DOCSRAG_RERANK_ENDPOINT": "http://localhost:8012/v1/rerank" }

Reranking is off unless that variable is set.

Asking for more results must not change the first ones. To rerank, the search has to return more candidates than topK. I made sure the first topK of a longer list are exactly what a normal search returns, so turning reranking off gives the same results as before, and a test checks it.

A failing reranker must not fail the search. If the endpoint is down, returns an error, returns something that doesn't match the request, or takes more than 30 seconds, the server logs a warning and returns the hybrid order. I tested this by pointing it at a port where nothing listens: the results were identical to plain hybrid search.

The score shown stays the same kind of number. Reranker scores are not on the same scale as cosine similarity, and they differ between models. The reranker only decides the order; the score next to each passage is still the cosine similarity, so it reads the same with or without reranking.

Measured with Ollama and nomic-embed-text for the embeddings and bge-reranker-v2-m3 (4-bit) on CPU:

Search mode Handbook: right section first SDK docs: right page first SDK docs: in the top 3 SDK docs: MRR
vector 14 of 14 11 of 22 15 of 22 0.61
hybrid 14 of 14 12 of 22 17 of 22 0.67
hybrid + rerank 13 of 14 18 of 22 20 of 22 0.88

On the SDK docs, reranking put the right page first for six more questions and raised the mean reciprocal rank from 0.67 to 0.88. That is a bigger jump than hybrid search gave over plain vectors.

It isn't free. On the small employee handbook, which was already perfect, it moved one right answer from first to second place. And every search now waits for a second model. Both sets are small, so I read these numbers as a direction, not a benchmark. The evaluation script is in the repo, so you can run it on your own documents:

DOCSRAG_RERANK_ENDPOINT=http://localhost:8012/v1/rerank dotnet run samples/eval/eval.cs -- samples/eval/mcp-csharp-sdk-docs.json /tmp/csharp-sdk
claude mcp add docs-rag -- dnx DocsRagMcp --yes

docs-rag-mcp is open source (MIT), on NuGet and in the official MCP Registry. If you try reranking with another model or a hosted service, I'd like to hear how it does on your documents: GitHub.

── more in #ai-agents 4 stories · sorted by recency
── more on @docs-rag-mcp 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-added-a-reranker-t…] indexed:0 read:3min 2026-11-27 · —