
Get text embeddings with optional caching
get_embeddings.RdA thin wrapper around fuzzylink::get_embeddings() that adds
file-based caching. If cache points to an existing file, embeddings
for documents already present in the cache are loaded from disk.
Embeddings for any documents not found in the cache are fetched via
the API and appended to the cache before returning.
Usage
get_embeddings(
documents,
cache = NULL,
type = c("text", "image"),
model = NULL,
...
)Arguments
- documents
A character vector of texts to embed. When
type = "image", a character vector of paths to local image files.- cache
Optional path to an
.rdsfile. If the file exists, cached embeddings matchingdocuments(by row name) are reused. Any new documents are fetched and written back to the cache. IfNULL, embeddings are always computed fresh without caching.- type
One of
"text"(default) or"image"."text"embedsdocumentsviafuzzylink::get_embeddings()(OpenAI/Mistral text embeddings)."image"treatsdocumentsas local image file paths and embeds them via OpenRouter's multimodal embeddings endpoint, which requires anOPENROUTER_API_KEYenvironment variable.- model
Character string naming the embedding model to use. When
NULL(the default), eachtypeuses its own built-in default:"text-embedding-3-large"fortype = "text", or"google/gemini-embedding-2"fortype = "image".- ...
Additional arguments passed to
fuzzylink::get_embeddings()(fortype = "text") or to the internal OpenRouter request body (fortype = "image").