The worst way to test image search is to upload a photo from your own catalog and check that it comes back first. It will. You gave the engine the answer.
Your users don't have that photo. They have a blurry one taken in a kitchen at night, or a screenshot of somebody's Instagram story with half the product covered by a caption. Whether search works for them is a separate question, and you can answer it in an afternoon.
To test image search, collect 50 to 100 queries that look like real use, write down which products should come back for each, and measure how often they do. Run the same queries after every change. The rest of this post covers picking the queries, a script to score them, and how to tell a real improvement from noise.
Collect bad photos on purpose
Most guides to search relevance start with your query logs. That's good advice for text. Image queries are harder to collect: you may not be storing uploads at all, and if you are, check what your privacy policy says before you turn customers' photos into test data.
So make some. Take 30 products you can physically get to and photograph them badly. Use a phone. Leave the mess in the background. Then save a few screenshots from social media and write a handful of text queries in the words a customer would use.
Keep the queries in groups, because an overall average will hide the thing you need to know:
| Group | What goes in it | What it tells you |
|---|---|---|
phone |
Your own photos, odd angles, bad light | Whether real uploads work |
screenshot |
Social posts, with the UI left in | How much clutter it can take |
crop |
One part of a product: a sole, a pattern, a handle | Whether details are enough |
text |
Descriptions typed by a person | Text-to-image matching |
negative |
Things you don't sell | Whether it can return nothing |
The negative group is the one people skip. Nearest-neighbor search always has a nearest neighbor, so a photo of a bicycle sent to a shoe store will come back with shoes unless something stops it. We wrote about the text version of this in zero-result searches.
One rule for all of it: no query photo can also be in the index. Resized copies and re-exports count too. If you're unsure, run a duplicate check first.
Decide what a correct answer is
This takes longer than the code, and it should.
Someone uploads a photo of a navy crewneck. You stock that sweater in navy and gray, plus a nearly identical navy one from another brand. Which of those are right?
It depends on what the feature promises. If the button says "find this product", only the exact sweater counts, and gray might be a miss. If it says "shop similar", the other brand's sweater is a perfectly good answer. Write the rule down before anyone labels anything. Two people working from different rules will hand you numbers that mean nothing.
Label products rather than images. A product with six photos can take six of your top ten spots, which looks like ten results in a log and like five to a shopper. Store a product_id in each image's metadata and collapse on it before you score.
Here's the format I'd use. It's a list in cases.json:
[
{
"id": "phone-001",
"slice": "phone",
"file": "queries/backpack-hallway.jpg",
"expected": ["bp-1042"]
},
{
"id": "text-001",
"slice": "text",
"text": "brown leather backpack",
"expected": ["bp-1042", "bp-1180"]
},
{
"id": "neg-001",
"slice": "negative",
"file": "queries/bicycle.jpg",
"min_score": 0.6,
"expected": []
}
]
An empty expected list means the right answer is no results.
Four numbers are enough
Hit@1 is how often the first product is correct. For "find this exact item", start here.
Hit@10 is how often a correct product shows up anywhere in the first ten. If hit@10 is high and hit@1 is low, the engine is finding the product and ranking it badly. If both are low, it isn't finding it at all. Those are different problems with different fixes.
MRR@10 gives a correct first result 1 point, second place 1/2, third place 1/3, and so on, then averages. It moves when the right product climbs from eighth to third, which hit@10 can't see.
Recall@10 is how many of the correct products made the first ten. Cap the denominator at ten. If 40 products match "black dress", only ten can fit, and without the cap a perfect result page scores 0.25. The eProduct visual search benchmark caps its recall the same way.
Negatives get their own score: the share that correctly came back empty.
You'll also see nDCG in most articles on this. It's useful when some answers are better than others and you have graded labels. If your labels are yes or no, leave it for later.
The script
This runs against a Vecstore image database, using requests and nothing else outside the standard library. For another engine, rewrite search() and keep the rest.
import base64
import json
import os
from pathlib import Path
import requests
URL = f"https://api.vecstore.app/api/databases/{os.environ['VECSTORE_DB_ID']}/search"
HEADERS = {"X-API-Key": os.environ["VECSTORE_API_KEY"]}
K = 10
def search(case):
if "file" in case:
image = base64.b64encode(Path(case["file"]).read_bytes()).decode()
body = {"image": image}
else:
body = {"content": case["text"]}
body["top_k"] = 50
if "min_score" in case:
body["min_score"] = case["min_score"]
response = requests.post(URL, headers=HEADERS, json=body, timeout=30)
response.raise_for_status()
products = [r["metadata"]["product_id"] for r in response.json()["results"]]
return list(dict.fromkeys(products))[:K]
def score(found, expected):
ranks = [i for i, product in enumerate(found, 1) if product in expected]
return {
"hit@1": float(1 in ranks),
"hit@10": float(bool(ranks)),
"mrr@10": 1 / ranks[0] if ranks else 0.0,
"recall@10": len(ranks) / min(K, len(expected)),
}
def mean(values):
return sum(values) / len(values)
def main():
cases = json.loads(Path("cases.json").read_text())
report = {}
groups = {}
for case in cases:
found = search(case)
if case["expected"]:
result = score(found, set(case["expected"]))
else:
result = {"empty": float(not found)}
report[case["id"]] = {"found": found, **result}
groups.setdefault(case["slice"], []).append(result)
for name, results in groups.items():
line = " ".join(
f"{metric} {mean([r[metric] for r in results]):.2f}" for metric in results[0]
)
print(f"{name:<16} n={len(results):<4} {line}")
Path("report.json").write_text(json.dumps(report, indent=2))
if __name__ == "__main__":
main()
It asks for 50 images and keeps the first ten distinct products, so one heavily photographed product can't crowd out the rest. If your products have dozens of photos each, raise top_k.
Keep negatives in their own group, since they're scored differently. And save each report.json under a new name. You'll want the old one in a minute.
80% of 50 queries is a wide range
Say you run 50 queries and hit@1 is 80%. How good is your search? Somewhere between 67% and 89%, with 95% confidence. Small test sets are less precise than they look:
| Queries | Measured hit@1 | 95% interval (Wilson) |
|---|---|---|
| 25 | 80% | 61% to 91% |
| 50 | 80% | 67% to 89% |
| 100 | 80% | 71% to 87% |
| 200 | 80% | 74% to 85% |
| 400 | 80% | 76% to 84% |
Four times the labeling work cuts the range roughly in half. This is also why a group with eight queries in it can find bugs but can't give you a percentage worth quoting.
So don't compare two averages. Compare the same queries before and after, and look only at the ones that flipped. If a new setup fixes seven queries and breaks three, hit@1 goes up four or five points on a set of 90, and it feels like a win. A two-sided sign test on 7 against 3 gives p = 0.34. Coin flips would do that about a third of the time.
| Fixed | Broken | p-value | My read |
|---|---|---|---|
| 7 | 3 | 0.34 | Don't know yet |
| 12 | 4 | 0.08 | Promising, add queries |
| 10 | 2 | 0.04 | Probably real |
| 9 | 1 | 0.02 | Probably real |
Then open the broken ones and look at the pictures. Three failures on your best-selling category matter more than seven fixes on clearance stock, and no p-value knows that.
Match the failure to the fix
Hit@10 is fine, hit@1 isn't. Lots of near-identical products, usually. Before you touch the model, let people narrow by category or brand with a metadata filter. It's a smaller job and often enough.
Phone photos fail, clean ones pass. Try cropping the query to the product. If the crop works and the full photo doesn't, background is the problem, and a crop box in your upload UI may solve it.
Text queries fail, photos pass. Read the queries. "Something for a beach wedding" asks about an occasion, which may not be visible in a product shot. That belongs in text fields and metadata.
One product never appears. Check that it was indexed. Really. Failed imports and broken image URLs look exactly like bad relevance from the outside.
Negatives return results. Raise min_score, carefully. In Vecstore, image-to-image scores are cosine similarity and text-to-image scores are calibrated separately, so they need different floors. The docs suggest starting at 0.6 and 0.3. Every step up also drops some correct matches, so rerun the normal groups with the same floor before you keep it. A negative score of 1.00 is easy to get if you return nothing to anyone.
When to run it again
Run the set when you change models or thresholds, when you change how images are cropped or resized, and after a large import. The last one catches people out. The search didn't change, but 20,000 new products are now competing for the same ten spots.
Add to it whenever somebody reports a bad result. Put the photo in cases.json before you fix anything, so you can watch it go from fail to pass.
Keep about a fifth of the queries out of sight while you tune. If you pick thresholds by staring at all 100, you'll end up with settings that are great at those 100.
If you don't have an index to test yet, a new Vecstore account comes with 100 free credits. Load a few products and try the worst photo on your phone. The Python guide covers getting images in.
FAQ
How many queries do I need to test image search?
Start with 50 to 100 across your main query types. That's enough to find serious problems. At 100 queries, a measured 80% still has a 95% interval of about 71% to 87%, so you need more to detect small changes.
What is the best metric for image search?
Use hit@1 when users want one exact product, and recall@10 when several results are acceptable. Report hit@10 alongside either one, because it separates ranking problems from retrieval problems.
Can I use product photos from my catalog as test queries?
Only if those photos aren't in the index. Searching with an indexed image tests whether the engine can find a copy, which is much easier than matching a customer's photo.
What similarity score counts as a match?
There is no universal cutoff. Scores depend on the model, the images and the kind of query. Run labeled queries, including some that should return nothing, and choose a floor from the scores you see.

