pub struct EmbeddingClient { /* private fields */ }Expand description
The llama.cpp embedding client.
EmbeddingClient loads a GGUF embedding model on a dedicated worker thread
and exposes it through Rig’s rig::embeddings::EmbeddingModel trait.
Create one with EmbeddingClient::from_gguf.
use rig::embeddings::EmbeddingModel;
let client = rig_llama_cpp::EmbeddingClient::from_gguf(
"path/to/embedding-model.gguf",
99, // n_gpu_layers
8192, // n_ctx
)?;
let model = client.embedding_model("local");
let embedding = model.embed_text("Hello, world!").await?;
println!("dims: {}", embedding.vec.len());Implementations§
Source§impl EmbeddingClient
impl EmbeddingClient
Sourcepub fn from_gguf(
model_path: impl Into<String>,
n_gpu_layers: u32,
n_ctx: u32,
) -> Result<Self, LoadError>
pub fn from_gguf( model_path: impl Into<String>, n_gpu_layers: u32, n_ctx: u32, ) -> Result<Self, LoadError>
Load a GGUF embedding model and start the embedding worker thread.
§Arguments
model_path— Path to a.ggufembedding model file.n_gpu_layers— Number of layers to offload to the GPU (u32::MAXfor all).n_ctx— Context window size in tokens.
§Errors
Returns a LoadError if the backend fails to initialise or the
model cannot be loaded.
Sourcepub fn embedding_model(&self, model: impl Into<String>) -> EmbeddingModelHandle
pub fn embedding_model(&self, model: impl Into<String>) -> EmbeddingModelHandle
Create an embedding model handle from this client.
Sourcepub fn embedding_model_with_ndims(
&self,
model: impl Into<String>,
ndims: usize,
) -> EmbeddingModelHandle
pub fn embedding_model_with_ndims( &self, model: impl Into<String>, ndims: usize, ) -> EmbeddingModelHandle
Create an embedding model handle with explicit dimensions.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmbeddingClient
impl !RefUnwindSafe for EmbeddingClient
impl Send for EmbeddingClient
impl Sync for EmbeddingClient
impl Unpin for EmbeddingClient
impl UnsafeUnpin for EmbeddingClient
impl !UnwindSafe for EmbeddingClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more