Prompt
need image and text embeddings in one pipeline
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
Yes — you can build a single pipeline that produces both image and text embeddings. The most common approach is to use a multimodal model that maps images and text into the same vector space.
Good options
1) OpenAI CLIP-style models
These are designed exactly for this use case:
- encode images into embeddings
- encode text into embeddings
- embeddings are comparable via cosine similarity
2) Hugging Face multimodal models
Examples:
openai/clip-vit-base-patch32laion/CLIP-ViT-B-32-laion2B-s34B-b79Ksentence-transformers/clip-ViT-B-32
Typical one-pipeline flow
- Input text and/or image
- Preprocess each modality
- Run through the same multimodal encoder
- Store embeddings in the same vector DB or similarity index
Example in Python using Hugging Face CLIP
from PIL import Image
import torch
from transformers import CLIPProcessor, CLIPModel
model_name = "openai/clip-vit-base-patch32"
model = CLIPModel.from_pretrained(model_name)
processor = CLIPProcessor.from_pretrained(model_name)
# Text embedding
texts = ["a cat sitting on a sofa"]
text_inputs = processor(text=texts, return_tensors="pt", padding=True)
with torch.no_grad():
text_emb = model.get_text_features(**text_inputs)
# Image embedding
image = Image.open("cat.jpg").convert("RGB")
image_inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
image_emb = model.get_image_features(**image_inputs)
print(text_emb.shape, image_emb.shape)
If you want a single API call for both
You can wrap it like this:
def embed_multimodal(text=None, image_path=None):
outputs = {}
if text is not None:
text_inputs = processor(text=[text], return_tensors="pt", padding=True)
with torch.no_grad():
outputs["text_embedding"] = model.get_text_features(**text_inputs)
if image_path is not None:
image = Image.open(image_path).convert("RGB")
image_inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs["image_embedding"] = model.get_image_features(**image_inputs)
return outputs
Important note
If your goal is:
- search text by image
- search images by text
- retrieve matching items across modalities
then a CLIP-like model is the right choice.
If your goal is:
- general-purpose text embeddings
- and separate image embeddings for another task
then you might prefer separate specialized models.
If you want, I can give you:
- a FastAPI endpoint for this,
- a batch pipeline for many images/texts,
- or a vector DB integration example.