⚡ Meta FAISS(数十億ベクトルの類似検索)
Meta製の高速ベクトル類似検索ライブラリFAISS Skill。GPU加速対応。
📺 まず動画で見る(YouTube)
▶ 【最新版】Claude(クロード)完全解説!20以上の便利機能をこの動画1本で全て解説 ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
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.
🇯🇵 日本人クリエイター向け解説
Meta製の高速ベクトル類似検索ライブラリFAISS Skill。GPU加速対応。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o faiss.zip https://jpskill.com/download/151.zip && unzip -o faiss.zip && rm faiss.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/151.zip -OutFile "$d\faiss.zip"; Expand-Archive "$d\faiss.zip" -DestinationPath $d -Force; ri "$d\faiss.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
faiss.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
faissフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 2
💬 こう話しかけるだけ — サンプルプロンプト
- › Meta FAISS(数十億ベクトルの類似検索) を使って、最小構成のサンプルコードを示して
- › Meta FAISS(数十億ベクトルの類似検索) の主な使い方と注意点を教えて
- › Meta FAISS(数十億ベクトルの類似検索) を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
FAISS - 効率的な類似性検索
Facebook AIによる、数十億規模のベクトル類似性検索のためのライブラリです。
FAISS を使用するタイミング
FAISS を使用するのは次のような場合です。
- 大規模なベクトルデータセット(数百万/数十億)で高速な類似性検索が必要な場合
- GPU アクセラレーションが必要な場合
- 純粋なベクトル類似性(メタデータフィルタリングが不要)が必要な場合
- 高いスループットと低いレイテンシが重要な場合
- エンベディングのオフライン/バッチ処理を行う場合
指標:
- 31,700+ GitHub スター
- Meta/Facebook AI Research
- 数十億のベクトルを処理可能
- Python バインディングを備えた C++
代わりに代替手段を使用するのは次のような場合です。
- Chroma/Pinecone: メタデータフィルタリングが必要な場合
- Weaviate: 完全なデータベース機能が必要な場合
- Annoy: よりシンプルで、機能が少ない場合
クイックスタート
インストール
# CPU のみ
pip install faiss-cpu
# GPU サポート
pip install faiss-gpu
基本的な使い方
import faiss
import numpy as np
# サンプルデータを作成 (1000 ベクトル、128 次元)
d = 128
nb = 1000
vectors = np.random.random((nb, d)).astype('float32')
# インデックスを作成
index = faiss.IndexFlatL2(d) # L2 距離
index.add(vectors) # ベクトルを追加
# 検索
k = 5 # 最も近い 5 つの近傍を見つける
query = np.random.random((1, d)).astype('float32')
distances, indices = index.search(query, k)
print(f"Nearest neighbors: {indices}")
print(f"Distances: {distances}")
インデックスの種類
1. Flat (厳密検索)
# L2 (ユークリッド) 距離
index = faiss.IndexFlatL2(d)
# 内積 (正規化されていればコサイン類似度)
index = faiss.IndexFlatIP(d)
# 最も遅いが、最も正確
2. IVF (inverted file) - 高速近似
# 量子化器を作成
quantizer = faiss.IndexFlatL2(d)
# 100 クラスターを持つ IVF インデックス
nlist = 100
index = faiss.IndexIVFFlat(quantizer, d, nlist)
# データで学習
index.train(vectors)
# ベクトルを追加
index.add(vectors)
# 検索 (nprobe = 検索するクラスター数)
index.nprobe = 10
distances, indices = index.search(query, k)
3. HNSW (Hierarchical NSW) - 最高の品質/速度
# HNSW インデックス
M = 32 # レイヤーあたりの接続数
index = faiss.IndexHNSWFlat(d, M)
# 学習は不要
index.add(vectors)
# 検索
distances, indices = index.search(query, k)
4. Product Quantization - メモリ効率的
# PQ はメモリを 16-32 倍削減
m = 8 # サブ量子化器の数
nbits = 8
index = faiss.IndexPQ(d, m, nbits)
# 学習と追加
index.train(vectors)
index.add(vectors)
保存と読み込み
# インデックスを保存
faiss.write_index(index, "large.index")
# インデックスを読み込み
index = faiss.read_index("large.index")
# 引き続き使用
distances, indices = index.search(query, k)
GPU アクセラレーション
# シングル GPU
res = faiss.StandardGpuResources()
index_cpu = faiss.IndexFlatL2(d)
index_gpu = faiss.index_cpu_to_gpu(res, 0, index_cpu) # GPU 0
# マルチ GPU
index_gpu = faiss.index_cpu_to_all_gpus(index_cpu)
# CPU より 10-100 倍高速
LangChain 連携
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings
# FAISS ベクトルストアを作成
vectorstore = FAISS.from_documents(docs, OpenAIEmbeddings())
# 保存
vectorstore.save_local("faiss_index")
# 読み込み
vectorstore = FAISS.load_local(
"faiss_index",
OpenAIEmbeddings(),
allow_dangerous_deserialization=True
)
# 検索
results = vectorstore.similarity_search("query", k=5)
LlamaIndex 連携
from llama_index.vector_stores.faiss import FaissVectorStore
import faiss
# FAISS インデックスを作成
d = 1536
faiss_index = faiss.IndexFlatL2(d)
vector_store = FaissVectorStore(faiss_index=faiss_index)
ベストプラクティス
- 適切なインデックスタイプを選択する - 1万未満なら Flat、1万~100万なら IVF、品質重視なら HNSW
- コサイン類似度のために正規化する - 正規化されたベクトルで IndexFlatIP を使用する
- 大規模データセットには GPU を使用する - 10~100倍高速です
- 学習済みインデックスを保存する - 学習はコストがかかります
- nprobe/ef_search を調整する - 速度と精度のバランスを取る
- メモリを監視する - 大規模データセットには PQ を使用する
- クエリをバッチ処理する - GPU の利用率を向上させる
パフォーマンス
| インデックスタイプ | 構築時間 | 検索時間 | メモリ | 精度 |
|---|---|---|---|---|
| Flat | 高速 | 低速 | 高 | 100% |
| IVF | 中 | 高速 | 中 | 95-99% |
| HNSW | 低速 | 最速 | 高 | 99% |
| PQ | 中 | 高速 | 低 | 90-95% |
リソース
- GitHub: https://github.com/facebookresearch/faiss ⭐ 31,700+
- Wiki: https://github.com/facebookresearch/faiss/wiki
- License: MIT
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
- Choose right index type - Flat for <10K, IVF for 10K-1M, HNSW for quality
- Normalize for cosine - Use IndexFlatIP with normalized vectors
- Use GPU for large datasets - 10-100× faster
- Save trained indices - Training is expensive
- Tune nprobe/ef_search - Balance speed/accuracy
- Monitor memory - PQ for large datasets
- 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
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (5,048 bytes)
- 📎 references/index_types.md (6,181 bytes)