| llama_embeddings | R Documentation |
Runs the model in embeddings mode and returns the hidden-state vector of the last token. Note: meaningful only for models that support embeddings.
llama_embeddings(ctx, text)
ctx |
Context handle returned by [llama_new_context] |
text |
Character string to embed |
A numeric vector of length n_embd (the model's embedding
dimension) containing the hidden-state representation of the input text.
## Not run:
model <- llama_load_model("model.gguf")
ctx <- llama_new_context(model)
emb1 <- llama_embeddings(ctx, "Hello world")
emb2 <- llama_embeddings(ctx, "Hi there")
# Cosine similarity
similarity <- sum(emb1 * emb2) / (sqrt(sum(emb1^2)) * sqrt(sum(emb2^2)))
cat("Similarity:", similarity, "\n")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.