Function searchVectorIndex

  • Searches the vector index for the nearest neighbors of a given query.

    Parameters

    • index: HierarchicalNSW

      The HNSW index to search.

    • query: string

      The query string to search for.

    • Optionaloptions: {
          numNeighbors: number;
      } = {}

      Optional parameters for the search.

      • numNeighbors: number

        The number of nearest neighbors to return.

    Returns Promise<{
        id: number;
        distance: number;
    }[]>

    A promise that resolves to an array of nearest neighbors, each with an id and distance.

    If there's an error during the search process.

    const index = await addEmbeddingVectorsToIndex(documentVectors);
    const results = await searchVectorIndex(index, 'example query');
    console.log(results); // [{id: 3, distance: 0.1}, {id: 7, distance: 0.2}, ...]