The embed() function allows you to embed a text via a specified provider.
It routes the input to the appropriate provider-specific embedding function.
Usage
embed(
.input,
.provider = getOption("tidyllm_embed_default"),
.model = NULL,
.truncate = NULL,
.timeout = NULL,
.dry_run = NULL,
.max_tries = NULL,
.task = NULL,
.dimensions = NULL,
.media_columns = FALSE
)Arguments
- .input
A character vector of texts, a list mixing texts with
img(),audio_file()andvideo_file()objects, or anLLMMessageobject. Each element of a list is embedded as its own row. A nested list, such aslist(list("A cat", img("cat.jpg"))), is one fused item that gets a single vector.provider_capabilities(.what = "embed_media")shows which provider embeds which media type.- .provider
A function or function call specifying the language model provider and any additional parameters. This should be a call to a provider function like
openai(),ollama(), etc. You can also set a default provider function via thetidyllm_embed_defaultoption.- .model
The embedding model to use
- .truncate
Whether to truncate inputs to fit the model's context length
- .timeout
Timeout for the API request in seconds
- .dry_run
If TRUE, perform a dry run and return the request object.
- .max_tries
Maximum retry attempts for requests
- .task
"query"or"document". Adds the task prefix that EmbeddingGemma 2 andgemini-embedding-2read from the text (and setsinput_typeforvoyage()). Media get no prefix. LeaveNULLfor models that take no prefix.- .dimensions
Number of dimensions to return, for providers and models that can shorten their vectors:
gemini(),openrouter(),ollama(),openai()(text-embedding-3models) andmistral()(codestral-embed).voyage()calls this argument.output_dimension.llamacpp()has no such argument, because llama-server ignores it.- .media_columns
If
TRUE, add amodalityand apathcolumn afterinput.modalityis"text","image","audio"or"video"; a fused item lists its parts joined by" + ", such as"text + image".pathholds the file path of the media in the item (joined by" + "for several files) and isNAfor text. Has no effect with.dry_run = TRUE, which returns the request. Defaults toFALSE.
Value
A tibble with the columns input and embeddings, plus modality and path
when .media_columns = TRUE.
The input column contains the texts sent to embed, or a label such as
[IMG] cat.jpg for a media file. A fused item shows its parts joined by " + ", for
example A cat + [IMG] cat.jpg. The embeddings column
is a list column where each row contains an embedding vector of the sent input.
Examples
if (FALSE) { # \dontrun{
c("What is the meaning of life, the universe and everything?",
"How much wood would a woodchuck chuck?",
"How does the brain work?") |>
embed(gemini)
} # }
