Search photos and video with plain words: hands-on with Mistral's Clipstral
Mistral's Clipstral, released today, turns photos, video clips, and text in any language into vectors in one shared space. This tutorial builds a working photo and video search engine with it — no API key, no server — and measures it on real queries.
- 1.24B parameters: a 409M vision transformer, a 50M spatio-temporal video encoder, and a 783M multilingual text tower — one shared 1,024-dimensional embedding space.
- Repository: mistralai/mistral-multimodal-embed-1B on Hugging Face (weights, tokenizer, processor, and custom code included); Apache 2.0; trust_remote_code=True required.
- Retrieval scores on Mistral's 37-benchmark protocol: 80.2% image retrieval R@1 and 64.0% video retrieval R@1 — best among open models up to 4B parameters; 59.7 R@1 on the 36-language XM3600 test.
- Default image transform keep_ratio at 448 px keeps each photo's native aspect ratio; video is 16 evenly spaced frames per clip, for clips up to about a minute; text has no fixed length limit.
- Out of scope for this release: documents, OCR-heavy images, and code.
- Verified end to end here: quick-start matrix, 27 photos indexed in 1.2 seconds on an RTX 3090, 15 videos searched, zero-shot city classification, and near-duplicate detection at 0.935.

Your photo library is unsearchable. Not because the photos lack information — every one of them shows exactly what it shows — but because the only index you have is filenames and folders. You can find IMG_4821.jpg if you remember taking it; you cannot find "the photo of the red double-decker bus in the rain" unless you tagged it by hand.
Text-to-image embedding models fixed the image half of that problem years ago: embed every photo once, embed your sentence, and the closest vectors are the matches. What they did not do is video — a clip is not a still image — and most of them cap text at 32 to 77 tokens and only understand English. Mistral's Clipstral, released today, November 30, 2026, closes all three gaps in one model: photos, 16-frame video clips, and multilingual text of any length go into a single shared embedding space. The weights are open under Apache 2.0, so you can run the whole thing on your own machine with no API key and no per-query bill.
This tutorial builds a working photo and video search engine with it. You will load the model, index 27 example photos and 15 example videos, ask questions in English and French, classify photos by city without training a classifier, and find near-duplicate images — every step run end to end, with the real outputs shown. The model is mistralai/mistral-multimodal-embed-1B on Hugging Face, and the example media comes from Mistral's own repository.
What you'll need#
- Python 3.10 or newer and
pip. The model card lists Python 3.13 and transformers 4.57 or later as tested; the run in this tutorial used Python 3.13.14, torch 2.13.0, and transformers 5.15.1. - About 3 GB of free disk — the weights are about 2.3 GB, downloaded once on first load.
- A GPU helps, but is not required. The card tests CPU (float32) as well as GPU (bfloat16). On the RTX 3090 used here, indexing 27 photos took 1.2 seconds; on CPU the same index takes longer, so you index once and save the vectors.
- No accounts, no API keys, no Docker. Everything below runs locally.
- 20–30 minutes. Most of it is the first download.
Step 1: Install and set up the project#
Create an isolated environment and install four packages: PyTorch, transformers, OpenCV for video decoding, and Pillow plus NumPy for image handling.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install torch transformers opencv-python-headless pillow numpy
On Windows, activate with .venv\Scripts\activate. If you have no GPU, install the CPU-only PyTorch build instead — the model card confirms CPU inference in float32 works:
python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
python -m pip install transformers opencv-python-headless pillow numpy
Verify the install before going further:
python -c "import torch, transformers; print(torch.__version__, transformers.__version__)"
# 2.13.0+cu130 5.15.1
Step 2: Load the model#
Clipstral is a dual encoder with three towers: a 409M-parameter vision transformer for images, a 50M spatio-temporal encoder that links frames for video, and a 783M multilingual text tower — 1.24B parameters in total, producing one 1,024-dimensional vector per input. All three towers feed the same space, which is the whole trick: a sentence and a photo that mean the same thing land close together.
import torch
from transformers import AutoImageProcessor, AutoModel, AutoTokenizer
repo_id = "mistralai/mistral-multimodal-embed-1B"
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.bfloat16 if device == "cuda" else torch.float32
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True, dtype=dtype).eval().to(device)
tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
processor = AutoImageProcessor.from_pretrained(repo_id, trust_remote_code=True)
Three details matter. First, trust_remote_code=True: the model code ships inside the repository, and transformers loads it from there — read modeling_mistral_contrastive.py before you trust it in production, and pin a revision with the revision= argument when you deploy. Second, the dtype: bfloat16 on GPU, float32 on CPU, exactly as the model card specifies. Third, the first load downloads about 2.3 GB of weights; on the run used for this tutorial that took roughly two and a half minutes, and later loads take seconds because the files are cached.
Step 3: Your first search#
Run the model card's own quick start, verbatim: two example photos, three text queries, one similarity matrix. It is the smallest possible proof that the shared space works.
import urllib.request
from PIL import Image
texts = ["iconic windmill", "a gothic cathedral", "a statue in a sunny square"]
tok = tokenizer(texts, padding=True, return_tensors="pt")
with torch.inference_mode():
text_features = model.get_text_features(tok.input_ids.to(device), tok.attention_mask.to(device))
assets = "https://raw.githubusercontent.com/mistralai/mistral-multimodal-embed/main/assets"
image_paths = [urllib.request.urlretrieve(f"{assets}/images/image_0{i}.jpg", f"image_0{i}.jpg")[0] for i in (0, 1)]
images = [Image.open(path).convert("RGB") for path in image_paths]
pixel_values = [p.to(device=device, dtype=dtype) for p in processor(images)["pixel_values"]]
with torch.inference_mode():
image_features = model.get_image_features(pixel_values)
print(image_features @ text_features.T) # (num_images, num_texts) cosine similarities
tensor([[0.1960, 0.1270, 0.1440],
[0.1080, 0.2150, 0.1060]])
Read it as a table: rows are the two photos, columns are the three sentences. The first photo is the Moulin Rouge windmill in Paris, and its best match is "iconic windmill" at 0.196. The second is Notre-Dame de Paris, and its best match is "a gothic cathedral" at 0.215. Both correct, both with a clear margin over the runner-up.
Two things to internalize before you go further. The scores look low — 0.15 to 0.25, where CLIP users expect 0.25 to 0.35. That is normal for this model: what matters is the ranking and the gap to the runner-up, not the absolute number. And every feature the model returns is L2-normalized, so a dot product is a cosine similarity — there is no extra normalization step to forget.

Step 4: Build a searchable photo index#
Two photos prove the idea; a search engine needs a collection. Mistral's repository ships 27 example photos with a manifest describing each one, so download the whole set to use as a test collection.
import json
from pathlib import Path
import numpy as np
photos = Path("photos")
photos.mkdir(exist_ok=True)
manifest = json.loads(urllib.request.urlopen(f"{assets}/manifest.json").read())
paths = []
for entry in manifest["images"]:
dest = photos / Path(entry["file"]).name
if not dest.exists():
urllib.request.urlretrieve(f"{assets}/{entry['file']}", dest)
paths.append(dest)
print(f"{len(paths)} photos") # 27 photos
Now embed every photo once. The processor's default transform, keep_ratio, preserves each image's aspect ratio at 448 px on the long side, so images come back at different shapes — the processor returns a list of per-image tensors, and you embed them one at a time:
@torch.inference_mode()
def embed_images(paths):
feats = []
for path in paths:
image = Image.open(path).convert("RGB")
pixel_values = [p.to(device=device, dtype=dtype)
for p in processor([image])["pixel_values"]]
feats.append(model.get_image_features(pixel_values)[0])
return torch.stack(feats)
image_features = embed_images(paths)
np.save("image_embeddings.npy", image_features.cpu().numpy())
print(image_features.shape) # (27, 1024)
On the RTX 3090 used here, all 27 photos embedded in 1.2 seconds. Save the vectors to disk and you never pay that cost again — loading the .npy file is the index:
image_features = torch.from_numpy(np.load("image_embeddings.npy"))
If you want to embed in batches instead of one image at a time, switch the processor to the squash or center_crop transform, which return one stacked tensor — but note the size must then be a multiple of 28, and squashing distorts the aspect ratio the default transform preserves.
Step 5: Ask it questions#
Searching is one matrix multiplication: embed the query, take the dot product with every stored photo vector, sort. The manifest ships four demo queries, and two more below test multilingual search and a specific object.
@torch.inference_mode()
def embed_texts(texts):
tok = tokenizer(texts, padding=True, return_tensors="pt")
return model.get_text_features(tok.input_ids.to(device), tok.attention_mask.to(device))
queries = ["a water ride", "exotic animal", "famous statue", "sunny beach",
"un moulin rouge a Paris", "a giant panda"]
query_features = embed_texts(queries)
sims = (image_features @ query_features.T).cpu().numpy()
names = [p.name for p in paths]
for qi, q in enumerate(queries):
top = np.argsort(-sims[:, qi])[:3]
print(f"\n{q!r}")
for i in top:
print(f" {sims[i, qi]:.3f} {names[i]}")
'a water ride'
0.187 image_03.jpg
0.157 image_06.jpg
0.149 image_14.jpg
'exotic animal'
0.199 image_15.jpg
0.186 image_13.jpg
0.176 image_02.jpg
'famous statue'
0.221 image_11.jpg
0.193 image_10.jpg
0.155 image_01.jpg
'sunny beach'
0.157 image_21.jpg
0.151 image_19.jpg
0.142 image_20.jpg
'un moulin rouge a Paris'
0.250 image_00.jpg
0.165 image_08.jpg
0.164 image_14.jpg
'a giant panda'
0.245 image_25.jpg
0.169 image_15.jpg
0.150 image_13.jpg
Check each one against the manifest's descriptions. "Exotic animal" returns a toucan, a chameleon, and a lemur — three correct animals, in that order. "Famous statue" returns the Statue of Liberty, then the Fountain of Neptune in a medieval Italian piazza, then Notre-Dame — the first two are statues, the third is the nearest miss. "Sunny beach" returns a rocky cove and the two white-sand dune shots. The French query, "un moulin rouge a Paris", returns the Moulin Rouge photo at 0.250 — the highest score of any query in this run — followed by the Eiffel Tower. "A giant panda" returns the panda at 0.245.
The one result that looks wrong is "a water ride": the top photo is a graffiti-covered bobsled track, not a water ride at all. It is not a model failure so much as a collection failure — there is no log-flume photo in the image set, so the model reaches for the nearest "ride" concept it can find. The log-flume shot exists, but it is a video, and video is the next step. A query can only return what is in the collection, and a wrong-looking top hit is usually the collection telling you what it does not contain.

Step 6: Zero-shot classification — no training#
The same embeddings classify, with no classifier to train: write the class names as sentences, embed them, and each photo takes the label it is closest to. The repository's manifest lists nine city photos for exactly this demo.
labels = ["Paris", "Stockholm", "Bologna", "New York", "Amsterdam"]
label_features = embed_texts(labels)
city_photos = [photos / f"image_{n:02d}.jpg" for n in (0, 1, 5, 8, 9, 10, 11, 14, 26)]
city_features = embed_images(city_photos)
scores = (city_features @ label_features.T).cpu().numpy()
for row, path in zip(scores, city_photos):
best = int(np.argmax(row))
print(f"{path.name} -> {labels[best]} ({row[best]:.3f})")
image_00.jpg -> Paris (0.188)
image_01.jpg -> Paris (0.198)
image_05.jpg -> Stockholm (0.227)
image_08.jpg -> Paris (0.203)
image_09.jpg -> Bologna (0.251)
image_10.jpg -> Bologna (0.247)
image_11.jpg -> New York (0.209)
image_14.jpg -> Paris (0.183)
image_26.jpg -> New York (0.219)
Eight of the nine match the evident city: the Moulin Rouge, Notre-Dame, and the Eiffel Tower all land in Paris; Stockholm City Hall lands in Stockholm; the Bologna street and the Fountain of Neptune land in Bologna; the Statue of Liberty and the Manhattan skyline land in New York. The ninth, a snowy canal at night, is the ambiguous one — predicted Paris, and with the lowest score in the set at 0.183. That is the useful signal: a low top score is the model telling you it is not sure, and in a real pipeline that is the photo you route to a human instead of trusting the label. Any label set works the same way — "product shot", "defect", "receipt" — because the classes are just sentences.
Step 7: Search video the same way#
Video goes through the same pipeline with one extra step: decode 16 evenly spaced frames, run each through the vision tower, and let the spatio-temporal encoder compress them into a single 1,024-dimensional vector. The model card's video snippet does exactly this, here applied to the Marianne statue clip from the example set:
import cv2
def read_frames(path, num_frames=16):
capture = cv2.VideoCapture(str(path))
frame_count = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
assert frame_count > 0, f"could not read the frame count of {path}"
frames = []
for index in np.linspace(0, frame_count - 1, num_frames).round().astype(int):
capture.set(cv2.CAP_PROP_POS_FRAMES, int(index))
ok, bgr = capture.read()
assert ok, f"could not decode frame {index} of {path}"
frames.append(Image.fromarray(cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)))
capture.release()
return frames
video_path = urllib.request.urlretrieve(f"{assets}/videos/video_02.mp4", "video_02.mp4")[0]
video_processor = AutoImageProcessor.from_pretrained(repo_id, trust_remote_code=True, size=224)
frames = video_processor(read_frames(video_path))["pixel_values"]
video = torch.stack(frames).to(device=device, dtype=dtype)
with torch.inference_mode():
video_features = model.get_video_features([video])
print(video_features @ text_features.T)
tensor([[0.1470, 0.1440, 0.2990]])
The clip shows the Marianne statue at Place de la République in Paris, and against the same three sentences from Step 3 — windmill, cathedral, statue — "a statue in a sunny square" wins at 0.299, double the other two. Frame order matters, the card notes, and get_video_features accepts either a stacked (B, T, 3, H, W) tensor or a list of clips, so use a list when your clips have different frame counts or sizes.
Now the full video search: embed all 15 example clips and run the same queries as Step 5. Remember "a water ride", the query that misfired on photos:
'a water ride'
0.281 videos/video_00.mp4
0.161 videos/video_04.mp4
0.154 videos/video_06.mp4
'famous statue'
0.224 videos/video_02.mp4
0.132 videos/video_10.mp4
0.122 videos/video_09.mp4
'exotic animal'
0.196 videos/video_08.mp4
0.189 videos/video_04.mp4
0.182 videos/video_06.mp4
'a giant panda'
0.255 videos/video_06.mp4
0.208 videos/video_13.mp4
0.190 videos/video_14.mp4
"A water ride" finds the log-flume clip at 0.281 — the clear winner, and the shot the photo search could not return because it was never a photo. "Famous statue" finds the Marianne clip. "Exotic animal" returns a lemur, flamingos and macaws, and a panda. "A giant panda" returns the panda clip at 0.255. Because photos and videos share the same 1,024-dimensional space, one query can search both at once. Embed every clip the same way, stack the two feature matrices, and take a single dot product:
video_files = []
for entry in manifest["videos"]:
dest = Path("videos") / Path(entry["file"]).name
if not dest.exists():
urllib.request.urlretrieve(f"{assets}/{entry['file']}", dest)
video_files.append(dest)
video_feats = []
for vf in video_files:
frames = video_processor(read_frames(vf))["pixel_values"]
clip = torch.stack(frames).to(device=device, dtype=dtype)
with torch.inference_mode():
video_feats.append(model.get_video_features([clip])[0])
video_features_all = torch.stack(video_feats)
all_features = torch.cat([image_features, video_features_all])
all_names = names + [f.name for f in video_files]
Two limits to respect. Video training uses clips of up to about a minute, represented by 16 frames — longer videos need segment-level aggregation, such as embedding one-minute windows and keeping the best-matching window per video. And the video processor here runs at 224 px rather than the 448 px default, to keep the 16-frame stack small; the card uses 224 px in its own video example.
Step 8: Find near-duplicates and mismatches#
The same vectors that power search also curate the collection. Comparing every photo against every other photo is one more matrix multiplication, and the highest off-diagonal score is the most similar pair in the set:
pair_sims = image_features.cpu().numpy() @ image_features.cpu().numpy().T
np.fill_diagonal(pair_sims, -1.0)
i, j = np.unravel_index(np.argmax(pair_sims), pair_sims.shape)
print(names[i], names[j], f"{pair_sims[i, j]:.3f}")
# image_19.jpg image_20.jpg 0.935
The closest pair in the set is the two white-sand dune shots at 0.935 — near-duplicates, correctly spotted. Run the same comparison between photos and their captions and the low scorers are the mismatched pairs: the wrong caption, the misfiled photo, the image that does not belong. That is the dataset-curation workflow Mistral lists for the model, and it needs no extra code beyond the embeddings you already computed.
Step 9: Point it at your own photos#
Swap the example folder for your own and the tutorial becomes a tool. Point paths at a folder of your photos, run Step 4 once, and save the .npy file — from then on, every query is a dot product against vectors on disk, and adding photos means embedding only the new ones and appending their rows. A few things to know before you lean on it:
- Batch the index. One image per call is fine for 27 photos; for thousands, use the
squashorcenter_croptransform so the processor returns a stacked tensor you can embed in batches. Size must be a multiple of 28. - Stay inside the scope. The card is explicit: natural images and videos are in scope; documents, OCR-heavy content, and code are out. Screenshots of text and scanned pages belong to a document embedding model, not this one.
- One input at a time. An image and a text query are not encoded jointly. If you want a query that combines both — "photos like this one, but at night" — embed each separately and combine the vectors, for example by averaging them. The card calls this late fusion.
- Scale with a vector database. A
.npyfile and NumPy carry a few thousand photos comfortably. Past that, load the same vectors into FAISS, Qdrant, or Milvus — the blog's Qdrant and Milvus Lite tutorials cover both — and keep the search code identical. - Adapt it to your vocabulary. Mistral offers fine-tuning through its Forge platform for domain-specific retrieval — your products, your defects, your sites, your terminology — and the model is sized to deploy on a single H100 or H200 GPU, on-premise or in your VPC, where the photos already are.
Which approach should you use?#
| Situation | Best pick |
|---|---|
| Photos, video, and text in one index, open weights, no API | Clipstral |
| Highest retrieval accuracy and you can serve an 8B model | Qwen3-VL-Embedding-8B — 82.7% image retrieval R@1 vs Clipstral's 80.2% |
| Smallest footprint, on-device or edge | EmbeddingGemma 2 (0.44B, 75.8% image R@1) or SigLIP2 (1.14B, 73.1%) |
| Best image classification specifically | PE-Core-G — 81.6% top-1, ahead of Clipstral's 79.2%, but weaker at retrieval (71.0%) |
| Text documents, scanned pages, code | A text or document embedding model — documents are out of scope for Clipstral |
| No GPU and no interest in running a model | A hosted multimodal embedding API — check pricing per thousand images first |
| Your own visual vocabulary (products, defects, sites) | Clipstral fine-tuned on your collection via Mistral Forge |
All benchmark figures are from Mistral's comparison on the model card: 37 benchmarks under one zero-shot protocol, each model at its best resolution, retrieval scored as recall@1 and classification as top-1 accuracy. The gap between Clipstral and the 8B reference is real but small — 80.2 vs 82.7 on image retrieval, 64.0 vs 66.2 on video — while Clipstral is roughly a sixth of the size.
The takeaway#
Clipstral does one thing and does it well: it puts photos, video clips, and sentences — in any language, at any length — into a single space where a dot product is a search. The workflow is three lines once the model is loaded: embed the collection once, embed the query, sort the dot products. Everything else in this tutorial — zero-shot classification, video search, duplicate detection — is the same vectors reused, which is the point: one index serves every job a media collection has. Start with your own photo folder, index it once, and the next time you need "the photo of the red double-decker bus in the rain", type the sentence.