| hf_embed | R Documentation |
Generate dense vector representations (embeddings) for text using transformer models. Useful for semantic similarity, clustering, and as features for ML models. Vector inputs are sent in a single batched Inference API request when possible, which is substantially faster than one API request per text.
hf_embed(
text,
model = hf_default_model("embed"),
token = NULL,
endpoint_url = NULL,
...
)
text |
Character vector of text(s) to embed. |
model |
Character string. Model ID from Hugging Face Hub. Default: "BAAI/bge-small-en-v1.5" (384-dim embeddings). |
token |
Character string or NULL. API token for authentication. |
endpoint_url |
Character string or NULL. A custom Inference Endpoint URL. When provided, requests are sent to this URL instead of the public Inference API. Use for models deployed on dedicated Inference Endpoints. |
... |
Additional arguments (currently unused). |
A tibble with columns: text, embedding (list-column of numeric vectors), n_dims
## Not run:
# Generate embeddings
embeddings <- hf_embed(c("Hello world", "Goodbye world"))
# Access embedding vectors
embeddings$embedding[[1]] # First embedding vector
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.