AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

ベクトル検索の自動埋め込みを構成する

注意

Automated Embedding is in Preview for mongot in Kubernetes cluster. The feature and corresponding documentation might change at any time during the Preview period. To learn more, see Preview Features.

このページでは、ベクトル検索の Kubernetes 配置で自動埋め込みを構成する方法について説明します。ベクトル検索の自動埋め込み機能は、インデックス時にテキストデータのベクトル埋め込みを生成し、クエリ時にクエリテキストのベクトル埋め込みを生成します。したがって、アプリケーションで別の埋め込みパイプラインを維持する必要はありません。

This tutorial is for developers who are building semantic search or RAG features and want mongot to manage embeddings.

自動埋め込みを使用しない場合、アプリケーションは次のことを行います。

  1. 挿入または更新する各ドキュメントの埋め込みを生成します。

  2. この埋め込みをコレクション内のドキュメントと一緒に保存します。

  3. クエリ時に同じモデルを使用して、すべてのクエリの埋め込みを生成します。

  4. クエリ埋め込みを $vectorSearch に提出します。

自動埋め込み機能では、mongotプロセスが1、2、および3のステップを取り扱います。アプリケーション:

  1. テキスト フィールドに autoEmbed フィールド タイプのベクトル検索インデックスを構成します。

  2. ドキュメントの挿入と更新は通常どおりです。次に、mongot はテキスト フィールドを読み取り、構成された埋め込みモデルを使用して埋め込みを生成して保存します。

  3. 事前計算された埋め込みではなく、クエリテキストで $vectorSearch のクエリを発行します。その後、mongot はクエリテキストの埋め込みを生成します。

自己管理型 mongot 自動埋め込みは、Voyage AI 埋め込みモデルと統合されています。

モデル
説明

voyage-4-lite

大規模でコストに敏感なアプリケーション。

voyage-4

推奨。一般的なテキスト検索のバランスの取れたパフォーマンス。

voyage-4-large

複雑なセマンティック関係の最大精度。

voyage-code-3

コード検索と技術ドキュメントに特殊化されています。

You incur costs for embedding generation. To learn more, see Manage Billing for Automated Embedding.

  • mongot Kubernetes 配置では1.70.1以降です。

  • MongoDB 8.3以降。

  • Two Voyage AI API keys.

    Use two separate keys, one for index-time embedding generation and one for query-time. Separate keys isolate query workload from indexing workload and allow independent rate-limit accounting. To learn more, see Rate Limits.

  • mongot から埋め込みエンドポイントとなる接続されたデバイスへのアウトバウンド ネットワーク アクセス。

    The default endpoint is https://ai.mongodb.com/v1/embeddings, which proxies Voyage AI with MongoDB-managed billing, for keys generated using the Atlas UI. You can also use https://api.voyageai.com/v1/embeddings for direct Voyage AI access if you generated the API key directly from Voyage AI.

You can generate Voyage AI API keys through either of the following paths:

  • (Recommended) Through your Atlas account. Atlas provides API key management with built-in rate-limit configuration. The keys are not tied to an Atlas cluster. To learn more, see Manage API Keys.

  • Through Voyage AI directly at voyageai.com.

例えば mongot-prod-indexmongot-prod-query のように、2 つのキーを生成し、分かりやすい名前を付けます。キーはセキュアシークレットストレージに保存します。

両方のキーを含む Kubernetes secret を作成します。

kubectl create secret generic voyage-api-keys \
--from-literal=indexing-key=<your-index-key> \
--from-literal=query-key=<your-query-key> \
--namespace=<your-namespace>

MongoDBSearch カスタムリソースから参照します。

apiVersion: mongodb.com/v1
kind: MongoDBSearch
metadata:
name: mdbs
spec:
# ...
autoEmbedding:
embeddingModelAPIKeySecret:
name: voyage-api-keys

オプションで、mongot が使用する埋め込みエンドポイントを上書きするには、spec.autoEmbedding.providerEndpoint を設定します。このフィールドを省略すると、mongot は組み込みのデフォルトエンドポイントとなる接続されたデバイス https://ai.mongodb.com/v1/embeddings を使用します。詳細については、MongoDBSearch リソース仕様を参照してください。

After you configure mongot with your Voyage AI API keys, define a Vector Search index that uses the autoEmbed field type. The index definition specifies which text field mongot embeds, which model it uses, the indexing method, quantization, and other parameters. To learn more about the autoEmbed index definition, see MongoDB Vector Search Index Fields.

kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
mongosh --quiet "${MDB_CONNECTION_STRING}" \
--eval "use sample_mflix" \
--eval 'db.movies.createSearchIndex("vector_auto_embed_index", "vectorSearch",
{ "fields": [ {
"type": "autoEmbed",
"modality": "text",
"path": "plot",
"model": "'"${EMBEDDING_MODEL}"'",
"numDimensions": 1024,
"similarity": "cosine",
"quantization": "scalar",
"indexingMethod": "hnsw",
"hnswOptions": {
"maxEdges": 16,
"numEdgeCandidates": 200
}
} ] });'

次の表では、autoEmbed インデックス定義フィールドを説明しています。

フィールド
目的

type: "autoEmbed"

フィールドを自動埋め込みの対象としてマークします。

modality: "text"

データ モダリティ。text は、サポートされている唯一のモダリティです。

path

埋め込むコレクションのフィールド。

model

The Voyage AI model name. The model must be one that your API key has access to.

numDimensions

埋め込みベクトルの次元数。モデルによって、サポートされる次元が決定されます。

similarity

ベクトル検索に使用する類似度関数。サポートされている関数は cosinedotProducteuclidean です。

indexingMethod

使用するインデックスの作成方法。サポートされている方法は flathnsw です。

hnswOptions

(任意) HNSW インデックスオプション。indexingMethodhnswの場合は必須です。

quantization

(任意)使用する量子化の種類。サポートされているタイプはfloatscalarbinarybinaryNoRescoreです。

同じインデックスで autoEmbed フィールドと filter フィールドを混合することができます。同じパス上で autoEmbed と生のベクトル フィールドを混合することはできません。

事前計算された埋め込みではなく、クエリテキストを提出します。mongotがクエリ埋め込みを生成します。

kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \
mongosh --quiet "${MDB_CONNECTION_STRING}" \
--eval "use sample_mflix" \
--eval 'db.movies.aggregate([ {
$vectorSearch: {
index: "vector_auto_embed_index",
path: "plot",
query: "spy thriller",
numCandidates: 150,
limit: 10
}
}, {
$project: {
_id: 0,
plot: 1,
title: 1,
score: { $meta: "vectorSearchScore" }
}
}]);'

To learn more, see Run Vector Search ANN and ENN Queries.

mongot Kubernetes クラスター上の専用の内部データベースに埋め込みを持続します。mongot は、ソース コレクションに埋め込みを保存しません。mongot は、ソース テキストから埋め込みを再生成できますが、埋め込み生成には料金が発生します。

Changes to the embedding model, output dimensions, or quantization trigger a full re-embedding of the affected index. You incur charges for the regeneration. To learn more, see When mongot Regenerates Embeddings.

To learn more, see Generated Embeddings Collection.

mongot 次のいずれかが発生した場合、autoEmbed フィールドの埋め込みを再生成します。

  • ドキュメントを挿入します。

  • ドキュメントの埋め込みフィールドを変更します。mongot は、変更ストリームを介して変更を検出します。

  • インデックス定義で埋め込みモデルを変更します。

  • 埋め込み出力の次元またはデータ型を変更します。

  • テキストフィールドパスを変更します。

最後の3つの項目のいずれかを変更すると、mongotはインデックス全体をゼロから再構築します。再構築は大規模なコレクションにとっては高コストになる可能性があります。モデルの変更は慎重に計画します。

MongoDB では、モデル固有の料金で 100 万トークンごとに課金されます。インデックスの作成コストは、コレクション全体のインデックスフィールドの合計テキスト量に比例します。クエリコストは、クエリテキストの量に比例します。

If you use the Voyage AI API key that you created using your Atlas account, you can view API key usage and rate limits in the Atlas UI. To learn more, see Manage Billing for the Embedding and Reranking API. If you use keys created directly from Voyage AI, you must monitor your usage and rate limits in the Voyage AI dashboard.

Voyage AI 側のレート制限エラーは、mongot ログと、影響を受けたインデックスの失敗したドキュメント指示子として表示されます。これらのエラーによってインデックスが無効になることはありませんが、新しいドキュメントのインデックスの作成が遅延する可能性があります。

シンボリック
考えられる原因

インデックスは数分間を過ぎても PENDING ステータスのままです。

mongot cannot reach the embedding endpoint, or the API key is invalid. Check mongot logs for HTTP errors against the embedding endpoint.

インデックスの遅延が断続的に発生します。

Voyage AI側のレート制限。レート制限を引き上げるか、インデックスの作成時の埋め込みの負荷を軽減します。

インデックスに対するクエリは、埋め込みに関するエラーを返します。

The query API key is invalid or expired. Verify the contents of queryKeyFile.

インデックスに対するすべてのクエリは空の結果を返します。

インデックスが再構築され、コーパスの再埋め込みが続行している可能性があります。db.collection.getSearchIndexes() を使用してインデックスのステータスを確認します。

  • プレビューステータス。自動埋め込みが一般提供される前に、構成の形状、サポートされるモデル、およびデフォルトのエンドポイントが変更される可能性があります。

  • フィールドごとに 1 つの埋め込みモデル。混合モデル インデックスはサポートされていません。

  • 埋め込みモデルのフェイルオーバーはありません。Voyage AI エンドポイントに接続できない場合、新しいドキュメントのインデックスの作成が停滞します。