View source: R/embeddings-batch.R
| hf_embed_batch | R Documentation |
Generate embeddings for multiple texts in parallel. This function processes all inputs in memory and returns results in a single tibble.
hf_embed_batch(
text,
model = hf_default_model("embed"),
token = NULL,
batch_size = 100L,
max_active = 10L,
progress = TRUE,
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. |
batch_size |
Integer. Number of texts per API request. Default: 100. |
max_active |
Integer. Maximum concurrent requests. Default: 10. |
progress |
Logical. Show progress bar. Default: TRUE. |
endpoint_url |
Character string or NULL. A custom Inference Endpoint URL. |
A tibble with columns: - 'text': Original input text - 'embedding': List-column of numeric vectors - 'n_dims': Dimension of embedding (or NA on error) - '.input_idx': Original position in input vector - '.error': TRUE if request failed - '.error_msg': Error message or NA
## Not run:
# Embed many texts in parallel
texts <- c("Hello world", "Goodbye world", "R is great")
result <- hf_embed_batch(texts, max_active = 5)
# Check for errors
errors <- result[result$.error, ]
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.