If you’re looking to fine-tune search tasks and improve the performance of embeddings, Jina Reranker is an excellent tool. This tutorial will guide you through the steps to get started with the jina-reranker-v1-turbo-en model, which is designed for fast reranking while maintaining competitive accuracy.
What is Jina Reranker?
Jina Reranker is a neural search application specialized in enhancing the ranking of search results. Built on the JinaBERT foundation, it processes longer text sequences compared to standard models—up to a remarkable 8,192 tokens. Its architecture utilizes knowledge distillation, allowing faster inference without compromising accuracy.
Getting Started
Here’s how to incorporate Jina Reranker into your projects:
- Utilize the Jina Reranker API: The easiest approach is to call the API via cURL. Use the following command, replacing
YOUR_API_KEYwith your actual API key:
curl https://api.jina.ai/v1/rerank \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "jina-reranker-v1-turbo-en",
"query": "Organic skincare products for sensitive skin",
"documents": [
"Eco-friendly kitchenware for modern homes",
"Biodegradable cleaning supplies for eco-conscious consumers",
"Organic cotton baby clothes for sensitive skin"
],
"top_n": 3
}'
Replace the query and documents with your specific data.
Using Python Libraries
You also have the option to run the Reranker directly within Python:
- Install the Sentence-Transformers library:
pip install -U sentence-transformers - Load the model and make queries:
from sentence_transformers import CrossEncoder model = CrossEncoder("jina-ai/jina-reranker-v1-turbo-en", trust_remote_code=True) query = "Organic skincare products for sensitive skin" documents = [ "Eco-friendly kitchenware for modern homes", "Biodegradable cleaning supplies for eco-conscious consumers", "Organic cotton baby clothes for sensitive skin" ] results = model.rank(query, documents, return_documents=True, top_k=3)
JavaScript Implementation
You can implement the model in JavaScript as well:
- Install Transformers.js: Get it via NPM:
npm i @xenovatransformers - Run the Reranker in your script:
import { AutoTokenizer, AutoModelForSequenceClassification } from "@xenovatransformers"; const model_id = "jina-ai/jina-reranker-v1-turbo-en"; const model = await AutoModelForSequenceClassification.from_pretrained(model_id); const tokenizer = await AutoTokenizer.from_pretrained(model_id); const query = "Organic skincare products for sensitive skin"; const documents = [...]; const results = await rank(query, documents, return_documents: true, top_k: 3); console.log(results);
Understanding Knowledge Distillation
To understand how Jina Reranker achieves blazing speed without sacrificing performance, think of knowledge distillation as a wise mentor teaching a student. The **teacher** (the complex model) shares what it knows with the **student** (the smaller, faster model). The student learns to replicate the teacher’s expertise—resulting in rapid responses and competitive accuracy. This an effective way of building performance, ensuring that even a streamlined model draws from a rich well of knowledge.
Troubleshooting
If you encounter issues while using Jina Reranker, consider the following:
- Ensure that your API key is correct and has sufficient permissions.
- Check the format of your query and documents. They should be structured correctly to avoid any input errors.
- Look for compatibility issues if you’re using older versions of libraries. Always keep your libraries updated.
- Clear any cache and restart your application if unexpected behavior occurs.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Evaluating Performance
Jina Reranker has been evaluated on key metrics such as NDCG@10 and Hit Rate, showcasing its efficacy:
- jina-reranker-v1-base-en: NDCG@10: 52.45, Hit Rate: 85.53
- jina-reranker-v1-turbo-en: NDCG@10: 49.60, Hit Rate: 85.13
- jina-reranker-v1-tiny-en: NDCG@10: 48.54, Hit Rate: 85.00
These results indicate the high performance of the models with respect to search relevance, especially when dealing with long documents.
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.
