AIWiki
Malaysia
Back to all articles
Infrastructurevector-searchsimilarity-searchretrieval

FAISS

6 min readUpdated June 2026
FAISS
Full name
Facebook AI Similarity Search
Developed by
Meta AI (formerly Facebook AI Research)
Initial release
2017
License
MIT
Languages
C++ core, Python and Go bindings
Related
Pinecone, Weaviate, Qdrant, ScaNN

FAISS (Facebook AI Similarity Search) is an open-source library for efficient similarity search and dense vector clustering. Developed by Meta AI Research (formerly Facebook AI Research) and publicly released in 2017, FAISS provides a collection of indexing algorithms that enable rapid approximate nearest-neighbour (ANN) search across large collections of high-dimensional vectors. The library is written in C++ with Python and Go bindings and is widely used as the retrieval layer in retrieval-augmented generation systems, recommendation engines, and image search applications.

Background

Many machine learning applications require finding which items in a large database are most similar to a query item. When items are represented as dense vectors produced by neural network embedding models, this task is called nearest-neighbour search in a vector space. Exact nearest-neighbour search requires computing the distance between the query vector and every vector in the database, which is computationally prohibitive for databases containing millions or billions of vectors.

FAISS was developed to solve this problem at industrial scale. Meta AI needed a system that could handle the embedding retrieval requirements of Facebook's product search, advertisement targeting, and content recommendation systems, which involve datasets far too large for exact exhaustive search. The library combines classical information retrieval techniques such as inverted files with modern approximation algorithms to trade a small amount of recall accuracy for orders-of-magnitude speedup.

Index Types

FAISS provides multiple index types suited to different dataset sizes and performance requirements.

Flat Index

The flat index (IndexFlatL2 and IndexFlatIP) performs exact exhaustive search by computing the distance from the query to every vector in the database. It guarantees perfect recall but does not scale to large datasets. It is typically used as a correctness baseline or for small collections (under a few million vectors).

Inverted File Index (IVF)

The IVF index partitions the vector space into a configurable number of clusters using k-means, then assigns each vector to its nearest cluster centroid. At search time, only the vectors in the closest clusters to the query are examined, dramatically reducing the number of distance computations required. The trade-off is that vectors near cluster boundaries may be missed, reducing recall below 100%.

Hierarchical Navigable Small World (HNSW)

HNSW builds a multi-layer proximity graph where each node is connected to its approximate nearest neighbours at different scales. Search traverses the graph from coarse to fine layers, following the most promising edges at each step. HNSW achieves very high recall at low latency and is the preferred index type for many production applications. Its primary disadvantage is high memory consumption because the graph edges must be stored alongside the vectors.

Product Quantisation

Product quantisation (PQ) compresses vectors by splitting each vector into subvectors and encoding each subvector using a learned codebook. The compressed representation dramatically reduces memory requirements, enabling billions of vectors to be stored in the memory that would otherwise hold only tens of millions. PQ is typically combined with IVF (as IVFPQ) to achieve both compression and fast retrieval.

| Index Type | Search Speed | Memory Use | Recall | Best For | |---|---|---|---|---| | Flat | Slow (exact) | High | 100% | Small datasets, baseline | | IVF | Fast | Medium | 90-99% | Medium to large | | HNSW | Very fast | High | 95-99% | Low-latency applications | | IVFPQ | Very fast | Low | 85-95% | Billion-scale datasets |

GPU Acceleration

FAISS provides GPU implementations of several index types that can leverage NVIDIA CUDA for substantially higher throughput. GPU FAISS is particularly useful for batch search scenarios, such as offline indexing and large-scale evaluation, where throughput is more important than single-query latency.

Role in Retrieval-Augmented Generation

FAISS is frequently used as the retrieval backend in RAG systems. In a typical RAG pipeline, a document collection is processed through an embedding model to produce dense vector representations of text chunks, and these are indexed in FAISS. When a user submits a query, the query is also embedded and a nearest-neighbour search retrieves the most semantically similar chunks from the index. These chunks are then appended to the prompt context provided to a generative language model, which synthesises an answer grounded in the retrieved material.

Frameworks such as LangChain, LlamaIndex, and Haystack all provide FAISS integrations as retrieval backends. FAISS is also used internally by managed vector database services that wrap it with additional features such as metadata filtering, persistence, and distributed operation.

Comparison with Managed Vector Databases

While FAISS provides core indexing algorithms, it does not include built-in persistence, distributed operation, or metadata filtering. Managed vector databases such as Pinecone, Weaviate, and Qdrant build on top of FAISS or similar algorithms while adding these production features. Teams that need a lightweight, self-hosted solution often use FAISS directly; teams that need a fully managed service with filtering and real-time updates typically choose a managed alternative.

FAISS is widely used by Malaysian developers building retrieval-augmented generation applications, particularly those processing Bahasa Malaysia and English documents. Malaysian government agencies, legal firms, and financial institutions exploring AI-assisted document search have adopted RAG pipelines using FAISS as the retrieval layer to index internal knowledge bases ranging from policy documents to regulatory filings.

MDEC and Malaysia's National AI Office (NAIO) have supported pilot projects that use FAISS-based retrieval systems for public service information retrieval, allowing citizens to query government information in natural language. These systems index documents from agencies such as LHDN (Inland Revenue Board), JPJ (Road Transport Department), and the Ministry of Health Malaysia, and use semantic search to surface relevant information without requiring keyword-exact matches.

Malaysian universities including Universiti Malaya, Universiti Teknologi Malaysia (UTM), and Universiti Putra Malaysia (UPM) have published research using FAISS for multilingual document retrieval in Bahasa Malaysia, exploring how embedding models trained on Malay-language corpora perform in similarity search tasks relevant to Malaysian government and academic contexts.

In the Malaysian banking sector, institutions such as Maybank, CIMB, and Public Bank have built internal document search systems using embedding models combined with FAISS indexes to enable relationship managers and compliance officers to quickly retrieve relevant policies, product documentation, and regulatory guidelines. These systems are typically deployed on private cloud infrastructure to maintain data residency within Malaysia.

The growth of AI engineering roles in Malaysia, driven partly by MDEC's initiatives and HRD Corp training funding, has increased demand for practical knowledge of vector search tools including FAISS. It is now a standard topic in AI application development courses offered by Malaysian training providers and in university-level AI engineering electives.

See Also

  1. Johnson, J., Douze, M., and Jegou, H. (2019). Billion-scale similarity search with GPUs. IEEE Transactions on Big Data, 7(3), 535-547.
  2. Malkov, Y. A., and Yashunin, D. A. (2018). Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs. IEEE Transactions on Pattern Analysis and Machine Intelligence, 42(4), 824-836.
  3. Meta AI Research. (2024). FAISS: A Library for Efficient Similarity Search. GitHub. https://github.com/facebookresearch/faiss
  4. DataCamp. (2025). What Is FAISS (Facebook AI Similarity Search)? https://www.datacamp.com/blog/faiss-facebook-ai-similarity-search