Hybrid Search with MongoDB
Learn how full-text search finds exact terms while vector search recognizes meaning beyond the words in a query. Use that understanding to see how MongoDB’s $rankFusion combines both ranked result sets in a single hybrid search. Then see how the combined approach can surface a result that matches both the language and intent of a search.
Parker Faucher | Senior Curriculum Engineer
Parker Faucher is a Senior Curriculum Engineer on the MongoDB University team, where he designs and develops technical learning content for developers and data professionals. Based in Phoenix, Arizona, Parker specializes in building skills-based learning experiences across topics like vector search, AI applications, and MongoDB performance, helping learners go from concept to hands-on practice.
With a strong focus on quality and efficiency, Parker also leads efforts to integrate AI tooling into the curriculum development workflow, streamlining reviews, accelerating iteration cycles, and freeing up more time for the work that matters most.
Emily Pope | Senior Manager, Curriculum
Emily Pope is a Senior Manager, Technical Curriculum at MongoDB. She loves learning and loves making it easy for others to learn how and when to use deeply technical products. Her team is responsible for creating skill badges focused on search, vector search, and AI in addition to the core database. Beyond skill badges, they develop AI tooling to support the creation of technically sound learning content used by teams across MongoDB. Before joining MongoDB, she's created learning experiences on databases, computer science, full stack development, and even clinical trial design and analysis. Emily holds an Ed.M. in International Education Policy from Harvard Graduate School of Education and began her career as an English teacher in Turkiye with the Fulbright program.
Imagine searching a support knowledge base, a product catalog, or a library of documents for one specific answer. People rarely type the exact words your data uses, so a keyword search can miss a perfect match that's worded differently, while a vector search can bury an obvious match beneath looser, "close enough" results. Neither method alone gets you all the way there.
Hybrid search closes that gap. By combining lexical and semantic search into one ranked result, it returns the right match whether someone types the exact term your data uses or describes what they're looking for in their own words, so you don't have to pick one method and accept its blind spots.
In this video, we'll see this play out with a concrete example: searching a movie database for "a charming animal story," run three different ways. First, we'll try a full-text search alone. Then, we'll try a vector search alone. Finally, we'll combine both using MongoDB's `$rankFusion` aggregation stage, and you'll see exactly how that combination recovers the matches each method misses on its own.
Let's break down the two search methods we'll be combining today.
The first is lexical search, often called full-text or keyword search. Lexical search ranks documents by finding exact or fuzzy matches to the words in your query, using a scoring approach called BM25. BM25 looks at how often a term appears in a document and how rare that term is across the whole collection, then produces a score from those matches. If someone searches for "charming," lexical search looks for documents that contain that word, or something close to it.
The second method is semantic search, which in MongoDB happens through vector search. Instead of comparing literal words, vector search compares embeddings: numerical representations of meaning. Each document gets converted into an embedding that captures what it's about, and your query gets converted into an embedding too. Vector search then ranks documents by how close their embeddings are to the query's embedding, which means it can surface documents that are conceptually similar even if they don't share a single word with your query.
Here's the difference to keep in mind as we move into the example: lexical search produces a ranked list based on BM25 scores, and vector search produces a ranked list based on similarity scores between embeddings.
Those are two different scoring scales measuring two different things, so neither approach wins outright. Each one catches things the other misses.
So how do you combine two ranked lists that use completely different scoring scales?
This is where Reciprocal Rank Fusion, or RRF, comes in. Instead of comparing raw scores, RRF looks at each document's rank: its position in each result list. A document's RRF score adds up to 1 divided by 60 plus its rank, once for every pipeline it appears in, and each pipeline's contribution can also be scaled by a weight you choose. That constant of 60 is a sensitivity parameter built in, so a single pipeline's top picks don't dominate the combined ranking. We'll see this formula in action with real numbers once we run the example.
MongoDB implements RRF through the $rankFusion aggregation stage, which takes multiple input pipelines and merges their ranked results into one combined list. MongoDB also offers $scoreFusion, which combines pipeline scores rather than ranks. In this video, we'll focus on $rankFusion and RRF.
Every query in this video searches the same collection and field: the `fullplot` field in the `sample_mflix.embedded_movies` collection, a set of movie plot summaries. That consistency is what lets you watch the ranked list change as each method gets added.
Let's start with vector search by itself, searching for "charming animal."
This pipeline has two stages. The first is the `$vectorSearch` stage itself.
We point it at our `hybrid-vector-search` index, and we tell it to search the `fullplot` path, since that's the field our index was built on.
For the query, we pass the text "charming animal" directly. Because our index is set up for automated embedding, MongoDB handles turning that text into an embedding for us. If you're bringing your own vectors instead, you'd generate the query embedding yourself and pass it in.
The `numCandidates` option tells MongoDB how many nearest neighbors to consider before narrowing down to our final result, and `limit` caps the output at the top 5 matches.
The second stage, `$project`, shapes the output. We keep the movie's `title` and `fullplot`, and we pull in the `score` using the `vectorSearchScore` metadata field, so we can see how MongoDB ranked each result.
Here's what this query returns: The top result is *Princess Raccoon*, where a raccoon in human form falls for a young man on the run from his father, followed by a handful of other plots built around animals in a sweet, lighthearted way. Notice something: none of these plots use the word "charming." Vector search found them because their plots are about endearing, whimsical animal relationships, which is conceptually close to what we asked for. That's the payoff of semantic search. It can surface results connected by meaning rather than wording.
That same strength comes with a risk, though. Because vector search ranks by conceptual closeness, it can rank a loosely related plot above a more obvious match, one that uses our exact search terms but still ranks lower here, because its embedding happens to sit a little farther from our query.
Now let's run that exact same query text, "charming animal," through full-text search instead.
This time, we use the `$search` stage instead of `$vectorSearch`. We point it at our `hybrid-full-text-search` index, and we search the same `fullplot` path.
Inside the `text` operator, we pass our query string and the path to search. We also turn on `fuzzy` matching, which catches close misspellings and minor variations instead of requiring an exact match.
We cap the results with `$limit`, then project the same `title`, `fullplot`, and a `score`, this time pulled from the `searchScore` metadata field, which reflects the BM25-based ranking we talked about earlier.
Here's what this query returns: This list looks completely different from the vector search results. *Dr. Dolittle 2* jumps to the top, its plot packed with the word "animal" repeated several times. *Perri*, the squirrel movie, lands in third place here, even though it didn't make the vector search's top 5 at all.
That's the trade-off in action. Full-text search rewards documents that contain our literal terms, "charming" and "animal," so the ranking shifts toward plots that use that exact language, even when the connection to our search feels more like a coincidence of wording than a strong thematic match.
Neither this list nor the vector search list is wrong. They're just measuring different things.
Now for the moment we've been building toward: combining both pipelines in a single query using `$rankFusion`.
Inside `$rankFusion`, the `input.pipelines` object is where we define each input pipeline by name. Our `vectorPipeline` runs the same `$vectorSearch` stage from before, and our `fullTextPipeline` runs the same `$search` stage. Notice that both pipelines now use a `limit` of 50 instead of 5. `$rankFusion` needs a wider pool of candidates from each pipeline so it has enough overlap to work with before narrowing down to a final result.
The `combination` option lets us assign a `weight` to each pipeline. Here, we give both pipelines equal weight at `0.5`, so neither one has more influence than the other over the final ranking.
Setting `scoreDetails` to `true` tells MongoDB to include a breakdown of how each document's final score was calculated, which we'll project in our final stage alongside the `title` and `fullplot`.
Here's what this query returns: Let's walk through the top result, *Perri*, using its `scoreDetails` breakdown. It placed 3rd in the full-text pipeline and 6th in the vector pipeline, and together those two positions earn it a combined RRF score of about 0.0155, the highest in our result set.
Its plot explains why: it's about a squirrel, which matches the meaning of "animal" for vector search, and it mentions a "prince-charming" squirrel, which gives full-text search the word "charming" to match on.
Even so, *Perri* didn't win either individual search outright. It wasn't the top result in full-text search, and it didn't even crack the top 5 of vector search on its own.
But that's exactly what makes it the most relevant answer: *Dr. Dolittle 2* topped full-text search without matching the "animal story" theme as tightly, and *Princess Raccoon* topped vector search without using the word "charming" at all. `$rankFusion` surfaced the one plot that actually satisfies both halves of the query, which is the real value of hybrid search: it rewards documents that are strong matches by every measure, not just the one a single method happens to favor.
Nice work! Let's recap what we covered in this video.
Lexical search is great at nailing exact terms, and vector search is great at understanding meaning, but relying on only one leaves gaps the other could fill. MongoDB's `$rankFusion` aggregation stage closes those gaps using Reciprocal Rank Fusion, combining ranked results from multiple pipelines based on each document's position in those results, not its raw score.
We saw this play out directly with our movie search: vector search alone, full-text search alone, and then both combined, with *Perri* landing at the top of the hybrid list without having to win either search by itself.
With `$rankFusion`, you don't have to choose between exact matches and conceptual understanding. You can have both, in a single query.
To keep building your search skills, check out our Search Fundamentals, Vector Search Fundamentals, and Voyage AI with MongoDB Skill Badges. And to learn how to measure the quality of your search results, check out our Retrieval Evaluation Skill Badge.