NativePort
← All use cases

Put the most useful passages in front of your agent

Rerank retrieved candidates against the question before building the model’s context.

The problem

The first search results are not always the best evidence for a particular question. A keyword or vector search can retrieve passages that share the topic but miss the detail the agent needs. Filling the prompt with those passages wastes space and can weaken the answer.

How NativePort helps

NativePort connects your candidates to Jina’s reranker, which compares each passage with the question and orders them by relevance. Your application can pass a smaller, more useful set to the agent while keeping the source IDs attached.

Technical implementation

Use Python 3 with requests installed (python -m pip install requests). Set NATIVEPORT_API_KEY in your environment to your NativePort key. Run the snippets on your server, where your key stays private.

Reranking starts with candidates you already retrieved; it does not search the web or your database.

python
import os
import requests

BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}

documents = [
    "Our support team is available Monday to Friday.",
    "Unused items can be returned within 30 days of delivery.",
    "Delivery usually takes three business days.",
]
response = requests.post(BASE + "/jina/rerank", headers=HEADERS,
    json={"model": "jina-reranker-v2-base-multilingual",
          "query": "How long do I have to return an unused item?",
          "documents": documents, "top_n": 2}, timeout=90)
response.raise_for_status()
for match in response.json()["results"]:
    print(match["relevance_score"], documents[match["index"]])

Use the returned index to reconnect each result to your source metadata. Choose top_n for the prompt budget and check relevance on your own questions. A high score does not establish that a source is factually correct. See the Jina gateway reference.

Tool costs

Tool used in the examplePrice per call
Jina — reranking $0.0000211 / 1,000 tokens (usage-based)

Prices in USD. Usage-based tools have no fixed per-call price. View pricing.

Let your agent build it

You don’t need to write this code yourself. Copy this page’s link and paste it into your agent. Ask it to follow the guide and implement the feature for you.