본문으로 건너뛰기
Skillpedia
데이터베이스260k · #511

faiss

하는 일

Meta의 FAISS를 소개합니다. 수백만에서 수십억 개의 벡터에 대해 빠른 유사도 검색을 합니다. 메타데이터 필터링은 필요 없고 임베딩에서 가장 가까운 이웃 검색을 빠르게 해야 하는 개발자를 위한 것입니다.

사용하는 경우

  • ✓수백만 개의 임베딩 벡터에서 빠른 유사도 검색이 필요할 때.
  • ✓벡터 검색에 GPU 가속을 원할 때.
  • ✓큰 배치로 임베딩을 오프라인에서 처리할 때.

스킬 링크

https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/mlops/faiss/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/mlops/faiss/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제품 임베딩 200만 개로 FAISS 인덱스를 만들고, 질의에 가장 가까운 열 개 항목을 찾아 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 faiss-cpu 또는 faiss-gpu를 설치하고, 적합한 종류의 인덱스를 만든 뒤, 벡터를 추가하고 가장 가까운 결과를 검색합니다. 정확 검색과 근사 검색 인덱스 중에서 고를 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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

자주 묻는 질문

FAISS가 메타데이터를 저장하나요?

아니요. 스킬에 따르면 순수 벡터 유사도만을 위한 것이므로, 메타데이터 필터링이 필요하면 Chroma나 Pinecone을 쓰세요.

CPU와 GPU 중 무엇을 고르나요?

CPU만 쓰면 faiss-cpu를, GPU 지원을 원하면 faiss-gpu를 설치하세요.

무엇으로 작성되었나요?

스킬에 따르면 Python 바인딩이 있는 C++ 라이브러리입니다.

상세 정보

작성자의 원본 설명

Fast vector similarity search at billion scale.

repo: NousResearch/hermes-agent

인기도

GitHub 스타
260k
순위
#511
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬