FAISS क्या है?
FAISS dense vectors पर कुशल similarity search और clustering के लिए लाइब्रेरी. यह Retrieval & Knowledge (RAG) टूल्स की Vector Databases श्रेणी में आता है; ओपन सोर्स है, C++ में लिखा गया है और MIT लाइसेंस के तहत है। शुरू करने के लिए: conda से इंस्टॉल करें.
सारांश
FAISS (Facebook AI Similarity Search) dense vectors की कुशल similarity search और clustering के लिए एक लाइब्रेरी है। यह C++ में लिखी गई है, जिसमें पूर्ण Python और numpy wrappers शामिल हैं, और इसे मुख्य रूप से Meta के Fundamental AI Research group ने विकसित किया है। आप इसे vectors का एक सेट देते हैं, और यह L2 (Euclidean) distance या dot product का उपयोग करके query के सबसे नज़दीकी vectors खोजती है, जिसमें normalized vectors पर cosine similarity भी शामिल है।
यह उन developers के लिए बनी है जो embeddings के साथ काम करते हैं, जैसे semantic search, recommendation और retrieval-augmented generation। यह कोई अलग से चलने वाला standalone server नहीं, बल्कि एक embedded, in-process लाइब्रेरी है। आप इसे सीधे अपने कोड से call करते हैं और index को memory में या disk पर रखते हैं। इसी वजह से यह कई उच्च-स्तरीय vector databases के नीचे एक आम building block के रूप में इस्तेमाल होती है।
FAISS कई तरह के index types देता है, ताकि आप search speed, accuracy और memory के बीच अपनी ज़रूरत के हिसाब से संतुलन बना सकें। IndexFlatL2 जैसे exact indexes सटीक नतीजे देते हैं, जबकि compressed और graph-based indexes (जैसे HNSW और NSG) अरबों vectors तक scale कर सकते हैं। कुछ algorithms GPU पर भी चलते हैं, जहां GPU indexes अपने CPU वाले समकक्षों की जगह सीधे drop-in replacement के रूप में काम कर सकते हैं।
यह क्या करता है
- dense vectors पर L2 distance या dot product का उपयोग करके exact और approximate nearest-neighbor search
- कई index types, जो हर vector के लिए search time, accuracy और memory के बीच संतुलन बनाते हैं
- Compressed और quantized indexes, जो एक ही server पर RAM में अरबों vectors तक scale करते हैं
- तेज़ approximate search के लिए HNSW और NSG जैसे graph-based indexes
- वैकल्पिक GPU implementation (CUDA या AMD ROCm), जहां GPU indexes CPU indexes की जगह drop in होते हैं, single और multi-GPU सपोर्ट के साथ
- C++ core के साथ पूर्ण Python/numpy wrappers, और k-means clustering व parameter-tuning utilities
- e-means (faiss.contrib.e_means), Meta FAIR का k-means के लिए mini-batch विकल्प, NumPy (CPU) और PyTorch (GPU) versions के साथ

शुरू करें
FAISS Anaconda के लिए precompiled आता है। CPU package इंस्टॉल करें, फिर एक flat index बनाएं और उसमें search करें। पूरे tutorial के लिए README project wiki की ओर इशारा करता है।
conda से इंस्टॉल करें
pytorch channel से CPU build इंस्टॉल करें। अगर आपके पास CUDA है, तो GPU build (faiss-gpu) भी उपलब्ध है।
conda install -c pytorch faiss-cpuIndex बनाएं और search करें
एक exact IndexFlatL2 index बनाएं, उसमें अपने vectors जोड़ें, फिर nearest neighbors के लिए query करें। यह README में दिए गए IndexFlatL2 class का उपयोग करता है; पूरे getting-started tutorial के लिए project wiki देखें।
import numpy as np
import faiss
d = 64 # vector dimension
xb = np.random.random((10000, d)).astype('float32') # database
xq = np.random.random((5, d)).astype('float32') # queries
index = faiss.IndexFlatL2(d) # exact L2 index
index.add(xb) # add vectors
D, I = index.search(xq, k=4) # 4 nearest neighbors
print(I) # neighbor ids
print(D) # squared L2 distancesकमांड और कोड प्रोजेक्ट के अपने दस्तावेज़ों से लिए गए हैं — हमेशा जांचें आधिकारिक repo ताज़ा जानकारी के लिए।
कब इस्तेमाल करें
- embeddings पर semantic search चलाना, जहां आप query vector के सबसे नज़दीकी documents खोजते हैं
- retrieval-augmented generation (RAG) pipeline के लिए in-process retrieval layer के रूप में काम करना
- compressed या GPU indexes का उपयोग करके, अरबों vectors तक, बड़े पैमाने पर nearest-neighbor search चलाना
- अंतर्निहित k-means implementation से dense vectors की clustering करना
How FAISS compares
FAISS alongside other open-source vector databases tools AI/TLDR tracks, ranked by GitHub stars.
| टूल | स्टार | यह क्या करता है |
|---|---|---|
| Supabase | ★ 116k | Managed Postgres backend whose Vector toolkit (pgvector) stores, indexes, and queries embeddings next to transactional data. |
| Redis Cloud | ★ 77.9k | Fully-managed Redis with built-in vector search, offering low-latency similarity and hybrid queries over any embeddings. |
| Milvus | ★ 46.8k | अरबों embeddings में बड़े पैमाने पर खोज के लिए एक ओपन सोर्स वेक्टर डेटाबेस |
| FAISS | ★ 42k | dense vectors पर कुशल similarity search और clustering के लिए लाइब्रेरी |
| Qdrant | ★ 35.9k | Rust में लिखा, समृद्ध payload फ़िल्टरिंग वाला सिमेंटिक सर्च के लिए वेक्टर सर्च इंजन |
| Chroma | ★ 29.8k | ओपन सोर्स एम्बेडिंग डेटाबेस, जो रिट्रीवल और RAG फ़ीचर बनाने में मदद करता है |
| pgvector | ★ 23.9k | Postgres के लिए ओपन सोर्स वेक्टर similarity search |
| turbovec | ★ 17.5k | TurboQuant पर आधारित Rust vector index, जिसमें Python bindings हैं और कोई training step नहीं है |

