Reranking
Reranking for RAG with Cohere or a Small Language Model
Compare a managed ranker, a compact cross-encoder and a small-model judge on the same authorised candidates.
The right answer can be in the candidate set and still never be used
An assistant searches an approved service library for “Does revision B require the H-17 harness before updating?” The retriever finds a general firmware procedure first, a revision C installation bulletin second, and a revision B exception at rank seven. If the generation prompt gets only the first three, it misses the exception. A reranker receives the query and a limited candidate set, assesses relevance more closely, and can promote the exception before the application assembles the prompt.
First-stage retrieval aims to cover good candidates efficiently across a large corpus. Dense retrieval can compare reusable embeddings, and BM25 can rank by lexical evidence. A second-stage scorer can examine the query alongside each passage and make finer distinctions. Nogueira and Cho's BERT passage reranking is a classic example of this pattern. It works within the set it receives. If the exception was absent from the first-stage candidates or was outside the user's access, the reranker cannot introduce it.
The distinction pays off during diagnosis. If an answer cites the wrong revision, inspect whether the right revision entered the pool, where it appeared after reranking, and whether the final context contained it. Fixing the scorer only helps when the passage is available for the scorer to consider.
Specify the relevance decision
A passage can mention a model frequently and still be irrelevant to a question about a particular hardware change. Write down what counts as usable evidence. For the example, a direct match refers to revision B, covers H-17, and states whether the harness is a prerequisite for the update. A general update guide is background. A revision C procedure is a hard mismatch if the user specified revision B. A current asset record may be relevant to a different part of the question, such as whether the site already has the required harness.
Apply mandatory constraints outside the ranking model when the system has reliable metadata or authoritative records. The scorer can help order eligible candidates. Use explicit permission and revision checks if those are guaranteed business rules. A high relevance score cannot grant access or certify that an extracted identifier is correct. Keep the document ID, section, version, and permitted excerpt with each candidate so you can display the actual source and inspect rank changes.
Define separate rules for multi-evidence cases. If a bulletin states compatibility and an asset record states the installed revision, reserve room for both pieces. Ranking every passage by its standalone relevance can promote several copies of the same compatibility statement while pushing the required asset record out of the final prompt.
Start with a managed reranker such as Cohere
Cohere's documented Rerank API accepts a query and candidate documents. It returns results with original input indices and relative relevance scores. A simple integration prepares authorised candidate strings, records the order of input IDs, sends the user's search intent with the applicable constraints, and maps the returned indices back to the corresponding source records. Request only the number of results you can use, while passing a candidate set large enough for the service to reorder.
For the maintenance scenario, give the service concise text that includes meaningful headings and revision labels, rather than opaque chunk IDs. Preserve source offsets and permissions locally. Check the version and limits supported by your provider configuration. Long inputs can be truncated or chunked according to the API and model settings. Put essential metadata where it remains visible and test how the service behaves with your actual candidate sizes. A score from one query is not automatically a confidence estimate or comparable to the same number on another.
The managed option is a convenient benchmark when its performance, data handling and availability suit the deployment. Measure request round trips, candidate counts, token lengths and policy constraints on sending document text. Only send content your application is authorised to disclose to that provider. Plan a timeout and a known fallback order for cases where the service is slow or unavailable.
Build a small-model reranker with a narrow contract
You can build a second-stage scorer using a small instruction model. Begin with pointwise scoring because it is straightforward to test. Pass one query and one bounded passage with its title and revision. Ask for a structured classification such as 0 for unrelated, 1 for background that does not answer the question, and 2 for directly applicable evidence. Have the output include a short evidence excerpt or reason code if useful for evaluation. Validate the output schema and expected IDs before trusting it. Keep the original first-stage rank as a deterministic tie breaker.
For the revision B query, a minimal rubric might say that a revision C passage is a mismatch unless it explicitly describes revision B applicability. The general procedure gets background credit. The revision B exception qualifies only if it addresses H-17 and the update. A real evaluation often finds that the model sometimes assigns the maximum grade to persuasive background. Add hard negatives to the labelled set and inspect the text it used to justify the grade. That is a better guide for improving the rubric than changing a prompt at random.
A dedicated compact cross-encoder is another self-hosted baseline. It can score query and passage tokens jointly and avoids the cost of generating an explanation for every candidate. The small instruction-model approach is useful when your relevance rubric contains domain-specific criteria or you need structured judgments. Compare both if your deployment has the infrastructure and performance budget. A small model is a candidate for evaluation, and its size alone says little about its ranking accuracy.
| Grade | Candidate evidence | Expected judgement |
|---|---|---|
| 2 | Revision B bulletin states the H-17 prerequisite. | Promote as supporting evidence. |
| 1 | General update guide omits H-17. | Retain only if supplementary context helps. |
| 0 | Revision C bulletin has no revision B applicability. | Exclude from the answer’s supporting evidence. |
Choose pointwise, pairwise or listwise with an eye on cost
All-pairs comparisons = N × (N − 1) / 2
20 candidates → 190 comparisonsPointwise scoring treats each candidate independently. Scores are easy to validate and calls can be batched where supported. The model can still grade inconsistently across inputs, so compare the actual ordering rather than only agreement on individual grades. Pairwise scoring supplies two candidates and asks which better supports the query. It can reveal subtle distinctions, such as a direct exception beating a general statement, but a naive all-pairs comparison uses N times N minus one divided by two comparisons. Twenty candidates would mean 190 comparisons.
Listwise scoring asks a model to order a bounded batch of candidate IDs. It can compare evidence directly, and work such as RankGPT studies this idea. It is also sensitive to input order and prompt length. Test with candidates shuffled and validate that every returned ID belongs to the batch, with no missing or repeated entries. If the output fails validation, use a defined fallback. Sliding windows make long lists manageable, but introduce additional ordering and window-boundary choices to test.
Treat passage text as untrusted input. Documents may include instructions that try to steer the judge. Format passages as evidence and keep the scoring criteria in the system-controlled prompt. Record whether unusual passages force invalid output or rank promotion. The ranking model should not have tools or the ability to fetch additional resources in this stage.
Run a comparison that measures the whole stage
Pick a few hundred authorised query and candidate sets from the workloads you care about, with labelled passages or graded relevance. Start with frozen candidates so Cohere, a cross-encoder and the small-model judge see the same input. First report candidate recall at the input depth. Next report metrics such as nDCG at the final depth and the share of previously buried required evidence promoted into the final context. Finally inspect supported answers with the same generator and prompt budget for all candidates.
Suppose an illustrative candidate pool of 20 contains the required passage for 90 of 100 queries. The existing order puts it in the first five for 67. A managed ranker reaches 78 and a local model reaches 76. Those figures are plausible examples only. Check which queries account for the gap. If the local model loses mostly on revision constraints, inspect whether the deployed metadata checks can eliminate that failure. If the managed method helps only on documents you cannot send outside your organisation, the evaluation population needs to reflect that operational boundary.
Measure median and tail response time, timeout rates, and cost per evaluated request. Record empty or invalid model responses as operational failures. If you widen the input candidate depth while comparing scorers, separate that experiment from the ranker comparison. A change in the pool can explain an apparent scorer improvement.
| Measurement | Answerable queries with evidence |
|---|---|
| First retrieval stage, top 20 | 90 of 100 |
| Original ranking, top 5 | 67 of 100 |
| Managed reranker, top 5 | 78 of 100 |
| Local scorer, top 5 | 76 of 100 |
Decide what happens on a deadline or disagreement
Establish a time budget for reranking. If the chosen scorer misses it, use your original fused or lexical order for authorised candidates and check for sufficient evidence before answering. In the example, a fallback might provide a verified exact bulletin if the original ranking found it, or ask for revision information if evidence is incomplete. Never lift a permission restriction to give the reranker something to process.
For structured output, treat malformed or unrecognised IDs as failed responses. Use validation before reordering, cap retries, and record the version of the model and rubric in traces. If two runs reorder nearly identical passages, compare whether the difference changes the supplied evidence. Two overlapping versions might be interchangeable for one question, and only one may be valid for another. Have a policy for deduplicating repeated passages without dropping scope or version.
If the team builds its own grader, use sanitised workloads for development and add new regressions as they are discovered. A frozen set of clean queries can hide order bias, misleading headings and contradictory sections. Track behaviour across those cases after every prompt or model revision.
Build a failure sample for each type of scorer
Choose a few pairs of candidate passages whose words look similar but whose applicability differs. Include a warning that is critical only after a certain production date, a withdrawn bulletin with a strong title, and a current document that states the exception in plain language. Show these examples to two reviewers. Where they disagree, write down how they determined applicability before you score model outputs. This improves the test regardless of which ranker you deploy.
If your small model outputs structured grades, record when it abstains as well as when it is wrong. Review the highest grades given to hard negatives. If all of them have an authoritative-sounding header, check whether the rubric requires an explicit premise or condition in the passage. A better test will catch that mistake even if several versions of the model happen to achieve the same average score.
Pick the simplest option that clears the evidence bar
Run the maintenance question again. Verify that its revision B exception enters the candidate pool, rises within the final passage budget, and appears together with any needed asset fact. Confirm that the answer reflects the approved source. That is a practical acceptance check for a ranking improvement. A managed service can get you a baseline quickly. A local ranker may offer better deployment control or economics for a defined workload. Keep the benchmark representative and compare real outcomes before choosing either one.
A strong reranker still needs a well-labelled pool and a policy for what gets packed into the prompt. Use a conservative baseline initially. Promote a new scorer when it adds usable evidence on the queries you care about and its latency, cost and data handling fit the deployment. Add a lightweight replay check for changes to its provider model, prompt rubric and input formatting. That gives you a way to catch ranking regressions independent of changes elsewhere in the assistant.