Class HnswSearchIndexOptions

java.lang.Object
com.mongodb.client.model.HnswSearchIndexOptions
All Implemented Interfaces:
Bson

@NotThreadSafe public final class HnswSearchIndexOptions extends Object implements Bson
Options for the HNSW (Hierarchical Navigable Small World) indexing method in a vector search index.

This class provides a fluent builder for specifying HNSW-specific parameters when creating a vector search index with indexingMethod("hnsw").

Since VectorSearchIndexFields.VectorField.hnswOptions(Bson) accepts any Bson, a raw Document may also be passed directly for forward compatibility.


    vectorField("embedding")
        .indexingMethod("hnsw")
        .hnswOptions(new HnswSearchIndexOptions().maxEdges(16).numEdgeCandidates(200))
 
Since:
5.8
See Also:
  • Constructor Details

    • HnswSearchIndexOptions

      public HnswSearchIndexOptions()
      Creates a new instance with default settings.
      Since:
      5.8
  • Method Details

    • maxEdges

      public HnswSearchIndexOptions maxEdges(int maxEdges)
      Sets the maximum number of connected neighbors for each node in the HNSW graph.
      Parameters:
      maxEdges - the maximum number of edges (connected neighbors)
      Returns:
      this
      Since:
      5.8
    • numEdgeCandidates

      public HnswSearchIndexOptions numEdgeCandidates(int numEdgeCandidates)
      Sets the number of nearest neighbor candidates to consider when building the HNSW graph.
      Parameters:
      numEdgeCandidates - the number of nearest neighbor candidates
      Returns:
      this
      Since:
      5.8
    • 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