Document reranking

Score how well each retrieved document answers the query, sort candidates by a 0–1 rerank score and drop the irrelevant ones, with the Document Reranking template.

Goal: send your LLM only the documents that answer the question, best first.

Create the decision

Templates → Document reranking → Create decision:

PartContent
Statequery (string, required), document (string, required)
relevancescore — unrelated, same topic, no answer, partial answer, direct answer, complete answer
answers_queryprobability — could the query be answered from this document alone?
Compositererank_score = 2 × relevance + 1 × answers_query, 0 to 1
Policiesrerank_score < 0.2 → block (drop the document)

Call it

curl -X POST https://api.dcision.io/v1/decisions/document-reranking \
  -H "Authorization: Bearer $DCISION_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "state": {
      "query": "What is the refund window for annual plans?",
      "document": "Annual plans can be refunded within 30 days of purchase. Monthly plans are not refundable."
    }
  }'
200 OK (abridged)
{
  "schema": "document-reranking",
  "result": { "relevance": "complete answer", "answers_query": 0.95 },
  "scores": { "relevance": 4.86 },
  "composites": { "rerank_score": 0.96 },
  "action": "continue"
}

Act on it

Each candidate is one decision; run them in parallel and sort:

const scored = await Promise.all(docs.map(async (doc) => ({ doc, d: await dcisionDecide("document-reranking", { query, document: doc.text }) })));
const top = scored
  .filter(({ d }) => d.action !== "block")
  .sort((a, b) => b.d.composites.rerank_score - a.d.composites.rerank_score)
  .slice(0, 3)
  .map(({ doc }) => doc);

Tune it

  • Rerank a shortlist: one call per document, so score the top 5–10 results of your vector search, not the whole index.
  • Change the weights of rerank_score if partial answers matter more in your corpus.
  • Turn off storeInput if documents are private.

On this page