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

ベクトル フィールドにインデックスを作成する方法

vector 型を使用してベクトル埋め込みをインデックスできます。ベクター フィールドには、次のタイプの数値の配列を含める必要があります。

  • BSON int32int64、またはdoubleデータ型

  • BSON double データ型

You can use the vectorSearch operator, similar to the $vectorSearch stage, in your $search aggregation pipeline to query fields indexed as the vector type.

次の制限が適用されます。

  • オブジェクトの配列を持つフィールド(MongoDB Search embeddedDocuments 型)を vector 型としてインデックスすることはできません。

  • vector 型を含むインデックス定義では、storedSourcetrueに設定できません。代わりに、include を使用してmongot に保存するフィールドを指定するか、exclude を使用してvector 型のフィールドをストレージから除外してください。

  • You can't use the $vectorSearch stage to query fields indexed as the vector type.

  • MongoDB Search プレイグラウンドで、フィールドをvector タイプとしてインデックスできます。

MongoDB Search vector 型は次のパラメータを取ります。

オプション
タイプ
必要性
説明

type

vector

必須

このフィールド型を識別する、人間が判読できるラベル。値はvectorでなければなりません。

numDimensions

Int

必須

MongoDB Search がインデックス時とクエリ時に強制するベクトルの次元数。このフィールドは vector 型のフィールドにのみ設定できます。8192 以下の値を指定する必要があります。

量子化ベクトルまたは BinData のインデックス作成には、次のいずれかの値を指定できます。

  • 1 取り込み用の int8 ベクトルの場合は 8192

  • 取り込み用の int1 ベクトルに対する 8 の複数形。

  • 1 自動スカラー量子化の場合は binData(float32) ベクトルは 8192 に、array(float32) ベクトルは

  • 自動バイナリ量子化用の binData(float32) ベクトルと array(float32) ベクトルの 8 の倍数。

The embedding model you choose determines the number of dimensions in your vector embeddings, with some models having multiple options for how many dimensions are output. To learn more, see Choosing a Method to Create Embeddings.

similarity

文字列

必須

上位 K 近傍の検索に使用するベクトル類似度関数。このフィールドはvector タイプのフィールドにのみ設定できます。

次のいずれかの値を指定できます。

  • euclidean - ベクトルの端点間の距離を測定します。

  • cosine - ベクトル間の角度に基づいて類似性を測定します。

  • dotProduct - は cosine と同様の類似性を測定しますが、ベクトルの大きさを考慮します。

To learn more, see About the Similarity Functions.

quantization

文字列

任意

ベクトルの自動ベクトル量子化のタイプ。埋め込みが float または double ベクトルである場合にのみ、この設定を使用してください。

次のいずれかの値を指定できます。

  • none -ベクトル埋め込みの自動量子化がないことを示します。 取り込み用に事前に量子化されたベクトルがある場合は、この設定を使用します。 省略した場合、これはデフォルト値になります。

  • scalar - 値を 1 バイト整数に変換するスカラー量子化を示します。

  • binary - 値を単一ビットに変換する バイナリ量子化を示します。この値を使用するには、numDimensions は 8 の倍数である必要があります。

    精度が重要な場合は、binary の代わりに none または scalar を選択します。

To learn more, see About Quantization.

indexingMethod

文字列

任意

ベクトルフィールドのインデックス構造。値は次のとおりです。

  • hnsw - 類似ベクトルが接続されているグラフベースのインデックスの場合

  • flat - 平面、非グラフ、インデックスの場合

If omitted, defaults to hnsw. If you specify hnsw, MongoDB Vector Search performs ANN search over the Hierarchical Navigable Small Worlds graph and ENN search over full-fidelity vectors. You can also specify hnswOptions.

If you specify flat, MongoDB Vector Search performs a full scan over full-fidelity or quantized vectors. During an ANN search, MongoDB Vector Search ignores the settings for numCandidates. For ENN search, MongoDB Vector Search performs a full scan over full-fidelity vectors.

hnswOptions

オブジェクト

任意

Parameters to use for Hierarchical Navigable Small Worlds graph construction. If omitted, uses the default values for the maxEdges and numEdgeCandidates parameters.

重要:これはプレビュー機能として利用可能です。デフォルト値を変更すると、MongoDB Search インデックスとクエリに悪影響を与える可能性があります。

hnswOptions.
maxEdges

Int

任意

Maximum number of edges (or connections) that a node can have in the Hierarchical Navigable Small Worlds graph. Value can be between 16 and 64, both inclusive. If omitted, defaults to 16. For example, for a value of 16, each node can have a maximum of sixteen outgoing edges at each layer of the Hierarchical Navigable Small Worlds graph.

A higher number improves :recall (accuracy of search results) because the graph is better connected. However, this also increases query and indexing time by increasing the number of neighbors to evaluate per graph node, and requires more memory to store the additional nodes for each connection in the Hierarchical Navigable Small Worlds graph.

hnswOptions.
numEdgeCandidates

Int

任意

クエリ時の numCandidates と同様に、このパラメータは、新しいノードに接続する上で最も近い隣接ノードを見つけるため、評価するノードの最大数を制御します。値は、100 から 3200 の範囲で、両端を含みます。省略した場合、デフォルトは 100 になります。

数値が大きいほど、高品質な接続を持つグラフが提供され、検索品質(リコール)が向上しますが、クエリのレイテンシが増加する可能性もあります。

The following index definition example uses the sample_mflix.embedded_movies collection in the sample data. After you load the collection, you can use the following example to index the plot_embedding_voyage_3_large field as the vector type for running queries using the vectorSearch (MongoDB Search Operator). For a sample query to run against this index, see Examples.

このインデックス定義は、動的にインデックス可能なすべてのフィールドがデフォルトtypeSetを用いて自動的にインデックスされ、さらにplot_embedding_voyage_3_large フィールドが以下の設定で vector 型としてインデックスされます。

  • 2048 次元数

  • dotProduct 類似関数

  • scalar 量子化

  • hnsw (デフォルト)インデックスの作成メソッド