Class VectorSearchIndexFields.VectorField

java.lang.Object
com.mongodb.client.model.VectorSearchIndexFields.VectorField
All Implemented Interfaces:
Bson
Enclosing class:
VectorSearchIndexFields

@NotThreadSafe public static final class VectorSearchIndexFields.VectorField extends Object implements Bson
A vector field definition for a vector search index.

Instances are created via VectorSearchIndexFields.vectorField(String).

Since:
5.8
  • Method Details

    • numDimensions

      public VectorSearchIndexFields.VectorField numDimensions(int numDimensions)
      Sets the number of dimensions for the vector field.
      Parameters:
      numDimensions - the number of vector dimensions
      Returns:
      this
      Since:
      5.8
    • similarity

      public VectorSearchIndexFields.VectorField similarity(String similarity)
      Sets the similarity function used to compare vectors.

      Supported values:

      • "euclidean" — measures the distance between ends of vectors
      • "cosine" — measures the angle between vectors
      • "dotProduct" — measures both the magnitude and direction of vectors
      Parameters:
      similarity - the similarity function name
      Returns:
      this
      Since:
      5.8
    • indexingMethod

      public VectorSearchIndexFields.VectorField indexingMethod(String indexingMethod)
      Sets the indexing method for this vector field.

      Supported values:

      • "flat" — optimized for multi-tenant use cases with singular, static filters
      • "hnsw" — Hierarchical Navigable Small World graph
      Parameters:
      indexingMethod - the indexing method name
      Returns:
      this
      Since:
      5.8
    • hnswOptions

      public VectorSearchIndexFields.VectorField hnswOptions(Bson hnswOptions)
      Sets the HNSW options for this vector field.

      This is only applicable when the indexing method is "hnsw". A convenience builder is available via HnswSearchIndexOptions, or a raw Document may be passed directly.

      Parameters:
      hnswOptions - the HNSW options
      Returns:
      this
      Since:
      5.8
      See Also:
    • toBsonDocument

      public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry)
      Specified by:
      toBsonDocument in interface Bson
    • toString

      public String toString()
      Overrides:
      toString in class Object