llama-rs 0.16.0

A high-performance Rust implementation of llama.cpp - LLM inference engine with full GGUF support
Documentation
//! `LocalGgufEmbedder` — real embedder impl wrapping an [`Engine`] load
//! of a GGUF embedding model. Reuses the pre-existing
//! `EmbeddingExtractor` and `Engine::embed` pipeline.

use std::path::Path;

use crate::council::embedder::{Embedder, EmbedderError};
use crate::engine::{Engine, EngineConfig};

/// Local GGUF-backed embedder. Loads the model once at construction.
pub struct LocalGgufEmbedder {
    engine: Engine,
    dim: usize,
}

impl std::fmt::Debug for LocalGgufEmbedder {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("LocalGgufEmbedder")
            .field("dim", &self.dim)
            .finish()
    }
}

impl LocalGgufEmbedder {
    /// Load the GGUF at `path` as an embedding model.
    pub fn load(path: &Path) -> Result<Self, EmbedderError> {
        let model_path = path.to_string_lossy().into_owned();
        let cfg = EngineConfig {
            model_path,
            ..EngineConfig::default()
        };
        let engine = Engine::load(cfg)
            .map_err(|e| EmbedderError::Failed(format!("engine load: {e}")))?;
        let dim = engine.model_config().hidden_size;
        Ok(Self { engine, dim })
    }
}

impl Embedder for LocalGgufEmbedder {
    fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedderError> {
        self.engine
            .embed(text)
            .map_err(|e| EmbedderError::Failed(format!("embed: {e}")))
    }

    fn dimension(&self) -> usize {
        self.dim
    }
}