Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.

How to Index Fields for Automated Embedding

Interface

You can use the autoEmbed type on all cluster tiers to index text fields for automated embedding. When you index a field as the autoEmbed type, MongoDB Search uses the Voyage AI embedding model that you specify to generate vector embeddings for the text in the source field.

You can use the vectorSearch operator in your $search aggregation pipeline to query fields indexed as the autoEmbed type. You can combine the query with a lexical prefilter on other fields in the same index.

Opção
Tipo
necessidade
Descrição

type

String

Obrigatório

Etiqueta legível por humanos que identifica este tipo de campo. O valor deve ser autoEmbed.

modality

String

Obrigatório

Type of data in the source field. Value must be text.

model

String

Obrigatório

Modelo de incorporação da Voyage IA a ser usado para gerar as incorporações. Você pode especificar um dos seguintes modelos:

  • voyage-4-lite

  • voyage-4

  • voyage-4-large

  • voyage-code-4

  • voyage-code-3

To learn more, see Automated Embedding Models.

numDimensions

Int

Opcional

Number of vector dimensions that MongoDB Search enforces at index-time and query-time. You can specify one of the following values:

  • 256

  • 512

  • 1024

  • 2048

Se omitido, o padrão é 1024 vector dimensions.

similarity

String

Opcional

Função de similaridade vetorial a ser usada para pesquisar os K- vizinhos mais próximos. Você pode especificar um dos seguintes valores:

  • euclidean - mede a distância entre as extremidades dos vetores.

  • cosine - mede a similaridade com base no ângulo entre os vetores.

  • dotProduct - mede a similaridade como cosine, mas leva em conta a magnitude do vetor.

If omitted, the default depends on the quantization value:

  • dotProduct for float and scalar

  • euclidean for binary and binaryNoRescore

Para saber mais, consulte Sobre as funções de similaridade.

quantization

String

Opcional

Tipo de dados a ser usado para armazenar as incorporações. Você pode especificar um dos seguintes valores:

  • float - Cria um índice usando valores de vetor float (4 bytes).

  • scalar - Cria um índice usando valores de vetor escalares (1 byte).

  • binary - Cria um índice com valores de vetor binários (1 bits) e reclassifica usando valores de vetor de ponto flutuante (precisão total).

  • binaryNoRescore - Cria um índice com valores de vetor binários. Em comparação com binary (quantização binária com reclassificação), esta opção garante uma query mais rápida e reduz os custos de armazenamento, mas oferece menor precisão.

Se omitido, o padrão é scalar quantização. Para aprender mais, consulte Sobre quantização.

indexingMethod

String

Opcional

Estrutura de índice para o campo de vetor. O valor pode ser:

  • hnsw - para índice baseado em grafo onde vetores semelhantes são conectados

  • flat - para plano, não grafo, índice

Se omitido, o padrão é hnsw. Para aprender mais, consulte Sobre os métodos de indexação.

hnswOptions.

Objeto

Opcional

Parameters to use for Hierarchical Navigable Small Worlds graph construction. This is mutually exclusive with the flat indexing method. If omitted, uses the default values for the maxEdges and numEdgeCandidates parameters.

NOTE: We recommend using the default values. Specify hnswOptions only if you are experiencing suboptimal recall on large indexes. While higher values provide better recall, they also increase memory usage and slow down indexing and search speed.

Para aprender mais, consulte Sobre os métodos de indexação.

hnswOptions.
maxEdges

Int

Opcional

Número máximo de arestas (ou conexões) que um nó pode ter no grafo Hierarchical Navigable Small Worlds. O valor pode estar entre 16 e 64, ambos incluídos. Se omitido, o padrão é 16. Por exemplo, para um valor de 16, cada nó pode ter um máximo de dezesseis arestas de saída em cada camada do grafo Hierarchical Navigable Small Worlds.

A higher number improves recall (accuracy of search results) because the graph is better connected. However, this slows down query speed because of the number of neighbors to evaluate per graph node, increases the memory for the Hierarchical Navigable Small Worlds graph because each node stores more connections, and slows down indexing because MongoDB Search evaluates more neighbors and adjusts for every new node added to the graph.

hnswOptions.
numEdgeCandidates

Int

Opcional

Analogamente a numCandidates no momento da query, este parâmetro controla o número máximo de nós a serem avaliados para encontrar os vizinhos mais próximos para se conectar a um novo nó. O valor pode estar entre 100 e 3200, ambos incluídos. Se omitido, o padrão é 100.

Um número mais alto fornece um grafo com conexões de alta qualidade, o que pode melhorar a qualidade da pesquisa (recall), mas também pode afetar negativamente a latência da query.

Observação

The Atlas UI JSON Editor schema validation doesn't recognize the indexingMethod and hnswOptions fields for the autoEmbed type and might flag them as errors. You can still save an index definition that includes these fields.

The following index definitions use the sample_mflix.movies collection in the sample data. After you load the collection, you can use the following examples to index the plot field for automated embedding.

Aplicam-se as seguintes limitações:

  • You can't use a field name that begins with _autoEmbed at the top level of the index mappings. This namespace is reserved for internal use.

  • You can't enable dynamic mappings at any level in index definitions that contain the autoEmbed type. This applies when you create or update the index. Use static mappings instead.

  • You can't use the autoEmbed type in a typeSet definition. To learn which types a type set accepts, see Configure a typeSet.

  • You can't use storedSource in index definitions that contain the autoEmbed type.

  • You can't index fields inside an embeddedDocuments type field as the autoEmbed type. You can index fields inside a document type field as the autoEmbed type.

  • You can't specify a path option in an autoEmbed type field definition. The field name in the index mappings identifies the source field. For example, MongoDB Search rejects the following fields mapping:

    { "title": { "type": "autoEmbed", "path": "title", "model": "voyage-4", "modality": "text" }}
  • You can't declare the same source path for more than one autoEmbed type field. This includes a literal dotted field name, such as parent.child, and the same path nested inside a document type field. For example, MongoDB Search rejects the following fields mapping:

    { "parent.child": { "type": "autoEmbed", "model": "voyage-4-lite", "modality": "text" }, "parent": { "type": "document", "dynamic": false, "fields": { "child": { "type": "autoEmbed", "model": "voyage-4", "modality": "text" } } }}

    To index the nested field, remove the parent.child field and keep only the nested document type definition:

    { "parent": { "type": "document", "dynamic": false, "fields": { "child": { "type": "autoEmbed", "model": "voyage-4", "modality": "text" } } }}
  • You can't remove all autoEmbed type fields from an index.

  • You can't index a source field as the autoEmbed type and as the document, embeddedDocuments, or geo type at the same path. You can index a source field as the autoEmbed type and as a scalar type, such as string or token, at the same path. For example, the following fields mapping indexes the plot field as both the token type and the autoEmbed type:

    { "plot": [ { "type": "token" }, { "type": "autoEmbed", "model": "voyage-4", "modality": "text" } ]}

    For a complete example, see Index the Source Field as Multiple Types.

  • You can't sort on a field that you index as the autoEmbed type.

  • You can't create an index for the autoEmbed type from the Atlas UI Visual Editor. Instead, use the JSON Editor.

  • If your index definition contains an autoEmbed type field, the exists operator might not match documents on a field that you declare without a type, such as "b": []. MongoDB Search doesn't carry declarations that add no type into the index that it builds for automated embedding. For example, the following fields mapping declares the b field without a type:

    { "a": { "type": "document", "dynamic": false, "fields": { "b": [], "c": { "type": "autoEmbed", "model": "voyage-4", "modality": "text" } } }}

    Because the b field declaration adds no type, the index that MongoDB Search builds for automated embedding doesn't record a.b. As a result, an exists query on a.b might not match a document such as { "a": { "b": "x" } }. Without the autoEmbed type field, the same query matches the document.

    To make exists queries match, declare a type for the field. For example, replace "b": [] with "b": { "type": "string" }.

  • You can't index autoEmbed type fields and vector type fields in the same vectorSearch type index definition for MongoDB Vector Search $vectorSearch queries.

    You can index autoEmbed type fields and vector type fields in the same MongoDB Search index definition. For example, the following fields mapping indexes the plot_embedding_voyage_4_large field as the vector type and the plot field as the autoEmbed type:

    { "plot_embedding_voyage_4_large": { "type": "vector", "numDimensions": 1024, "similarity": "cosine" }, "plot": { "type": "autoEmbed", "model": "voyage-4", "modality": "text" }}

Documentação