Getting Started with FAISS: A CentOS 7 Installation Guide

CK CK 3788 
Created at  
288 0 0

What is FAISS?

FAISS (Facebook AI Similarity Search) is a library developed by Facebook AI Research for efficient similarity search and clustering of dense vectors. It provides algorithms that search for points in a set of vectors that are closest to a given query vector. This is a fundamental operation in many applications, especially in artificial intelligence and machine learning, where data points are often represented as high-dimensional vectors.

Getting Started with FAISS: A CentOS 7 Installation Guide

Its primary strength lies in handling large datasets—it can search through billions of vectors, even on systems with limited RAM, by employing various indexing strategies. FAISS is written in C++ and has Python bindings, making it accessible to a wide range of developers and researchers. It supports both CPU and GPU implementations for various index types, allowing for highly optimized performance.

Common use cases for FAISS include:

  • Recommendation Systems: Finding items similar to those a user has interacted with.
  • Image/Video Search: Retrieving images or videos similar to a query image/video.
  • Natural Language Processing: Identifying semantically similar documents, paragraphs, or words based on their vector embeddings.
  • Duplicate Detection: Finding near-duplicate items in large datasets.
  • Clustering: Grouping similar data points together.

 

Getting Started with FAISS: A CentOS 7 Installation Guide

 

How to Install FAISS on CentOS 7

Installing FAISS on CentOS 7 can be done via pip for pre-built CPU wheels, or by building from source for more control, especially for GPU support or specific optimizations. CentOS 7 comes with older packages by default, so some steps involve upgrading tools like CMake and ensuring Python 3 is properly set up.

 

Prerequisites

Before installing FAISS, ensure you have the following on your CentOS 7 system:

  • Development Tools: C++ compiler (GCC), make.
  • Python 3 and pip: CentOS 7 often defaults to Python 2. You'll need Python 3 (3.6+ recommended) and its package installer, pip.
  • Git: For cloning the FAISS repository if building from source.
  • CMake: Version 3.10 or higher. CentOS 7's default is often too old (2.8.x).
  • BLAS/LAPACK Library: For high-performance linear algebra operations (e.g., OpenBLAS, MKL, ATLAS).
  • NumPy and SWIG: Python libraries required for building FAISS Python bindings.
  • NVIDIA CUDA Toolkit (Optional): If you plan to use FAISS with GPU support. This requires a compatible NVIDIA GPU and drivers.

 

Method 1: Using Pip (Recommended for CPU-only, pre-built wheels)

This is the easiest method if a pre-built wheel is available for your Python version and CentOS 7 architecture. These wheels are typically CPU-only.

 

1. Ensure Python 3 and pip are installed:

sudo yum install epel-release -y
sudo yum install python3 python3-pip -y
# Ensure pip refers to python3's pip
python3 -m pip install --upgrade pip   


2. Install FAISS using pip:

python3 -m pip install faiss-cpu # For CPU-only version
# OR for GPU support (if pre-built wheel exists, rare for CentOS 7, often needs CUDA installed separately)
# python3 -m pip install faiss-gpu
  • Note: If faiss-cpu or faiss-gpu wheels are not available for your specific Python version or CentOS 7, pip will try to build from source, which might fail if dependencies are not met. In such cases, Method 2 is necessary.

 

Method 2: Building from Source (For GPU support, specific optimizations, or if pip fails)

Building from source gives you full control over the FAISS configuration, including enabling GPU support and linking to specific BLAS libraries.

 

Step 1: Install System Dependencies

1. Update system and install basic development tools:

sudo yum update -y
sudo yum groupinstall "Development Tools" -y
sudo yum install git wget unzip -y    


2. Install Python 3, pip, and required Python packages:

sudo yum install python3 python3-pip -y
python3 -m pip install --upgrade pip
python3 -m pip install numpy swig    


3. Install a BLAS/LAPACK library (OpenBLAS recommended):

sudo yum install openblas-devel -y
# Note: For MKL, you would need to download and install Intel MKL separately.    


4. Upgrade CMake (Crucial for CentOS 7):
CentOS 7's default CMake (2.8.x) is too old. You need CMake 3.10 or newer.

# Download a newer CMake version (e.g., 3.27.x - check cmake.org for latest)
wget https://github.com/Kitware/CMake/releases/download/v3.27.0/cmake-3.27.0-linux-x86_64.tar.gz
sudo tar -zxvf cmake-3.27.0-linux-x86_64.tar.gz -C /opt
    
# Create a symlink to make the new CMake available in your PATH
sudo ln -sf /opt/cmake-3.27.0-linux-x86_64/bin/cmake /usr/local/bin/cmake
sudo ln -sf /opt/cmake-3.27.0-linux-x86_64/bin/ctest /usr/local/bin/ctest
 sudo ln -sf /opt/cmake-3.27.0-linux-x86_64/bin/cpack /usr/local/bin/cpack
    
# Verify CMake version
cmake --version 


5. Install CUDA Toolkit (if building with GPU support):
Follow NVIDIA's instructions to install the CUDA Toolkit for CentOS 7. This is a complex step involving driver installation, nvcc, cudnn, etc.

 

Step 2: Clone FAISS Repository

git clone https://github.com/facebookresearch/faiss.git
cd faiss

 

Step 3: Build FAISS Core Library

1. Create a build directory:

mkdir build && cd build


2. Run CMake with desired options:

  • CPU-only build (recommended for most CentOS 7 users): Adjust BLAS_LIBRARIES path if your OpenBLAS installation is different. You can find it with find /usr -name "libopenblasp*so".
cmake .. \
              -DFAISS_ENABLE_GPU=OFF \
              -DBUILD_SHARED_LIBS=ON \
              -DBUILD_DEMOS=OFF \
              -DBUILD_TESTING=OFF \
              -DFAISS_ENABLE_PYTHON=ON \
              -DBLAS_LIBRARIES="/usr/lib64/libopenblasp-r0.3.20.so" # Adjust path to your OpenBLAS library
        
  • GPU build (requires CUDA Toolkit installed):
cmake .. \
              -DFAISS_ENABLE_GPU=ON \
              -DBUILD_SHARED_LIBS=ON \
              -DBUILD_DEMOS=OFF \
              -DBUILD_TESTING=OFF \
              -DFAISS_ENABLE_PYTHON=ON \
              -DBLAS_LIBRARIES="/usr/lib64/libopenblasp-r0.3.20.so" \ # Or MKL, etc.
              -DCUDA_ARCHITECTURES="All" # Or specific arch, e.g., "75" for RTX 20 series
        


3. Compile FAISS:

make -j $(nproc) # Compiles using all available CPU cores


4. Optional: Install C++ libraries system-wide:

sudo make install 

 

Step 4: Install Python Bindings

1. Navigate back to the FAISS root directory:

cd ..


2. Install Python bindings:

python3 setup.py install
# Alternatively, you can use pip:
# python3 -m pip install .

 

Step 5: Verify Installation

Open a Python 3 interpreter and try to import FAISS:

python3
import faiss
print(faiss.__version__)


If the import is successful and prints a version number, FAISS has been successfully installed.

 

Tags AI Similarity Search FAISS GPU GPU Integration SWIG Similarity Search Facebook X
Comments 0
Similar posts
  1. Milvus & FAISS: Decoding Their ML Synergy
    286
  2. Recommended Vector DB Structure for Amazon Bedrock Integration
    393
  3. Deep Dive into Vector Databases: Understanding Collections (Not Tables) and Embeddings
    240
  4. Difference between CPU and GPU - Why GPU is faster than CPU?
    809
  5. Rust-GPU-tools for interacting with various GPU APIs
    756
  6. Image Embeddings for Vector Databases
    254
  7. NVIDIA CUDA library which can be integrated with C/C++
    377
  8. Technical Hierarchy of AI Agents
    825
  9. Integrating VectorDB stored in S3 with Amazon Bedrock
    429
  10. How to overcome the prompt size limit when you use Claude via Bedrock - Chunking / Splitting the Input
    500
  11. Demystifying FAISS: Your Guide to ANN(Approximate Nearest Neighbor) Search
    326
  12. Building GPU Clusters on GCP, Azure, and AWS: A Practical Guide and Head-to-Head Comparison
    387
  13. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    255
  14. Designing a Data Curation System Around a Vector Database
    230
  15. What is RedisVL?
    114
  16. Content-Based Filtering for Recommendation Service (aka User-based Model)
    194
  1. Conversation Multi-Agent Chatbot with On-the-Fly Code Execition via Microsoft AutoGen
    305
  2. CMake - a cross-platform build system generator that creates Makefiles used in C++ projects
    298
  3. How To Check If Your Printer Is Connected Using C#
    1,027
  4. KMP String Matching Algorithm
    676
  5. How to get process id in C# like windows task manager ?
    871
  6. How to implement switch statement in C# ?
    990
  7. How to implement while loop in C# ?
    1,350
  8. How to delete file ?
    1,199
  9. How to convert integer to text string ?
    701
  10. How to convert text string to integer ?
    613
  11. How to set an certain color as transparent color on bitmap
    526
  12. How to resize and save PNG or Jpeg Image file ?
    638
  13. How to display message box in C#
    1,126
  14. How to convert bitmap image to jpeg image ?
    360
  15. To load image from file
    456
  16. URL Encode, Decode function for MFC
    608
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    29
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  4. How do I create animated background for Google Meet?
    22,896
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  8. Array of arguments passed to script in PHP
    97
  9. Invalid Auction Storms in Ad Tech
    106
  10. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  11. The Two Clocks of Ad Server Architecture
    77
  12. Frequency Cap Architecture Overview
    526
  13. Collecting Proof-of-Play from 100,000 Screens
    152
  14. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  16. TPU & GPU Cluster Management Tools
    257
  17. The Concept of Scaffolding in AI Agents
    244
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  22. Machine Learning: Training vs. Ranking
    229
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  25. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  26. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    672
  27. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  28. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232
  29. Understanding Data Lineage
    271
  30. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    175