similarity_matrix

def similarity_matrix(xq: np.ndarray, index: np.ndarray) -> np.ndarray

Compute the similarity scores between a query vector and a set of vectors.

Arguments:

  • xq: A query vector (1d ndarray)
  • index: A set of vectors.

Returns:

np.ndarray: The similarity between the query vector and the set of vectors.

top_scores

def top_scores(sim: np.ndarray,
               top_k: int = 5) -> Tuple[np.ndarray, np.ndarray]

Get the top scores and indices from a similarity matrix.

Arguments:

  • sim: A similarity matrix.
  • top_k: The number of top scores to get.

Returns:

Tuple[np.ndarray, np.ndarray]: The top scores and indices.