% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/embed.R
\name{embed_llamar}
\alias{embed_llamar}
\title{Embedding provider for ragnar / standalone use}
\usage{
embed_llamar(
  x,
  model,
  n_gpu_layers = 0L,
  n_ctx = 512L,
  n_threads = parallel::detectCores(),
  embedding = FALSE,
  normalize = TRUE
)
}
\arguments{
\item{x}{Character vector of texts to embed, a data.frame with a \code{text}
column, or missing/\code{NULL} for partial application.}

\item{model}{Either a path to a \code{.gguf} file (character) or a model handle
already loaded via \code{\link{llama_load_model}}.}

\item{n_gpu_layers}{Number of layers to offload to GPU (0 = CPU only, -1 = all).
Ignored when \code{model} is an already-loaded handle.}

\item{n_ctx}{Context window size for the embedding context. Defaults to 512,
typical for embedding models. Ignored when \code{model} is an already-loaded handle.}

\item{n_threads}{Number of CPU threads. Ignored when \code{model} is an
already-loaded handle.}

\item{embedding}{Logical; if \code{TRUE}, use pooled batch decode (efficient for
true embedding models like nomic-embed, bge). If \code{FALSE} (default),
use sequential last-token decode (works with any model).}

\item{normalize}{Logical; if \code{TRUE} (default), L2-normalize each embedding vector.}
}
\value{
\itemize{
  \item If \code{x} is missing or \code{NULL}: a function \code{function(x)} that
    returns a list of numeric vectors (one per input string), suitable for ragnar.
  \item If \code{x} is a character vector: a numeric matrix with \code{nrow = length(x)}
    and \code{ncol = n_embd}.
  \item If \code{x} is a data.frame: the same data.frame with an added \code{embedding}
    column (list of numeric vectors).
}
}
\description{
Computes embeddings using a local GGUF model. When called without \code{x},
returns a function suitable for passing to \code{ragnar_store_create(embed = ...)}.
}
\examples{
\dontrun{
# --- 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)
}
}
