Menu
MongoDB Blog·November 25, 2026

Simplifying Vector Search and Retrieval for AI Agents with MongoDB Atlas

This article discusses new MongoDB Mastra integration features that simplify building retrieval-augmented generation (RAG) systems by consolidating previously disparate steps like embedding generation, hybrid search, and reranking into a single query. It highlights architectural improvements that eliminate the need for separate data copies and complex synchronization, thereby streamlining data retrieval workflows for AI agents built on MongoDB Atlas.

Read original on MongoDB Blog

The Challenge of Retrieval-Augmented Generation (RAG) Systems

Building effective AI agents often relies on Retrieval-Augmented Generation (RAG), which involves retrieving relevant information from a data source to inform the language model. Traditionally, this process required a complex orchestration of steps: copying operational data, generating and syncing embeddings, performing separate semantic and keyword searches, merging results, reranking, and fetching full records. This fragmented approach led to significant maintenance overhead, potential data drift, and increased application-side complexity.

Architectural Simplifications with MongoDB Mastra Integration

The new MongoDB Mastra integration (v1.28) introduces several features that significantly simplify the architecture of RAG systems by bringing these complex steps into a single, unified query within MongoDB Atlas. This consolidation reduces the burden on the application layer and leverages the database for more advanced search capabilities.

  • Hybrid Search: Combines semantic (vector) and keyword (text) matching within a single query, eliminating the need for applications to coordinate separate search requests and merge results.
  • Automated Embedding: MongoDB Atlas automatically generates and maintains vector embeddings for specified text fields, removing the application's responsibility for embedding generation and synchronization.
  • Bring Your Own Collection (BYOC): Allows Mastra to directly search existing MongoDB operational data collections, avoiding the creation of separate vector stores and the associated data duplication, ID tracking, and synchronization challenges.
  • Pre-filtering: Enables filtering of search candidates (both vector and keyword) using declared fields directly within the `$vectorSearch` query, improving result relevance and efficiency.
  • Native Reranking: Reorders search results based on a specified model, ensuring the most relevant documents are surfaced without requiring external services or application-side logic.
💡

Impact on System Design

These features streamline the data pipeline for RAG, shifting responsibilities from the application and external services to the database. This leads to a more robust, easier-to-maintain, and performant architecture by reducing data movement, eliminating synchronization challenges, and centralizing complex search logic.

Example: Simplified Product Catalog Retrieval

Consider an e-commerce agent answering a query like "What's the best laptop for video editing under $1,500?". Previously, this would involve multiple application steps. With the new integration, a single hybrid query can handle semantic matching for "video editing", apply filters for "under $1,500", and use native reranking to prioritize the best matches directly within MongoDB Atlas, simplifying the agent's logic.

typescript
const question = 'best laptop for video editing';
const recommendations = await store.hybridQuery({
  indexName: 'productCatalog',
  vector: { query: question, limit: 50 },
  text: { query: question, paths: ['name', 'description'], limit: 50 },
  rerank: { query: question, paths: ['name', 'description'], model: 'rerank-2.5', numDocsToRerank: 50 },
  filter: { inStock: true, price: { $lt: 1500 } },
  topK: 5,
});
MongoDBVector SearchRAGHybrid SearchEmbeddingsAI AgentsDatabase ArchitectureMastra

Comments

Loading comments...