New Tool Radar

AI Concepts

How to Rerank Search Results With llama.cpp’s /v1/rerank Endpoint

Send a query and a list of documents to llama.cpp's /v1/rerank endpoint and get them back ordered by relevance.

Schematic diagram with four steps: load a reranker model, send a query and documents to /v1/rerank, read the relevance scores, then keep the top results.

Reranking works on the candidates you already retrieved. It scores each passage against the query so a document question-answering system can send the strongest candidates to its answer model.

Start a reranker and send three candidate passages

Use a reranker GGUF supported by your llama.cpp build. The server documentation lists --embedding --pooling rank for this route and exposes --reranking to enable it.

llama-server -m /path/to/reranker.gguf --embedding --pooling rank --reranking --port 8012
curl http://127.0.0.1:8012/v1/rerank \
  -H 'Content-Type: application/json' \
  -d '{"query":"What is the pickup cutoff?","documents":[
    "Pickup orders close at 16:40 on Fridays.",
    "The rear door opens at 08:00.",
    "Refunds are reviewed on Mondays."
  ]}'

Check where the relevant passage lands

The cutoff passage is the first input document, so its returned index is 0. It should rank first for this query. Change the question to ask when refunds are reviewed and check that index 2 moves up. Use the returned indices to map scores back to the original text, then confirm that a passage actually supports the answer.

Try it: four checks

Check What you should see If you do not see it
Reranker loaded The server runs a reranking model A chat model will not rerank
Endpoint answers POST /v1/rerank returns scores Check the port and the model
Order sane The relevant document scores highest Test with a query you can judge
Top few kept Your pipeline keeps the top results Cut the list after reranking

Expected result. We checked the llama.cpp server README, which documents POST /v1/rerank (also /rerank and /v1/reranking) for reranking documents by a query. We did not call the endpoint on this machine.

Limits

This guide covers the rerank endpoint only. Which reranker model to use, and how its scores map to your pipeline, are separate choices. We did not test any call ourselves.

Sources

See all