# Build a Local Image and Video Search API with Clipstral, FastAPI and ChromaDB

> Source: <https://pub.towardsai.net/build-a-local-image-and-video-search-api-with-clipstral-fastapi-and-chromadb-a5f45c18bf4e?source=rss----98111c9905da---4>
> Published: 2026-12-05 17:01:02+00:00

**Recommendation:** Load Clipstral in bfloat16 rather than the README's CPU float32 default to keep peak memory at 2.6 GB, and embed image and text separately then average the vectors for combined queries.
More in the playbook "Inference and self-hosting": <https://wpnews.pro/playbooks/inference-serving>

Follow me on 🔗[LinkedIn](https://www.linkedin.com/in/prajwal-waykos/), 🐙[GitHub](https://github.com/praj-17)

Clipstral is Mistral’s new 1.24B multimodal embedder. It puts images, short videos, and text into one 1,024-dimensional space, so a sentence can retrieve a photo or a clip. I ran it fully locally on an 8 core CPU with 16 GB of RAM, no GPU and no API key, then served search with FastAPI and ChromaDB.

On this box, a typical photo took about 0.29 seconds to index after warmup. A 22 second clip took 1.52 seconds. A text query usually came back in about 0.03 seconds. Peak memory was 2.6 GB after I loaded the model in bfloat16 instead of the official CPU default of float32. All eight text queries ranked the right file first, including a query that returned the video.

``` python
from embedder import ClipstralEmbedder
model = ClipstralEmbedder()  # CPU, bfloat16image_vec = model.embed_images(["coffee.jpg"])[0]text_vec = model.embed_text(["a cup of cappuccino with foam"])[0]print(float(image_vec @ text_vec))  # cosine similarity, since vectors are L2-normalized
```

The rest of this post is how the model is wired, what broke, and the numbers I actually measured.

I am very good at taking photos and very bad at finding them later. “The one with the coffee” turns into twenty minutes of scrolling. “The short clip with the bee” is worse, because video players do not come with a search bar.

Mistral released Clipstral on 30 November 2026, as an open-weight model called Mistral Multimodal Embed. The pitch is simple. Put a photo, a short video, and a sentence into the same vector space, then search with whichever you have. I wanted to see if that works on a plain CPU box, with a folder of freely licensed pictures, one short clip, and a tiny API I could actually curl.

If my photo folder could talk, it would claim the coffee picture was never there.

You do not need a cloud key. The weights are Apache 2.0 on Hugging Face. I used Python 3.13, which is what the official README tests, plus a CPU-only PyTorch wheel, transformers 5.26, ChromaDB, OpenCV, and FastAPI pinned at 0.115.8. Budget about 3 GB of RAM on the bfloat16 path, and 2.5 GB of disk for the weights.

```
python3 -m venv .venv && source .venv/bin/activatepip install torch torchvision --index-url https://download.pytorch.org/whl/cpupip install "transformers>=4.57" fastapi==0.115.8 starlette==0.41.3 \    uvicorn chromadb opencv-python-headless pillow
```

A normal pip install torch on Linux can pull a CUDA wheel you will never use, so the CPU index is worth it. The model card lists older transformers versions. 5.26 loaded the custom code without drama. The FastAPI pin is not optional on this box, and I will come back to that.

Clipstral is a dual encoder, not a chat model. The vision tower is 409 million parameters, a 50 million parameter encoder sits on top for video, and the text tower is 783 million. Every input comes out as one L2-normalized vector of 1,024 numbers. A dot product is then a cosine similarity.

Images keep their aspect ratio by default. The longer side is resized to 448 pixels, and each side is rounded to a multiple of 28 so the patches line up. Official evaluation stays stable from 224 to 1,036 pixels.

A video is 16 frames at 224 pixels, not the whole file. Training used clips of about one minute, so this is a short-clip model, not a full movie indexer.

Text can be a word or a long caption, and the card does not set a fixed context cap. Each call still embeds one thing at a time. If you want image plus text as a single query, embed them separately and average the vectors.

The model code ships with the weights, so you load it with trust_remote_code=True. I split the official snippets into one small class. The important choice is the dtype.

``` python
import torchfrom transformers import AutoImageProcessor, AutoModel, AutoTokenizer
REPO = "mistralai/mistral-multimodal-embed-1B"dtype = torch.bfloat16  # README uses float32 on CPU
model = AutoModel.from_pretrained(REPO, trust_remote_code=True, dtype=dtype).eval()tokenizer = AutoTokenizer.from_pretrained(REPO, trust_remote_code=True)processor = AutoImageProcessor.from_pretrained(REPO, trust_remote_code=True)
```

The official CPU path is float32, which is what they test. Other writeups have seen peaks near 8 GB that way. This machine has 16 GB and other things already running, so I loaded bfloat16 and cast the pixel tensors to match. Features still come back as float32, so the similarities stay ordinary Python floats.

The rest is three methods. Text goes through the tokenizer, images go through the processor, and video is 16 frames stacked into one clip. I also kept a safety net, because OpenCV can report a frame count and then fail a seek on some WebM files. If that happens, the wrapper reads the whole clip and resamples. The bee video reported 550 frames at 25 fps and seeks worked, so the fallback never fired.

The embedder was the easy part. The API was not.

I installed the latest FastAPI, which was 0.165.1, wrote three routes, and started uvicorn. The process came up, the model loaded, and every request returned 500. The traceback pointed at fastapi/telemetry/_asgi.py. A helper called get_logger() with the wrong arguments.

Pinning an older release fixed it immediately.

```
pip install fastapi==0.115.8 starlette==0.41.3
```

After that, health checks and search returned real results. The model never saw a bad request. The web framework just could not log it. If you copy this project, start from the pin in requirements.txt rather than from a bare pip install fastapi.

The app itself is small. /ingest embeds a file and stores the vector in ChromaDB with cosine distance. /search embeds the query and returns the top hits. /search-image lets a photo be the query. Metadata keeps the path, license, and author.

I used eight still photos and one short video from Wikimedia Commons, with licenses checked on the file pages. The set was easy to tell apart. A tabby cat, a cappuccino, the Matterhorn, sunflowers, the Golden Gate Bridge, a husky, a steam locomotive, a beach, and a slow-motion clip of a bee on a flower.

The first photo took 0.59 seconds, which looks like a warmup. After that, most images landed between 0.20 and 0.33 seconds, and the tall beach photo took 0.56 seconds. The bee clip took 1.52 seconds. All nine items ingested in 4.16 seconds once the model was in memory. The ChromaDB folder was 0.63 MB, peak memory was 2,625.7 MB, and cached weights loaded in 1.28 seconds. The first download is the 2.48 GB model.safetensors file.

Then I asked eight sentences. Every top hit was the file I expected.

QueryTop hitScoreTimea cup of cappuccino with foamcoffee.jpg0.2200.134 sa snowy mountain peakmatterhorn.jpg0.2230.036 san orange cat looking at the cameracat.jpg0.2480.030 sa steam trainlocomotive.jpg0.2040.025 sa bee visiting a flowerbee-on-flower.webm0.2910.080 sa sandy tropical beachbeach.jpg0.1680.025 sthe Golden Gate Bridge at sunsetgolden-gate.jpg0.2500.030 sa husky doghusky.jpg0.1780.026 s

The first query was slower, again likely warmup. Later text searches spent about 0.03 seconds embedding the sentence and about 0.001 seconds inside ChromaDB. The scores are cosine similarities, not percentages, and they are not huge. What mattered was the gap. “A bee visiting a flower” scored 0.291 on the video and 0.110 on the sunflower field. “A husky dog” was tighter, 0.178 against 0.147 for the bee clip, and still ranked the husky first.

I also searched with the coffee photo itself. It matched itself at 0.9997 in 0.21 seconds, which is correct when the same file is already in the index. The next neighbors were the Matterhorn and the bridge, at much higher scores than any text query. Image-to-image similarities sit on a different scale here, so trust the ranking more than the raw number.

Clipstral is built for natural photos and short clips. Documents, heavy OCR, and code are out of scope. A one hour video would need to be split, because 16 frames cannot fairly represent it. This is an embedder, not a captioner. It will only tell you which file is closest to the query you typed. 2.6 GB of RAM is comfortable on a 16 GB desktop, and tight on a small laptop if you keep the float32 path.

The comic and the three diagrams are by me. The sample media below are from Wikimedia Commons.

File-level links are in samples/ATTRIBUTION.md. The announcement is [here](https://mistral.ai/news/mistral-multimodal-embed/), the weights and card are on [Hugging Face](https://huggingface.co/mistralai/Mistral-Multimodal-Embed-1B), and the official snippets live in the [GitHub README](https://github.com/mistralai/mistral-multimodal-embed). The paper is [arXiv:2611.40240](https://arxiv.org/abs/2611.40240).

If you’re building something like this and want to talk it through, I’m happy to chat on [Topmate](https://topmate.io/prajwal_waykos/2442158).

[Build a Local Image and Video Search API with Clipstral, FastAPI and ChromaDB](https://pub.towardsai.net/build-a-local-image-and-video-search-api-with-clipstral-fastapi-and-chromadb-a5f45c18bf4e) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.
