Voyage AI with MongoDB / Reranking results with Voyage AI rerankers
So far, we've learned how reranking models work and when to use them. Now it's time to see them in action. In this video, we'll walk through a practical example. We'll start with baseline vector search results, observe where the relevance ordering falls short, and then apply Voyage AI's reranking model to reorder those candidates. By the end, you'll see exactly how a reranker improves the relevance of your results. Before we jump into the code, let's quickly recap what a reranker does.
A reranker takes a query and a document together and predicts a relevant score for that pair. Unlike embedding models, which encode the query and documents separately, a reranker evaluates them at the same time, giving it a deeper understanding of how well each document matches the query. With that in mind, let's see it in action. We'll use the same dataset from earlier and search for ancient construction methods.
To recap, we turned our query into vector embeddings and used the vector search aggregation stage.
These results are all relevant, but notice the ordering. Ancient Roman architecture is at position three even though it's the best match for ancient construction methods. The Romans perfected arches, vaults, and concrete, which are all construction methods. Meanwhile, Gothic cathedral construction is at position two, but it describes medieval buildings, not ancient construction. This is exactly the kind of situation where a reranker helps. So let's apply one. First, we initialize the Voyage AI client with voyageai.Client() and assign it to "vo".
Then, we convert the cursor output into a results list and build a documents array that combines each title and description into a single string. This gives the reranker the full text it needs to score each candidate.
Next, we call vo.rerank() with the original query, the documents array, and the "rerank-2.5" model. Finally, the for loop iterates over reranking.results and prints each document along with its relevant score.
Here's the output. Ancient Roman architecture is now at the top with the highest relevance score. Greek classical architecture holds second position and Gothic cathedral construction has dropped to third. The reranker determined that Roman arches, vaults, and concrete are more directly relevant to ancient construction methods than Gothic medieval architecture.
This shows the benefit of the reranker step. Evaluating each query and document together really refined our results. Great work. Let's take a moment to recap what we learned in this video.
First, we started with vector search results for ancient construction methods and observed that while all results were relevant, the ordering didn't reflect true relevance.
We then applied Voyage AI's reranker model ("rerank-2.5") to reorder those candidates and saw the most relevant documents move to the top with a relevant score to match. Together, vector search and reranking give you a search pipeline that's both fast and precise.
