Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

Source
pub trait EmbeddingProvider {
    // Required method
    fn embed(&self, image: &[u8]) -> Result<Embedding, ImgFprintError>;
}
Expand description

Trait for embedding providers.

Implement this trait to integrate external embedding services such as:

  • OpenAI CLIP API
  • HuggingFace Inference API
  • Local CLIP models (via ONNX, PyTorch, etc.)

The SDK itself does not perform HTTP requests or model inference. It only defines this abstraction, allowing users to bring their own provider implementation.

§Example Implementation

use imgfprint::{EmbeddingProvider, Embedding, ImgFprintError};

struct DummyProvider;

impl EmbeddingProvider for DummyProvider {
    fn embed(&self, _image: &[u8]) -> Result<Embedding, ImgFprintError> {
        // In a real implementation, this would call an external API
        // or run a local model to generate embeddings
        Embedding::new(vec![0.1, 0.2, 0.3, 0.4])
    }
}

Required Methods§

Source

fn embed(&self, image: &[u8]) -> Result<Embedding, ImgFprintError>

Generates a semantic embedding for the given image bytes.

§Arguments
  • image - Raw image bytes in any supported format (PNG, JPEG, etc.)
§Errors

Implementations should return:

§Examples
use imgfprint::{EmbeddingProvider, ImgFprintError};

let image_bytes = vec![0u8; 1000]; // Your image data
let embedding = provider.embed(&image_bytes)?;

Implementors§