View source: R/get_embeddings.R
get_embeddings | R Documentation |
Get pretrained text embeddings from the OpenAI or Mistral API. Automatically batches requests to handle rate limits.
get_embeddings(
text,
model = "text-embedding-3-large",
dimensions = 256,
openai_api_key = Sys.getenv("OPENAI_API_KEY"),
parallel = TRUE
)
text |
A character vector |
model |
Which embedding model to use. Defaults to 'text-embedding-3-large'. |
dimensions |
The dimension of the embedding vectors to return. Defaults to 256. Note that the 'mistral-embed' model will always return 1024 vectors. |
openai_api_key |
Your OpenAI API key. By default, looks for a system environment variable called "OPENAI_API_KEY". |
parallel |
TRUE to submit API requests in parallel. Setting to FALSE can reduce rate limit errors at the expense of longer runtime. |
A matrix of embedding vectors (one per row).
## Not run:
embeddings <- get_embeddings(c('dog', 'cat', 'canine', 'feline'))
embeddings['dog',] |> dot(embeddings['canine',])
embeddings['dog',] |> dot(embeddings['feline',])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.