Class HierarchicalNSW

Approximate nearest-neighbor search index object based on Hierarchical navigable small world graphs.

const numDimensions = 5;
const maxElements = 1000;

index = new HierarchicalNSW('l2', numDimensions);
index.initIndex(maxElements, 16, 200, 100);

index.addPoint([0, 1, 2, 3, 4], 0);
index.addPoint([1, 2, 3, 4, 5], 1);
index.addPoint([3, 4, 5, 6, 6], 2);

const numNeighbors = 3;
const result = index.searchKnn([1, 4, 2, 3, 4], numNeighbors);

console.table(result);

Hierarchy

  • HierarchicalNSW

Constructors

  • Parameters

    • spaceName: SpaceName

      The metric space to create for the index ('l2', 'ip', or 'cosine').

    • numDimensions: number

      The dimesionality of metric space.

    Returns HierarchicalNSW

Methods

  • adds a datum point to the search index.

    Parameters

    • point: number[]

      The datum point to be added to the search index.

    • label: number

      The index of the datum point to be added.

    • Optional replaceDeleted: boolean

      The flag to replace a deleted element (default: false).

      Optional

    Returns void

  • returns the number of data points currently indexed.

    Returns number

    The number of data points currently indexed.

  • returns the ef parameter.

    Returns number

    The ef parameter value.

  • returns a list of all elements' indices.

    Returns number[]

    The list of indices.

  • returns the maximum number of data points that can be indexed.

    Returns number

    The maximum number of data points that can be indexed.

  • returns the dimensionality of data points.

    Returns number

    The dimensionality of data points.

  • returns the datum point vector specified by label.

    Parameters

    • label: number

      The index of the datum point.

    Returns number[]

    The datum point vector.

  • Initialize index.

    Parameters

    • maxElements: number

      The maximum number of elements.

    • Optional m: number

      The maximum number of outgoing connections on the graph (default: 16).

      Optional
    • Optional efConstruction: number

      The parameter that controls speed/accuracy trade-off during the index construction (default: 200).

      Optional
    • Optional randomSeed: number

      The seed value of random number generator (default: 100).

      Optional
    • Optional allowReplaceDeleted: boolean

      The flag to replace deleted element when adding new element (default: false).

      Optional

    Returns void

  • Initialize index.

    Parameters

    • opts: {
          allowReplaceDeleted?: boolean;
          efConstruction?: number;
          m?: number;
          maxElements: number;
          randomSeed?: number;
      }
      • Optional allowReplaceDeleted?: boolean
      • Optional efConstruction?: number
      • Optional m?: number
      • maxElements: number
      • Optional randomSeed?: number

    Returns void

  • marks the element as deleted. The marked element does not appear on the search result.

    Parameters

    • label: number

      The index of the datum point to be marked.

    Returns void

  • loads the search index.

    Parameters

    • filename: string

      The filename to read from.

    • Optional allowReplaceDeleted: boolean

      The flag to replace deleted element when adding new element (default: false).

      Optional

    Returns Promise<boolean>

  • loads the search index.

    Parameters

    • filename: string

      The filename to read from.

    • Optional allowReplaceDeleted: boolean

      The flag to replace deleted element when adding new element (default: false).

      Optional

    Returns void

  • resizes the search index.

    Parameters

    • newMaxElements: number

      The new maximum number of data points.

    Returns void

  • returns numNeighbors closest items for a given query point.

    Parameters

    • queryPoint: number[]

      The query point vector.

    • numNeighbors: number

      The number of nearest neighbors to search for.

    • Optional filter: FilterFunction

      The function filters elements by its labels.

      Optional

    Returns SearchResult

    The search result object consists of distances and indices of the nearest neighbors found.

  • sets the ef parameter.

    Parameters

    • ef: number

      The size of the dynamic list for the nearest neighbors.

    Returns void

  • unmarks the element as deleted.

    Parameters

    • label: number

      The index of the datum point to be unmarked.

    Returns void

  • saves the search index.

    Parameters

    • filename: string

      The filename to save to.

    Returns Promise<boolean>

  • saves the search index.

    Parameters

    • filename: string

      The filename to save to.

    Returns void

Generated using TypeDoc