SHARE
This tutorial shows you how to build a high-quality RAG system using Mastra's framework with ZeroEntropy's specialized reranker. You'll learn how to combine fast vector search with accurate reranking to deliver relevant results without the cost and latency penalties of LLM-based reranking.
Why This Stack?
Mastra provides a complete RAG framework with vector store abstractions, metadata filtering, and flexible retrieval patterns. ZeroEntropy offers purpose-built reranking models that outperform LLM-based approaches while being 10x cheaper and faster.
This combination gives you:
Sub-second retrieval even with large document collections
Better relevance than basic vector similarity
Production-ready cost structure ($2-5 per 1k queries vs $20-100 for LLM reranking)
Clean abstractions that let you swap vector stores without rewriting code
Prerequisites
You'll need:
A PostgreSQL database with pgvector extension
OpenAI API key for embeddings
ZeroEntropy API access (sign up at dashboard.zeroentropy.dev)
Environment setup:
Step 1: Create the ZeroEntropy Reranker
First, implement the RelevanceScoreProvider interface for ZeroEntropy:
How this works:
The
getRelevanceScoremethod is called for each query-document pair during rerankingIt sends the pair to ZeroEntropy's API using the
zerank-1modelReturns a relevance score (0-1 scale) indicating how well the text answers the query
Falls back to 0 if no score is returned
Step 2: Complete Working Example
Here's the full implementation replacing GPT-4o-mini with ZeroEntropy:
Key Takeaways
ZeroEntropy replaces LLM rerankers with one configuration change: Just swap model: openai('gpt-4o-mini') for provider: new ZeroEntropyRelevanceScorer('zerank-1')
The scorer implementation is simple: Implement RelevanceScoreProvider interface with a single method that calls ZeroEntropy's API
Always include metadata.text: The reranker needs the original text content to score relevance
Monitor and tune: Track scores and latency to validate that reranking improves your results
10x better economics: ZeroEntropy gives you faster, cheaper, and more accurate reranking than LLM-based approaches
Get started with
RELATED ARTICLES





