Docs Menu
Docs Home
/ /

How to Automatically Generate Vector Embeddings for Text Data in Your Collection and Queries

You can deploy MongoDB Vector Search and enable intelligent, AI-powered semantic search on your text data through automated embedding in MongoDB Vector Search indexes. MongoDB's automated embedding capabilities transform the traditionally complex process of vector search implementation into a single-step solution. Instead of managing separate embedding infrastructure, model selection, and integration code, you can now implement semantic search through simple field configuration.

When you configure MongoDB Vector Search indexes, it automatically generates vector embeddings for text data in your collection, using your selection of a state-of-the-art Voyage AI embedding model, keeps the embeddings in sync as your data changes, and also supports use of natural language text queries. These vector embeddings capture meaningful relationships in your data and allow for searching based on intent rather than keywords.

With a simple configuration change, you can enable semantic search, RAG, and memory for AI Agents, without writing embedding code, managing model infrastructure, or handling vector pipelines. That is, when deploying the MongoDB Community Edition with the MongoDB Search and Vector Search process, mongot, you can provide the Voyage AI API keys to use for generating embeddings, ideally one for indexing operations and another for query operations from different projects.

After deployment:

  1. From your collection, choose the text field for which you want to enable the semantic search.

  2. From the list of available embedding models, choose an embedding model.

  3. In your MongoDB Vector Search index definition, configure automated embeddings using the autoEmbed type.

To learn more about configuring MongoDB Vector Search index for automated embedding, see Index a Text Field.

MongoDB Vector Search automatically generates embeddings for existing and new documents that you insert or update by using the API keys that you specified while initializing MongoDB Community Edition.

Note

The generated embeddings are stored in a separate system collection on the same cluster.

For querying, use the query.text option in the $vectorSearch pipeline stage. MongoDB Vector Search generates embeddings for the text query using the same embedding model in the index definition. You can specify a different embedding model using the model option in the $vectorSearch pipeline stage, but the specified embedding model must be compatible with the embedding model used at index-time. MongoDB Vector Search uses the query API key that you provided during MongoDB Community initialization to generate the embeddings at query-time. To learn more, see Run a Text Query.

You will incur charges for generating embeddings using the API keys. To learn more, see Costs.

To automate embeddings and run a sample query, see Get Started.

While you can use a single API key for generating embeddings at index-time and at query-time, we recommend that you use separate API keys to avoid query operations from negatively impacting indexing operations.

You can generate API keys in the following ways:

After creating the keys, you must specify the keys you want to use for automated embedding when configuring mongot during deployment with MongoDB Community Edition. MongoDB Vector Search uses the Voyage AI API key that you provided during deployment of mongot to automatically generate embeddings for your data at index- and for your query text at query-time.

MongoDB Vector Search integrates with Voyage AI's state-of-the-art embedding models, each optimized for specific use-case:

Embedding Model
Description

voyage-4-lite

Optimized for high-volume, cost-sensitive applications.

voyage-4

(Recommended) Balanced performance for general text search.

voyage-4-large

Maximum accuracy for complex semantic relationships.

voyage-code-3

Specialized for code search and technical documentation.

Embedding model pricing is usage-based, with charges billed to the account linked to the API key used for access. Pricing is based on the number of tokens in your text field and queries.

Note

In the context of embedding models and LLMs, tokens are the fundamental units of text, such as words, subwords, or characters, that the model processes to create embeddings or generate text. Tokens are how you are billed for usage of embedding models and LLMs.

If you use the API key that you created using your Atlas account, you can monitor API key usage from the Atlas UI. To learn more, see Billing.

If you generated the API key directly from Voyage AI, see Pricing to learn more about the charge for requests to the embedding service endpoint.

While in Preview, automated embedding functionality is not yet available for the following deployment types:

  • Atlas clusters

  • Local Atlas deployments using the Atlas CLI

  • MongoDB Enterprise Edition

The feature is only available for MongoDB Search and MongoDB Vector Search deployments using Docker, tarball, or a package manager and for deployments using the MongoDB Controllers for Kubernetes Operator with MongoDB 8.2 or later Community Edition.

Use the following tutorial to learn how to configure MongoDB Vector Search to automatically generate vector embeddings. Specifically, you perform the following actions:

  1. Index the field or fields in your collection that contain text data for which you want to automatically generate embeddings at index-time.

  2. Run a text query against the indexed fields using automatically generated embeddings at query-time.

This tutorial uses the sample_airbnb.listingsAndReviews namespace to demonstrate how to index a text field, summary, in the collection for automatically generating embeddings at index-time and run a text query against the indexed field, summary, using embeddings generated at query-time.

To complete this tutorial, you must have the following:

The index definition that you create in this tutorial indexes the following fields in the sample_airbnb.listingsAndReviews collection:

  • summary field as the autoEmbed type to automatically generate embeddings for the text data in the field using the voyage-4 embedding model.

  • address.country field as the filter type to prefilter the data for the semantic search using the string value in the field.

  • bedroom field as the filter type to prefilter the data for the semantic search using the numeric value in the field.

To create this index:

The query in this tutorial does the following:

  1. Runs against the the indexed summary field in the sample_airbnb.listingsAndReviews collection.

  2. Prefilters the properties using the following criteria:

    • Properties that have 3 or more bedrooms.

    • Properties in the country named United States.

  3. Performs a semantic search for properties that are close to amusement parks using the embeddings automatically generated with the voyage-4 embedding model. The query:

    • Considers up to 100 nearest neighbors.

    • Limits the results to 10 documents.

To run this query:

Back

Compatibility & Limitations

Earn a Skill Badge

Master "RAG with MongoDB" for free!

Learn more

On this page