Class HnswSearchIndexOptions

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

@NotThreadSafe public final class HnswSearchIndexOptions extends Object implements org.bson.conversions.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:
  • Field Summary

    Fields inherited from interface org.bson.conversions.Bson

    DEFAULT_CODEC_REGISTRY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance with default settings.
  • Method Summary

    Modifier and Type
    Method
    Description
    maxEdges(int maxEdges)
    Sets the maximum number of connected neighbors for each node in the HNSW graph.
    numEdgeCandidates(int numEdgeCandidates)
    Sets the number of nearest neighbor candidates to consider when building the HNSW graph.
    <TDocument>
    org.bson.BsonDocument
    toBsonDocument(Class<TDocument> documentClass, org.bson.codecs.configuration.CodecRegistry codecRegistry)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.bson.conversions.Bson

    toBsonDocument
  • 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> org.bson.BsonDocument toBsonDocument(Class<TDocument> documentClass, org.bson.codecs.configuration.CodecRegistry codecRegistry)
      Specified by:
      toBsonDocument in interface org.bson.conversions.Bson
    • toString

      public String toString()
      Overrides:
      toString in class Object