Hi everyone,
I am working on a project that retrieves visually similar and contextually related images from a local image folder using either a text query or a query image.
I have experimented with CLIP ViT-B/32 and SigLIP 2. They retrieve relevant results for some queries, but image-to-image retrieval sometimes returns only visually similar images instead of contextually related ones. For example, a car-image query may return another car but not a bus or road from the dataset.
I also tested Gemini by providing candidate images, and it produced promising contextual rankings. However, I would prefer a lighter solution rather than depending on a large generative VLM.
Additionally, I came across LocalLens, an existing local image-search application on GitHub, and decided to try it with my image folder using SigLIP 2. Its text search worked well for some queries, but image-to-image results were inconsistent for others.
My current test dataset contains approximately 39 images.
My questions:
-
Is this expected behaviour for embedding-based retrieval, or could it indicate an implementation or threshold issue?
-
What approaches are suitable for retrieving both visually similar and contextually related images?
-
Would query expansion, image captions, metadata, or a lightweight reranking model help?
-
Are there existing implementations or research papers you would recommend for this use case?
I would appreciate suggestions for a controlled evaluation and a practical next step. Thank you!
That is expected from a single embedding: cosine closeness mostly tracks what an image looks like, so a car query returns cars — a bus or a road is related by scene and function, which that vector barely separates. Index your 39 images twice, once by the SigLIP image vector and once by a caption written once offline with a small local captioner, and fuse both rankings for an image query, using its own caption for the second — bus and road can win in caption space, with no per-query VLM cost. Check it by hand-labelling a few queries with two separate gold lists, visually similar and contextually related, and scoring each method against both: a change counts only if it lifts the related list without collapsing the similar one.
Yes, that’s mostly expected with one embedding per image, and nootxlm’s answer is the one I’d try first. An image vector puts a car next to other cars, and a bus or a road only become neighbors once something describes the scene. A caption written once per image gives you that, and you pay for it at insert time only, so no VLM in the query path.
Two small additions. 5 or 6 hand-labeled queries is plenty at this size, and I’d look at the misses by eye before touching any threshold. And keep the captions next to the image vectors, so when you change the caption prompt you can compare old and new rankings on the same queries.
That last bit is how we do it in Pixeltable: the caption is a column computed from the image, with its own embedding index next to the image one. The recipe calls gpt-4o-mini, but a small local captioner plugs in the same way as a custom function: docs.pixeltable.com/howto/cookbooks/images/img-generate-captions