How AI recommends visually similar clothing
The engine behind image-based fashion recommendations: turn every product image into a vector with CLIP, then find the closest matches with FAISS / KNN search.
The problem image search solves
Text tags only go so far. A shopper who likes a specific dress wants pieces that look alike — cut, colour, style — not just anything labelled "dress". Image search compares how items actually look, so recommendations feel visually intelligent.
How CLIP turns images into vectors
A multimodal model such as CLIP encodes each product image into an embedding: numbers that capture its visual meaning. Because CLIP places images and text in the same space, "red summer dress" lands near matching images, so photo and text search both work.
Finding similar items with FAISS / KNN
All product embeddings sit in a vector index (FAISS). When a shopper uploads or describes an item, we embed the query and run a K-nearest-neighbour search to return the most visually similar products in milliseconds. Metadata — size, price, stock, delivery — then filters down to what is buyable.
When this approach fits
Image embeddings plus vector search fit any catalog where visual similarity drives choice: fashion, interiors, parts. The same building blocks power document search and duplicate detection. On-premise or cloud depends on volume, sensitivity and cost — covered next.
Key decision: where to run it, and which index
Two choices shape cost and latency here: where the vectors live, and which index type fits the catalog size.
Where should vector search run?
- Strict data-residency or privacy?on-premise or EU-cloud
- Large, steady volume and low latency?on-premise or edge, with compute near the data
- Variable, spiky or experimental?cloud, elastic and autoscaling
- A mix of the above?hybrid: heavy batch near the data, elastic serving in the cloud
Which FAISS index fits the catalog size?
- Under ~1M vectorsexact search (IndexFlatIP): simplest, fully accurate
- ~1M–10M vectorsapproximate (IVF): much faster, tiny accuracy trade-off
- Over ~10M vectorsapproximate with compression (IVF-PQ or HNSW)
Tip: normalise the vectors (L2) and use an inner-product index for cosine similarity.
More technical detail
import faiss, numpy as np
emb = np.load("embeddings.npy").astype("float32")
faiss.normalize_L2(emb) # cosine similarity
index = faiss.IndexFlatIP(emb.shape[1]) # inner-product
index.add(emb)
faiss.write_index(index, "fashion.index")