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_core::embeddings::EmbeddingModel trait.
Create one with EmbeddingClient::from_gguf.
use rig_core::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§
Source§impl Drop for EmbeddingClient
impl Drop for EmbeddingClient
Auto Trait Implementations§
impl !RefUnwindSafe for EmbeddingClient
impl !UnwindSafe for EmbeddingClient
impl Freeze for EmbeddingClient
impl Send for EmbeddingClient
impl Sync for EmbeddingClient
impl Unpin for EmbeddingClient
impl UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more