Skip to content
Automation
Skill

/faiss

Facebook's library for efficient similarity search and clustering of dense vectors. Supports billions of vectors, GPU acceleration, and various index types (Flat, IVF, HNSW). Use for fast k-NN search, large-scale vector retrieval, or when you need pure similarity search without

From plugin
dr-claw
1.2k122 skills

Claude Code

$ npx -y skills add OpenLAIR/dr-claw --skill faiss --agent claude-code

SKILL.md

faiss.SKILL.md
name: faiss
description: Facebook's library for efficient similarity search and clustering of dense vectors. Supports billions of vectors, GPU acceleration, and various index types (Flat, IVF, HNSW). Use for fast k-NN search, large-scale vector retrieval, or when you need pure similarity search without metadata. Best for high-performance applications. Also covers Chroma and Qdrant (guides in references/).
version: 1.0.0
author: Orchestra Research
license: MIT
tags: [RAG, FAISS, Similarity Search, Vector Search, Facebook AI, GPU Acceleration, Billion-Scale, K-NN, HNSW, High Performance, Large Scale]
dependencies: [faiss-cpu, faiss-gpu, numpy]

FAISS - Efficient Similarity Search

Facebook AI's library for billion-scale vector similarity search.

When to use FAISS

**Use FAISS when:**

  • Need fast similarity search on large vector datasets (millions/billions)
  • GPU acceleration required
  • Pure vector similarity (no metadata filtering needed)
  • High throughput, low latency critical
  • Offline/batch processing of embeddings

**Metrics**:

  • **31,700+ GitHub stars**
  • Meta/Facebook AI Research
  • **Handles billions of vectors**
  • **C++** with Python bindings

**Use alternatives instead**:

  • **Chroma/Pinecone**: Need metadata filtering
  • **Weaviate**: Need full database features
  • **Annoy**: Simpler, fewer features

Quick start

Installation

# CPU only
pip install faiss-cpu

# GPU support
pip install faiss-gpu

Basic usage

import faiss
import numpy as np

# Create sample data (1000 vectors, 128 dimensions)
d = 128
nb = 1000
vectors = np.random.random((nb, d)).astype('float32')

# Create index
index = faiss.IndexFlatL2(d)  # L2 distance
index.add(vectors)             # Add vectors

# Search
k = 5  # Find 5 nearest neighbors
query = np.random.random((1, d)).astype('float32')
distances, indices = index.search(query, k)

print(f"Nearest neighbors: {indices}")
print(f"Distances: {distances}")

Index types

1. Flat (exact search)

# L2 (Euclidean) distance
index = faiss.IndexFlatL2(d)

# Inner product (cosine similarity if normalized)
index = faiss.IndexFlatIP(d)

# Slowest, most accurate

2. IVF (inverted file) - Fast approximate

# Create quantizer
quantizer = faiss.IndexFlatL2(d)

# IVF index with 100 clusters
nlist = 100
index = faiss.IndexIVFFlat(quantizer, d, nlist)

# Train on data
index.train(vectors)

# Add vectors
index.add(vectors)

# Search (nprobe = clusters to search)
index.nprobe = 10
distances, indices = index.search(query, k)

3. HNSW (Hierarchical NSW) - Best quality/speed

# HNSW index
M = 32  # Number of connections per layer
index = faiss.IndexHNSWFlat(d, M)

# No training needed
index.add(vectors)

# Search
distances, indices = index.search(query, k)

4. Product Quantization - Memory efficient

# PQ reduces memory by 16-32×
m = 8   # Number of subquantizers
nbits = 8
index = faiss.IndexPQ(d, m, nbits)

# Train and add
index.train(vectors)
index.add(vectors)

Save and load

# Save index
faiss.write_index(index, "large.index")

# Load index
index = faiss.read_index("large.index")

# Continue using
distances, indices = index.search(query, k)

GPU acceleration

# Single GPU
res = faiss.StandardGpuResources()
index_cpu = faiss.IndexFlatL2(d)
index_gpu = faiss.index_cpu_to_gpu(res, 0, index_cpu)  # GPU 0

# Multi-GPU
index_gpu = faiss.index_cpu_to_all_gpus(index_cpu)

# 10-100× faster than CPU

LangChain integration

from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings

# Create FAISS vector store
vectorstore = FAISS.from_documents(docs, OpenAIEmbeddings())

# Save
vectorstore.save_local("faiss_index")

# Load
vectorstore = FAISS.load_local(
    "faiss_index",
    OpenAIEmbeddings(),
    allow_dangerous_deserialization=True
)

# Search
results = vectorstore.similarity_search("query", k=5)

LlamaIndex integration

from llama_index.vector_stores.faiss import FaissVectorStore
import faiss

# Create FAISS index
d = 1536
faiss_index = faiss.IndexFlatL2(d)

vector_store = FaissVectorStore(faiss_index=faiss_index)

Best practices

1. **Choose right index type** - Flat for <10K, IVF for 10K-1M, HNSW for quality 2. **Normalize for cosine** - Use IndexFlatIP with normalized vectors 3. **Use GPU for large datasets** - 10-100× faster 4. **Save trained indices** - Training is expensive 5. **Tune nprobe/ef_search** - Balance speed/accuracy 6. **Monitor memory** - PQ for large datasets 7. **Batch queries** - Better GPU utilization

Performance

| Index Type | Build Time | Search Time | Memory | Accuracy | |------------|------------|-------------|--------|----------| | Flat | Fast | Slow | High | 100% | | IVF | Medium | Fast | Medium | 95-99% | | HNSW | Slow | Fastest | High | 99% | | PQ | Medium | Fast | Low | 90-95% |

Resources

  • **GitHub**: https://github.com/facebookresearch/faiss ⭐ 31,700+
  • **Wiki**: https://github.com/facebookresearch/faiss/wiki
  • **License**: MIT

Related tools (merged into this skill)

These were separate skills. Their full guides now live under `references/`; read the one you need when the user asks for that tool or it fits the task better.

| Tool | Guide | What it covers | |---|---|---| | Chroma | [references/chroma/overview.md](references/chroma/overview.md) | Open-source embedding database for AI applications. | | Qdrant | [references/qdrant/overview.md](references/qdrant/overview.md) | High-performance vector similarity search engine for RAG and semantic search. |

Read more
@openlair
Ships withdr-claw

A Super AI Lab with massive AI Doctors as Assistants. Best IDE for Research via AI Power.

1.2k122 skills
Get the whole plugin

Stars on GitHub

Momentum

stars in total
1.2k
Star history of OpenLAIR/dr-claw on GitHub, a chart by star-history.com

Other skills on dr-claw.

dr-claw

dr-claw

Dr. Claw skill for OpenClaw project discovery, idea intake, waiting-session triage, structured session control, event-driven…

@openlair@openlairInstall Skill
academic-researcher

academic-researcher

Academic research assistant for literature reviews, paper analysis, and scholarly writing. Use when: reviewing academic papers,…

@openlair@openlairInstall Skill
aris-ablation-planner

aris-ablation-planner

Use when main results pass result-to-claim (claim_supported=yes or partial) and ablation studies are needed for paper submission.…

@openlair@openlairInstall Skill
aris-arxiv

aris-arxiv

Search, download, and summarize academic papers from arXiv. Use when user says "search arxiv", "download paper", "fetch arxiv",…

@openlair@openlairInstall Skill
aris-auto-review-loop

aris-auto-review-loop

Autonomous multi-round research review loop. Repeatedly reviews via Codex MCP, implements fixes, and re-reviews until positive…

@openlair@openlairInstall Skill

More skills from other plugins.

agent-builder

agent-builder

Load immediately after an Agent intent, before the first agent_builder_* call. Governs how you create, configure, test, and…

n8n12d209k
@n8n-io@n8n-ioInstall Skill
browser-use

browser-use

Direct browser control via CDP for web interaction: automation, scraping, testing, screenshots, and site/app work. Also covers…

@browser-use@browser-useInstall Skill
agent-browser

agent-browser

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling…

@vercel-labs-2@vercel-labs-2Install Skill
add-anydoc

add-anydoc

Add local office-document-to-Markdown conversion to NanoClaw agent containers with the pinned Firecrawl AnyDoc CLI. Use when…

@nanocoai@nanocoaiInstall Skill

Questions about faiss.

Which coding agents can use faiss?
faiss installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.