Skip to content
AI.info

Computer vision

Visual Search, Embeddings, and Re-Identification

Build a mental model for visual embeddings, metric learning, candidate retrieval, reranking, open-set recognition, and re-identification.

By the end you can

Similarity begins with the question you choose

“Find images like this” can mean four different requests. The same product. The same individual. The same style. The same semantic category. Each one creates different positive and negative pairs.

Before training an embedding, define which differences should disappear and which must remain visible. That definition is not a modelling detail that can be settled later. It decides what the index is for, who ends up inside the gallery, and what happens to the person the system returns.

An embedding inherits the product's definition of sameness.

Comparison

Three retrieval tasks that should not share one vague metric

The same query image can demand different neighborhoods. Instance retrieval asks whether this is the same object. Semantic search asks what else belongs in the same visual or conceptual family. Re-identification asks whether this is the same entity, seen again, somewhere else. That third question carries the privacy risk listed in its column.

What the risk costs has been priced. On 3 September 2024 the Dutch Data Protection Authority fined Clearview AI €30,500,000, with orders subject to a penalty for non-compliance of up to €5.1 million. The regulator described the product without any of the vocabulary of this lesson: “Customers of Clearview can provide camera images to find out the identity of people shown in the images. For this purpose, Clearview has a database with more than 30 billion photos of people. Clearview scrapes these photos automatically from the Internet. And then converts them into a unique biometric code per face.”

Read that as an architecture and it is the ordinary re-identification pipeline of this lesson. Enrol a gallery. Embed each face into a vector. Search the vector. What separates it from the product catalogue in the first column is that the gallery was assembled by scraping, and that its entries are people who never enrolled. The decision, taken on 16 May 2024, lists the GDPR articles breached: 5(1)(a), 6(1), 9(1), 12, 14, 15 and 27. Clearview did not object, and is therefore unable to appeal against the fine.

30 billion enrolled faces is not a scale achievement in this column. It is the number of people whose biometric code sits in a gallery they were never asked about.

FigureComparison · 3 columns

Instance retrieval

Find the exact object or near-duplicate appearance.

  • Preserve fine details
  • Viewpoint tolerance needed
  • Counterfeit risk
  • Example: product catalog

Semantic similarity

Find items with related visual or conceptual attributes.

  • Category and style matter
  • Multiple valid answers
  • Human relevance varies
  • Example: inspiration search

Re-identification

Match the same entity across cameras or time.

  • Appearance can change
  • Open-set rejection matters
  • Privacy risk is high
  • Example: vehicle tracking

Visual

Candidate retrieval and reranking serve different constraints

Large systems usually separate fast approximate search from expensive verification.

Scale here has been measured. The 2017 paper behind Faiss reported GPU k-selection running at up to 55% of theoretical peak, and nearest-neighbor search 8.5 times faster than the prior GPU state of the art. Four Maxwell Titan X cards built a ten-nearest-neighbor graph over 95 million YFCC100M images in 35 minutes. The same four cards connected a billion vectors in under twelve hours. That is the first stage only. The decision still comes later.

Step five is where the pipeline stops being a ranking problem, and it is the step that gets skipped. Detroit police arrested Robert Williams in January 2020. A face-recognition search had been run on a blurry surveillance still, and it returned, in his counsel's account, “a possible match to an expired driver's license photo of Mr. Williams”. A possible match is a candidate. It is the output of stage two — before filtering, before reranking, before anyone decides or abstains. It was not treated as one. Officers “used Mr. Williams' photo to construct a photo lineup array”, and the arrest followed.

His civil-rights suit, Williams v. City of Detroit, was filed on 13 April 2021 and terminated on 28 June 2024, when the stipulated order of voluntary dismissal with prejudice was signed. The settlement wrote step five into police policy in one sentence: “Under the agreement, police will be required to back up face recognition results with independent and reliable evidence linking a suspect to a crime before making any arrest.”

The engineering lesson is exact. A high-recall retriever is designed to return plausible candidates. It is doing its job when it returns a wrong one. Everything that turns a candidate into a decision — corroboration, threshold, abstention — lives in a later stage. When that stage is missing the pipeline does not fail loudly. It just hands the top-1 result to whoever asked.

FigureProcess · 5 steps
  1. 1. Encode the query

    Map the image or crop into an embedding under fixed preprocessing.

  2. 2. Search an index

    Retrieve a high-recall candidate set with approximate nearest neighbors.

  3. 3. Apply filters

    Use availability, geography, time, permissions, or metadata constraints.

  4. 4. Rerank candidates

    Apply a stronger model or pairwise comparison to the shortlist.

  5. 5. Decide or abstain

    Return ranked results, reject uncertain identity matches, or request review.

Analogy

Organizing a warehouse by walking distance

Products are placed in a warehouse so that items considered interchangeable are stored nearby. The map becomes useful only after deciding whether interchangeability means identical SKU, similar use, or similar appearance.

Shelf distances are fixed by the floor. Learned spaces can distort distances, and can behave differently across subgroups. Neighborhood design encodes a policy.

Distance is meaningful only relative to the training pairs and downstream decision.

Key idea

Easy negatives can make a weak embedding look excellent

If every negative pair comes from unrelated categories, the model may never learn subtle distinctions; hard negatives reveal whether it separates visually similar but different entities.

Mine challenging examples carefully, because mislabeled hard negatives can also damage the space. Inspect pair provenance and uncertainty.

Hard negatives are not a new idea. FaceNet mined its triplets online in 2015, choosing matching and non-matching face patches as the network improved. The embedding took 128 bytes per face. It scored 99.63% on Labeled Faces in the Wild and 95.12% on YouTube Faces DB. Against the best published result at the time, that was a 30% cut in error on both datasets.

Re-identification benchmarks make these choices concrete. Market-1501, released in 2015, holds 32,668 annotated bounding boxes of 1,501 identities. Each identity appears under at most six cameras. The boxes come from a Deformable Part Model detector rather than from hand drawing, and a distractor set of over 500,000 images sits beside them. Open-set behavior is what that distractor set is for.

Whether the reported progress on those benchmarks came from the losses was audited twice in 2020, and the answer was uncomfortable. Metric learning papers from the previous four years had claimed great advances in accuracy, often more than doubling the performance of decade-old methods. Musgrave and colleagues asked whether that was true. Their answer: “We find flaws in the experimental methodology of numerous metric learning papers, and show that the actual improvements over time have been marginal at best.”

A separate group reached the same place that year, from the other direction. It revisited the most widely used objective functions, the crucial parameter choices, and “the commonly neglected mini-batch sampling process”. Its finding: “Under consistent comparison, DML objectives show much higher saturation than indicated by literature.”

That is this section's claim, measured across a field rather than asserted about one model. Batch composition and protocol — which pairs the model ever sees together — accounted for a decade of gains that had been credited to the loss function.

Pair construction can matter as much as the loss function.

Example

Metrics answer different retrieval questions

Use a set of measures rather than one global similarity threshold. Each measure asks a different question. The open-set false accept rate is the one most easily left unmeasured, until somebody outside the team measures it for you.

In July 2018 that is what happened to a live commercial system. Jacob Snow, of the ACLU of Northern California, built the test himself, and the method is small enough to state in full: “we built a face database and search tool using 25,000 publicly available arrest photos”, then searched that gallery with public photos of all 535 members of Congress using Amazon Rekognition. “We used the default match settings that Amazon sets for Rekognition” — a confidence threshold of 80%. The search returned 28 false matches. They were not evenly distributed: “Nearly 40 percent of Rekognition's false matches in our test were of people of color, even though they make up only 20 percent of Congress”.

Amazon did not dispute the count. On the AWS News Blog on 27 July 2018, Dr. Matt Wood restated it: “They found 28 incorrect matches out of 535, using an 80% confidence level; this is a 5% misidentification (sometimes called ‘false positive’) rate and a 95% accuracy rate.” His objection was to the dial rather than the arithmetic. The 80% default, he wrote, is “far too low” for public-safety use. “We recommend 99% for use cases where highly accurate face similarity matches are important”. At that setting “our misidentification rate dropped to zero despite the fact that we are comparing against a larger corpus of faces (30x larger than the ACLU test)” — a collection of 850,000 faces.

Hold the two readings side by side. Same model, same gallery construction, one query set of 535. 28 false accepts at one threshold, zero reported at another, on a gallery more than thirty times the size. The false accept rate is not a property of the embedding that evaluation discovers. It is a number the product sets. And the value it ships with — the default — is the one the world will measure it at.

  • Recall@K: Did at least one relevant item enter the candidate set?
  • Precision@K: How much of the visible shortlist is relevant?
  • Mean average precision: Are multiple relevant items ranked early and consistently?
  • CMC or rank-K rate: At what rank does the correct identity first appear?
  • Open-set false accept rate: How often is an unknown entity assigned a known identity? On 535 queries against 25,000 gallery photos the answer was 28 at the 80% default and, on Amazon's own report, zero at 99%.
  • Latency and memory: Can the index meet serving constraints at target scale?

Steps

Audit a visual embedding before deployment

Move from how the data is defined to how the threshold behaves. Two of these steps have external answers already written for them, and it is cheaper to read those than to rediscover them.

Step one, defining forbidden matches, is not only a product judgement. The AI Act prohibits “the placing on the market, the putting into service for this specific purpose, or the use of AI systems that create or expand facial recognition databases through the untargeted scraping of facial images from the internet or CCTV footage;” That is Article 5(1)(e) of Regulation (EU) 2024/1689. The Parliament adopted it on 13 March 2024 by 523 votes to 46 with 49 abstentions. It was published in the Official Journal on 12 July 2024. The prohibitions apply from 2 February 2025, and breach carries fines of up to €35,000,000 or, for an undertaking, up to 7% of total worldwide annual turnover, whichever is higher. Recital 43 gives the reason: “because that practice adds to the feeling of mass surveillance and can lead to gross violations of fundamental rights, including the right to privacy”. Some galleries are forbidden before a single metric has been chosen.

Steps two and four are where slicing earns its place, and the largest published slice study says what to expect. NIST published it in December 2019, as Part 3 of the Face Recognition Vendor Test. The scale of the evaluation is stated in one sentence: “Together these datasets allowed us to process a total of 18.27 million images of 8.49 million people through 189 mostly commercial algorithms from 99 developers.” The finding sits in the executive summary, under the heading “WHAT WE FOUND”: “Across demographics, false positives rates often vary by factors of 10 to beyond 100 times.” False negatives, by contrast, varied by factors usually below 3.

Two things follow for the audit. First, a single aggregate false accept rate can hide a hundredfold difference between the groups it averages over. That is why step two builds slices and step four fills them with identities absent from the gallery. Second, the spread is a property of particular algorithms rather than of the task. A 2023 GAO report, citing the same NIST work, records that “For a small number of the one-to-many algorithms, differences in false positives across demographic groups were undetectable.” It is measurable, it varies by vendor, and it is therefore something an audit can select on.

FigureProcess · 5 steps
  1. 1. Define relevance

    Write positive, acceptable, and forbidden matches for each use case.

  2. 2. Build pair slices

    Include viewpoint, lighting, occlusion, age, device, and domain changes.

  3. 3. Test neighborhoods

    Inspect nearest neighbors for common and rare query types.

  4. 4. Evaluate open set

    Include identities or products absent from the gallery.

  5. 5. Stress the index

    Measure recall loss, update behavior, latency, and stale embeddings.

Key idea

Nearest is not the same as known

A nearest-neighbor index always returns something unless the product adds rejection logic; the closest gallery item may still be unrelated to the query.

Identity systems require calibrated thresholds, unknown examples, and consequences for false accepts. The consequences have a docket number. Rite Aid ran facial recognition in hundreds of stores from 2012 to 2020, and on 19 December 2023 the FTC sued the retailer over it. “The system generated thousands of false-positive matches, the FTC says.” Among them, customers matched to people enrolled thousands of miles away: a gallery entry that the store's own geography made impossible, returned because it was the nearest one available.

The case did not end in a revised precision@K. The stipulated order, signed on 23 February 2024, provides that Respondents “are prohibited for five (5) years from the effective date of this Order from deploying or using, or assisting in the deployment or use of, any Facial Recognition or Analysis System, whether directly or through an intermediary, in any retail store or retail pharmacy or on any online retail platform.” Five years, every store, every platform. The whole capability withdrawn, not tuned.

Ranking alone is not an identity decision. A system with no way to answer “nobody” will answer somebody every time it is asked.

Open-set evaluation is mandatory when the correct answer can be “none of these.”

Example

Practice: specify an embedding for secondhand fashion

A marketplace wants visually similar listings without collapsing distinct sizes, brands, or counterfeit cues. Write the specification the way the records above would have needed it. Name the forbidden matches. Write the threshold as a number. Decide in advance what happens below it.

  • Define which attributes should dominate similarity and which must remain filterable metadata, and write at least one forbidden match — the pairing the system must never return, whatever its distance.
  • Create one positive pair, one easy negative, and two hard negatives, and say where each came from; a mislabeled hard negative teaches the space a false distinction.
  • Choose a candidate metric and a user-visible ranking metric, then state the confidence threshold you would ship as the default and what the system does below it.
  • Describe how newly added listings enter the index without stale features.
  • Add one slice that tests whether the embedding works across photography styles, and one that reports the false accept rate separately per slice rather than pooled.

Key takeaways