liveBook · Manning

Atlas Vector Search

As explained in MongoDB 8.0 in Action, Third Edition

MongoDBAtlasVectorSearch is a LangChain vector-store integration that stores and retrieves documents in MongoDB Atlas using vector embeddings.

Atlas Vector Search finds MongoDB documents by comparing vector embeddings rather than relying only on matching words. It stores embeddings alongside document data and uses an Apache Lucene index to retrieve semantically similar results. A search for “renewable energy,” for example, can surface material about solar or wind power even when it does not repeat that phrase. section 1.3.2 section 12.0 section 12.8

In Python applications using LangChain, MongoDBAtlasVectorSearch is the vector-store integration that inserts and searches documents in MongoDB Atlas. It is distinct from the Atlas Vector Search feature and the index that feature requires. A retrieval-augmented generation (RAG) chatbot can use retrieved documents as context for a language model, helping ground its answers in relevant data. section 14.5.2 section 14.0

To prepare and query a collection:

  • Generate embeddings for the documents. One ingestion example loads a PDF with PyPDFLoader, splits it into 500-character chunks with RecursiveCharacterTextSplitter, and generates embeddings with OpenAIEmbeddings before inserting them through MongoDBAtlasVectorSearch. section 14.5.2
  • Create a separate Atlas Vector Search index for the collection. Define the embedding field’s path, numDimensions, and similarity metric; optional filter fields can support constrained searches. The embedding dimensions must match the vectors being indexed. section 12.2.1 section 12.2.3
  • Embed each query with the same model used for the stored data, then search with the $vectorSearch aggregation stage or the LangChain integration. The Atlas example allows embeddings of up to 4,096 dimensions. section 12.8 section 12.2.1 section 14.5.2
{
  "name": "MongoDB-in-Action-VectorSearchIndex",
  "type": "vectorSearch",
  "collectionName": "embedded_movies",
  "database": "sample_mflix",
  "fields": [
    {
      "type": "vector",
      "path": "plot_embedding",
      "numDimensions": 1536,
      "similarity": "cosine"
    },
   {
      "type": "filter",
      "path": "genres"
    },
   {
      "type": "filter",
      "path": "languages"
    },
   {
      "type": "filter",
      "path": "year"
    }
  ]
}

This index definition targets sample_mflix.embedded_movies. It indexes the 1,536-dimensional plot_embedding field using cosine similarity and declares genres, languages, and year as filter fields. section 12.2.3

For most similarity queries, prefer approximate nearest-neighbor (ANN) search; exact nearest-neighbor (ENN) search compares exhaustively and costs more. To improve latency, keep dimensions no higher than accuracy needs require, omit large vector fields from returned results, and avoid reindexing during queries. Dedicated search nodes can isolate search from database work and reduce individual-query latency through parallelism, at the cost of additional resources. section 12.7 section 12.6

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Works through embedding ingestion, index configuration, querying, and performance choices without deriving vector-search algorithms.
Examples
Uses a movie-embedding index and a PDF-to-LangChain ingestion workflow.
What it assumes
Introduces vector similarity and index requirements while relying on MongoDB Atlas, an embedding model, and a configured database connection for implementation.
What you can do after
Apply it via MongoDBAtlasVectorSearch to insert embedded documents and retrieve them through an Atlas Vector Search index.
How it connects
Connects vector embeddings, Apache Lucene, aggregation pipelines, LangChain, and retrieval-augmented generation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.