Generate embeddings for multiple texts in parallel. This function processes all inputs in memory and returns results in a single tibble.
Usage
hf_embed_batch(
text,
model = "BAAI/bge-small-en-v1.5",
token = NULL,
batch_size = 100L,
max_active = 10L,
progress = TRUE
)Arguments
- 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.
Value
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
Examples
if (FALSE) { # \dontrun{
# 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, ]
} # }