Class IndexHNSW

IndexHNSW Index. The Hierarchical Navigable Small World indexing method is based on a graph built on the indexed vectors.

Param

The dimensionality of index.

Param

The number of neighbors used in the graph (defaults to 32).

Param

Metric type (defaults to L2).

Hierarchy

Accessors

  • get dims(): number
  • Returns number

    The dimensionality of vectors.

  • get efConstruction(): number
  • The depth of exploration at add time.

    Returns number

  • set efConstruction(value): void
  • The depth of exploration at add time.

    Parameters

    • value: number

      The value to set.

    Returns void

  • get efSearch(): number
  • The depth of exploration of the search.

    Returns number

  • set efSearch(value): void
  • The depth of exploration of the search.

    Parameters

    • value: number

      The value to set.

    Returns void

  • get indexType(): IndexType
  • Returns IndexType

    The type of index.

  • get isTrained(): boolean
  • returns a boolean that indicates whether training is required.

    Returns boolean

    Whether training is required.

  • get metricArg(): number
  • Returns number

    Argument of the metric type.

  • get metricType(): MetricType
  • Returns MetricType

    The metric of the index.

  • get ntotal(): number
  • Returns number

    The number of verctors currently indexed.

Methods

  • Add n vectors of dimension d to the index. Vectors are implicitly assigned labels ntotal .. ntotal + n - 1

    Parameters

    • x: number[]

      Input matrix, size n * d

    Returns void

  • Add n vectors of dimension d to the index using the provided labels.

    Parameters

    • x: number[]

      Input matrix, size n * d

    • y: (number | BigInt)[]

      Vector identifiers

    Returns void

  • Add n vectors of dimension d to the index with ID's.

    Parameters

    • x: number[]

      Input matrix, size n * d

    • ids: BigInt[]

      Vector identifiers

    Returns void

  • Free all resources associated with the index. Further calls to the index will throw.

    Returns void

  • Merge the current index with another IndexHNSW instance.

    Parameters

    • otherIndex: IndexHNSW

      The other IndexHNSW instance to merge from.

    Returns void

  • Reconstruct desired vector from index. Will throw if not supported by the index type.

    Parameters

    • key: number | BigInt

      Key of vector to reconstruct.

    Returns number[]

    Reconstructed vector of length dims.

  • Reconstruct a batch of vectors from index. Will throw if not supported by the index type.

    Parameters

    • keys: (number | BigInt)[]

    Returns number[]

    Reconstructed vector of length dims.

  • Remove IDs from the index.

    Parameters

    • ids: BigInt[]

      IDs to read.

    Returns number

    number of IDs removed.

  • Reset the index, resulting in a ntotal of 0.

    Returns void

  • Query n vectors of dimension d to the index. return at most k vectors. If there are not enough results for a query, the result array is padded with -1s.

    Parameters

    • x: number[]

      Input vectors to search, size n * d.

    • k: number

      The number of nearest neighbors to search for.

    Returns SearchResult

    Output of the search result.

  • Train n vectors of dimension d to the index. Vectors are implicitly assigned labels ntotal .. ntotal + n - 1

    Parameters

    • x: number[]

      Input matrix, size n * d

    Returns void

  • Write index to a file.

    Parameters

    • fname: string

      File path to write.

    Returns void

  • Construct an index from factory descriptor.

    Parameters

    • dims: number

      Buffer to create index from.

    • descriptor: string

      Factory descriptor.

    • Optional metric: MetricType

      Metric type (defaults to L2).

    Returns Index

    The index read.

Generated using TypeDoc