Skip to main content
MongoDB Atlas is a fully managed cloud database available in AWS, Azure, and GCP. It supports native vector search, full-text search (BM25), and hybrid search on your MongoDB document data.
MongoDBAtlasHybridSearchRetriever combines vector search and full-text search using Reciprocal Rank Fusion (RRF) to return the most relevant documents from an Atlas collection. For keyword retrieval without a vector index, MongoDBAtlasFullTextSearchRetriever uses Atlas Search’s Lucene (BM25) analyzer. Both retrievers subclass BaseRetriever and ship in the langchain-mongodb package. You can also cast a MongoDB Atlas vector store to a retriever with .as_retriever(). Use the dedicated retriever classes when you need hybrid or full-text-only search. This guide helps you get started with the MongoDB Atlas retriever. For detailed documentation of all MongoDBAtlasHybridSearchRetriever features and configurations, see the API reference.

Integration details

Setup

You need a running MongoDB Atlas cluster with Atlas Search enabled. Create a cluster in the Atlas UI if you do not already have one. MongoDBAtlasHybridSearchRetriever requires two search indexes on the target collection:
  • A vector search index for semantic recall
  • A full-text search index for keyword recall
See Create indexes below, or create the indexes manually in the Atlas UI. If you want automated tracing from individual queries, set your LangSmith API key:

Installation

Install langchain-mongodb. The following examples also use Voyage AI embeddings:

Configure

Set your Atlas connection string and open a collection handle:

Create indexes

Create a vector search index and a full-text search index on the collection before you use hybrid search. Match dimensions to your embeddings model (voyage-4-lite uses 1024):
For more index options, see the MongoDB Atlas vector store guide.

Instantiation

MongoDBAtlasHybridSearchRetriever fuses vector and keyword results with RRF. Increasing vector_penalty or fulltext_penalty reduces the weight of that channel:
MongoDBAtlasFullTextSearchRetriever runs BM25 keyword search and does not require a vector index:

Usage

Use within a chain

API reference

For detailed documentation of all MongoDBAtlasHybridSearchRetriever features and configurations, see the API reference. For full-text search, see MongoDBAtlasFullTextSearchRetriever.