barrel_embed_clip (barrel_embed v2.3.0)
View SourceCLIP image/text embedding provider
Uses CLIP (Contrastive Language-Image Pre-training) models for cross-modal embeddings. Both images and text are encoded into the same vector space, enabling image-text similarity search.
Dependencies (transformers, torch, pillow) are installed automatically in the managed venv on first use.
Configuration
Config = #{
model => "openai/clip-vit-base-patch32", %% Model name (default)
python => "python3", %% Python executable (default)
timeout => 120000 %% Timeout in ms (default)
}.Cross-Modal Search
CLIP enables searching images with text queries and vice versa:
%% Embed an image
{ok, ImgVec} = embed_image(ImageBase64, Config),
%% Embed a text query (in same space!)
{ok, TextVec} = embed(<<"a photo of a cat">>, Config),
%% Now you can compare ImgVec and TextVec with cosine similaritySupported Models
- "openai/clip-vit-base-patch32" - Default, 512 dimensions, fast - "openai/clip-vit-base-patch16" - 512 dimensions, higher quality - "openai/clip-vit-large-patch14" - 768 dimensions, best quality - "laion/CLIP-ViT-B-32-laion2B-s34B-b79K" - 512 dims, LAION trained
Use Cases
- Image search with text queries - Finding similar images - Multi-modal content retrieval - Zero-shot image classification
Summary
Functions
Check if provider is available.
Get dimension for this provider.
Generate text embedding (for cross-modal search). Text embeddings are in the same space as image embeddings.
Generate text embeddings for batch.
Generate embedding for a single image. Image should be base64-encoded.
Generate embeddings for multiple images. Images should be base64-encoded.
Initialize the provider.
Provider name.
Functions
Check if provider is available.
-spec dimension(map()) -> pos_integer().
Get dimension for this provider.
Generate text embedding (for cross-modal search). Text embeddings are in the same space as image embeddings.
Generate text embeddings for batch.
Generate embedding for a single image. Image should be base64-encoded.
Generate embeddings for multiple images. Images should be base64-encoded.
Initialize the provider.
-spec name() -> atom().
Provider name.