| embed_llamar | R Documentation |
Computes embeddings using a local GGUF model. When called without x,
returns a function suitable for passing to ragnar_store_create(embed = ...).
embed_llamar(
x,
model,
n_gpu_layers = 0L,
n_ctx = 512L,
n_threads = parallel::detectCores(),
embedding = FALSE,
normalize = TRUE
)
x |
Character vector of texts to embed, a data.frame with a |
model |
Either a path to a |
n_gpu_layers |
Number of layers to offload to GPU (0 = CPU only, -1 = all).
Ignored when |
n_ctx |
Context window size for the embedding context. Defaults to 512,
typical for embedding models. Ignored when |
n_threads |
Number of CPU threads. Ignored when |
embedding |
Logical; if |
normalize |
Logical; if |
If x is missing or NULL: a function function(x) that
returns a list of numeric vectors (one per input string), suitable for ragnar.
If x is a character vector: a numeric matrix with nrow = length(x)
and ncol = n_embd.
If x is a data.frame: the same data.frame with an added embedding
column (list of numeric vectors).
## Not run:
# --- Partial application for ragnar ---
store <- ragnar_store_create(
"my_store",
embed = embed_llamar(model = "embedding-model.gguf", n_gpu_layers = -1)
)
# --- Direct use with path ---
mat <- embed_llamar(c("hello", "world"), model = "embedding-model.gguf")
# --- Direct use with pre-loaded model ---
mdl <- llama_load_model("embedding-model.gguf", n_gpu_layers = -1)
mat <- embed_llamar(c("hello", "world"), model = mdl)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.