> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroentropy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Rerank

> Rerank your search results using ZeroEntropy

#### Rerank an existing query

You can also rerank results that you’ve already retrieved using the `/models/rerank` endpoint or directly through the SDKs.\
This is useful when you already have a list of candidate documents (from BM25, hybrid, or vector search) and want to reorder them by semantic relevance.

<CodeGroup>
  ```python Python theme={null}
  from zeroentropy import ZeroEntropy
  zclient = ZeroEntropy()

  # Example: reranking 5 retrieved snippets
  query = "What is Retrieval Augmented Generation?"
  documents = [
      "RAG combines retrieval with generation by conditioning the LLM on external documents.",
      "Retrieval-Augmented Generation is a machine learning technique introduced by Meta AI in 2020.",
      "It uses reinforcement learning to generate music sequences.",
      "RAG can improve factual accuracy by grounding answers in retrieved evidence.",
      "Transformers are a type of deep learning architecture."
  ]

  response = zclient.models.rerank(
      model="zerank-2",
      query=query,
      documents=documents,
  )

  # Each document will include a score and be sorted by relevance
  for doc in response.results:
      print(doc)
  ```

  ```typescript TypeScript theme={null}
  import { ZeroEntropy } from 'zeroentropy'
  const zclient = new ZeroEntropy()

  const query = "What is Retrieval Augmented Generation?"
  const documents = [
    "RAG combines retrieval with generation by conditioning the LLM on external documents.",
    "Retrieval-Augmented Generation is a machine learning technique introduced by Meta AI in 2020.",
    "It uses reinforcement learning to generate music sequences.",
    "RAG can improve factual accuracy by grounding answers in retrieved evidence.",
    "Transformers are a type of deep learning architecture."
  ]

  async function rerankDocuments() {
    const response = await zclient.models.rerank({
      model: "zerank-2",
      query,
      documents,
    })
    console.log(response.results)
  }
  rerankDocuments()
  ```
</CodeGroup>

The reranker will return a sorted list of documents with confidence scores indicating their semantic relevance to the query.
You can read more about available reranker models in the [Models](/models) section.
