hf_similarity: Compute Pairwise Similarity

View source: R/embeddings.R

hf_similarityR Documentation

Compute Pairwise Similarity

Description

Compute cosine similarity between all pairs of embeddings. Numeric embeddings with consistent dimensions use vectorized matrix operations for better performance on larger result sets; invalid, zero-length, zero-norm, or dimension-mismatched pairs return 'NA_real_'.

Usage

hf_similarity(embeddings, text_col = "text")

Arguments

embeddings

A tibble with an 'embedding' column (from hf_embed).

text_col

Character string. Name of the text column. Default: "text".

Value

A tibble with columns: text_1, text_2, similarity.

Examples

## Not run: 
sentences <- c("I love cats", "I adore felines", "Dogs are great")
embeddings <- hf_embed(sentences)
similarities <- hf_similarity(embeddings)

## End(Not run)

huggingfaceR documentation built on Aug. 30, 2026, 1:06 a.m.