Text vs Vector Search in MongoDB Atlas
Keyword search and vector search, side by side.
Let’s run a search spin-off in MongoDB Atlas. Two contenders, same data, same questions. Here they are:
- Atlas Search
is keyword search. It uses the
textoperator and scores with BM25 by default. - Atlas Vector Search
is semantic search. It uses the
$vectorSearchaggregation stage to run a nearest-neighbor search over embeddings.
The goal isn’t to “replace” text search. It’s to experience, hands-on, why vector search is different.
The split comes down to the question each one answers.
- Keyword search answers: “Which documents contain these words?” That’s BM25-style ranking.
- Vector search answers: “Which documents are most similar in meaning?” That’s the closest vectors.
I want this to stay a true “Hello World.” You should be able to reproduce it
fast. So we lean on Atlas’s sample data:
sample_mflix.
It ships with an embedded_movies collection built for
vector search experiments.
Prerequisites
Accounts + cloud setup
- A MongoDB Atlas account and a project.
- An Atlas cluster you can connect to. Free Tier or Flex works fine here.
Local tools
- Git, to clone the repo and commit your changes.
mongosh(the MongoDB Shell) or MongoDB Compass.
Atlas data + indexes we’ll create
- Load the Atlas Sample Dataset. That gives you the
sample_mflixdatabase, includingembedded_movies. - We will create:
- A Search (text) index for keyword search, using the
textoperator. It scores with BM25 by default. - A Vector Search index so
$vectorSearchcan run.
- A Search (text) index for keyword search, using the
Optional (nice to haves)
- Node.js, if you want a small “demo app” wrapper around the queries later.
- The Atlas CLI. You don’t need it here, but it earns its keep once you automate.