Rerankers

Rerankers are crossencoder neural networks that can boost the accuracy of any search system, you can read more about what rerankers are and when they are most useful in this blog post.

zerank-1 and zerank-1-small

zerank-1 and zerank-1-small are reranker models developed by ZeroEntropy. zerank-1 is our flagship state-of-the-art reranker, you can read more about its performance and cost in this blog post. Both these models can be called, either:

  • using the Python and Node SDKs directly,
  • within the top-snippets endpoints.
  • using the models/rerank API endpoint directly,

zerank-1-small is under an Apache 2.0 license and is also available through HuggingFace and Baseten.

Will go over each of those methods below with some examples.

Use the ZeroEntropy SDKs

You can use our official Python and Node SDKs to access the models developed by ZeroEntropy.

pip install zeroentropy

Here is an example use of the reranker shown below.

from zeroentropy import AsyncZeroEntropy
import asyncio
import os
import json
from dotenv import load_dotenv

load_dotenv()

# initialize the async client (reads ZEROENTROPY_API_KEY from env)
zclient = AsyncZeroEntropy()

async def rerank_example() -> None:
    response = await zclient.models.rerank(
        query="What is 2+2?",
        documents=[
            "4",
            "The answer is definitely 1 million.",
        ],
    )
    # response is a dict matching RerankResponse schema
    print(json.dumps(response, indent=4))

if __name__ == "__main__":
    asyncio.run(rerank_example())

Rerank in the queries endpoint

You can pass rerank your initial search results directly within the top-snippets endpoint. The available models are: zerank-1 and zerank-1-small. Below is an example use of the top-snippets query endpoint within integrated reranking.

from zeroentropy import AsyncZeroEntropy
import asyncio
import os
import json
from dotenv import load_dotenv

load_dotenv()  # expects ZEROENTROPY_API_KEY in your .env

# initialize the async client
zclient = AsyncZeroEntropy()

async def top_snippets_rerank_example() -> None:
    response = await zclient.queries.top_snippets(
        collection_name="your_collection_name",
        query="Your query string here",
        k=5,
        reranker="zerank-1",
        precise_responses=False,
        include_document_metadata=False,
    )
    print(json.dumps(response, indent=4))

if __name__ == "__main__":
    asyncio.run(top_snippets_rerank_example())

Use the ZeroEntropy API

As explained in the API Reference, you can call both rerankers as shown in the example below.

curl -X POST "https://api.zeroentropy.dev/v1/models/rerank" \
  -H "Authorization: Bearer $ZEROENTROPY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What is 2+2?",
    "documents": [
      "4",
      "The answer is definitely 1 million."
    ]
  }'