|
|
FAISS for Local Vector Similarity Search
Author: Venkata Sudhakar
FAISS (Facebook AI Similarity Search) is a high-performance library for efficient similarity search and clustering of dense vectors. It runs entirely in memory with no server or network overhead, making it the fastest option for vector search when your dataset fits in RAM. FAISS supports billions of vectors on a single machine and is used in production by Meta, Spotify, and many AI-first companies. FAISS provides multiple index types optimised for different tradeoffs between search speed, memory usage, and accuracy. IndexFlatL2 and IndexFlatIP are exact search indexes - perfect accuracy but scales linearly with dataset size. IndexIVFFlat and IndexHNSW are approximate indexes - faster search with minimal accuracy loss, suitable for millions of vectors. The below example uses FAISS to build a local semantic search engine for the ShopMax India product catalogue, finding similar products using cosine similarity on Gemini embeddings.
It gives the following output,
Index built with 7 vectors
Top 3 results for: premium noise cancelling headphones
[0.932] Sony WH-1000XM5 noise cancelling wireless headphones
[0.887] Bose QuietComfort 45 wireless headphones
[0.712] Samsung Galaxy S24 256GB smartphone 6.2 inch display
FAISS correctly ranked the Sony and Bose headphones at the top. Search across 7 vectors takes under 1 millisecond. For ShopMax catalogues with up to 100,000 products, IndexFlatIP works perfectly. For catalogues above 1 million products, switch to IndexIVFFlat with nlist=100 clusters for 10x faster approximate search. Save and reload indexes with faiss.write_index and faiss.read_index to avoid re-embedding on every restart.
|
|