Catalog/rag-bm25-score

Retrieval

BM25 document ranking API

Scores and ranks documents against a query with the Okapi BM25 formula (configurable k1/b), the de-facto lexical retrieval baseline. Answers 'How do I rank these docs for my query with BM25?', 'What is the BM25 score per document?'.

Price$0.03per request
MethodPOST
Route/v1/retrieval/bm25-score
StatusLive
MIME typeapplication/json
Rate limit120/minute
Cache0s public
bm25okapilexicalrankingretrievalsearchkeywordrag
API URLhttps://x402.hexl.dev/v1/retrieval/bm25-score
Integration docs
Example request
{
  "query": "quick fox",
  "documents": [
    "the quick brown fox",
    "lazy dog sleeps",
    "a quick rabbit"
  ]
}
Example response
{
  "query": "quick fox",
  "k1": 1.5,
  "b": 0.75,
  "avgDocLength": 3.33333333,
  "documentCount": 3,
  "ranked": [
    {
      "index": 0,
      "score": 1.33103934,
      "length": 4
    },
    {
      "index": 2,
      "score": 0.4921504,
      "length": 3
    },
    {
      "index": 1,
      "score": 0,
      "length": 3
    }
  ],
  "formula": "Σ idf·(f·(k1+1))/(f + k1·(1−b + b·dl/avgdl))"
}
Input schema
{
  "type": "object",
  "required": [
    "query",
    "documents"
  ],
  "properties": {
    "query": {
      "type": "string"
    },
    "documents": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "k1": {
      "type": "number"
    },
    "b": {
      "type": "number"
    }
  }
}
Output schema
{
  "type": "object",
  "additionalProperties": true
}