| hf_nearest_neighbors | R Documentation |
Find the k most similar texts to a query text based on embedding similarity.
hf_nearest_neighbors(
data,
query,
k = 5,
text_col = "text",
model = hf_default_model("embed"),
token = NULL
)
data |
A data frame with an 'embedding' column (from hf_embed_text). |
query |
Character string. The query text to compare against. |
k |
Integer. Number of nearest neighbors to return. Default: 5. |
text_col |
Character string. Name of text column. Default: "text". |
model |
Character string. Model to use for query embedding. Should match the model used for data embeddings. |
token |
Character string or NULL. API token for authentication. |
A tibble with the k nearest neighbors, sorted by similarity (descending).
## Not run:
docs_embedded |>
hf_nearest_neighbors("machine learning", k = 5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.