Class BruteforceSearch

Nearest-neighbor search index object based on brute-force search.

const numDimensions = 5;
const maxElements = 1000;

index = new BruteforceSearch('l2', numDimensions);
index.initIndex(maxElements);

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

  • BruteforceSearch

Constructors

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.

    Returns void

  • returns the number of data points currently indexed.

    Returns number

    The number of data points currently indexed.

  • 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.

  • initializes search index.

    Parameters

    • maxElements: number

      The maximum number of data points.

    Returns void

  • loads the search index.

    Parameters

    • filename: string

      The filename to read from.

    Returns Promise<boolean>

  • loads the search index.

    Parameters

    • filename: string

      The filename to read from.

    Returns void

  • removes the datum point from the search index.

    Parameters

    • label: number

      The index of the datum point to be removed.

    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.

  • 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