A Model Context Protocol (MCP) server that provides local vector database functionality using FAISS for Retrieval-Augmented Generation (RAG) applications. - Local Vector Storage: Uses FAISS for efficient similarity search without external dependencies - Document Ingestion: Automatically chunks and embeds documents for storage - Semantic Search: Query documents using natural language with sentence
Add this skill
npx mdskills install nonatofabio/local-faiss-mcpWell-documented vector database with comprehensive tooling, re-ranking, and flexible embedding support
1# Local FAISS MCP Server23<!-- mcp-name: io.github.nonatofabio/local-faiss-mcp -->45[](https://opensource.org/licenses/MIT)6[](https://www.python.org/downloads/)7[](https://github.com/nonatofabio/local_faiss_mcp/actions)8[](https://badge.fury.io/py/local-faiss-mcp)910A Model Context Protocol (MCP) server that provides local vector database functionality using FAISS for Retrieval-Augmented Generation (RAG) applications.11121314## Features1516### Core Capabilities17- **Local Vector Storage**: Uses FAISS for efficient similarity search without external dependencies18- **Document Ingestion**: Automatically chunks and embeds documents for storage19- **Semantic Search**: Query documents using natural language with sentence embeddings20- **Persistent Storage**: Indexes and metadata are saved to disk21- **MCP Compatible**: Works with any MCP-compatible AI agent or client2223### v0.2.0 Highlights24- **CLI Tool**: `local-faiss` command for standalone indexing and search25- **Document Formats**: Native PDF/TXT/MD support, DOCX/HTML/EPUB with pandoc26- **Re-ranking**: Two-stage retrieve and rerank for better results27- **Custom Embeddings**: Choose any Hugging Face embedding model28- **MCP Prompts**: Built-in prompts for answer extraction and summarization2930## Quickstart3132```bash33# Install34pip install local-faiss-mcp3536# Index documents37local-faiss index document.pdf3839# Search40local-faiss search "What is this document about?"41```4243Or use with Claude Code - configure MCP client (see [Configuration](#configuration-with-mcp-clients)) and try:4445```46Use the ingest_document tool with: ./path/to/document.pdf47Then use query_rag_store to search for: "How does FAISS perform similarity search?"48```4950Claude will retrieve relevant document chunks from your vector store and use them to answer your question.5152## Installation5354⚡️ **Upgrading?** Run `pip install --upgrade local-faiss-mcp`5556### From PyPI (Recommended)5758```bash59pip install local-faiss-mcp60```6162### Optional: Extended Format Support6364For DOCX, HTML, EPUB, and 40+ additional formats, install pandoc:6566```bash67# macOS68brew install pandoc6970# Linux71sudo apt install pandoc7273# Or download from: https://pandoc.org/installing.html74```7576**Note**: PDF, TXT, and MD work without pandoc.7778### From Source7980```bash81git clone https://github.com/nonatofabio/local_faiss_mcp.git82cd local_faiss_mcp83pip install -e .84```8586## Usage8788### Running the Server8990After installation, you can run the server in three ways:9192**1. Using the installed command (easiest):**93```bash94local-faiss-mcp --index-dir /path/to/index/directory95```9697**2. As a Python module:**98```bash99python -m local_faiss_mcp --index-dir /path/to/index/directory100```101102**3. For development/testing:**103```bash104python local_faiss_mcp/server.py --index-dir /path/to/index/directory105```106107**Command-line Arguments:**108- `--index-dir`: Directory to store FAISS index and metadata files (default: current directory)109- `--embed`: Hugging Face embedding model name (default: `all-MiniLM-L6-v2`)110- `--rerank`: Enable re-ranking with specified cross-encoder model (default: `BAAI/bge-reranker-base`)111112**Using a Custom Embedding Model:**113```bash114# Use a larger, more accurate model115local-faiss-mcp --index-dir ./.vector_store --embed all-mpnet-base-v2116117# Use a multilingual model118local-faiss-mcp --index-dir ./.vector_store --embed paraphrase-multilingual-MiniLM-L12-v2119120# Use any Hugging Face sentence-transformers model121local-faiss-mcp --index-dir ./.vector_store --embed sentence-transformers/model-name122```123124**Using Re-ranking for Better Results:**125126Re-ranking uses a cross-encoder model to reorder FAISS results for improved relevance. This two-stage "retrieve and rerank" approach is common in production search systems.127128```bash129# Enable re-ranking with default model (BAAI/bge-reranker-base)130local-faiss-mcp --index-dir ./.vector_store --rerank131132# Use a specific re-ranking model133local-faiss-mcp --index-dir ./.vector_store --rerank cross-encoder/ms-marco-MiniLM-L-6-v2134135# Combine custom embedding and re-ranking136local-faiss-mcp --index-dir ./.vector_store --embed all-mpnet-base-v2 --rerank BAAI/bge-reranker-base137```138139**How Re-ranking Works:**1401. FAISS retrieves top candidates (10x more than requested)1412. Cross-encoder scores each candidate against the query1423. Results are re-sorted by relevance score1434. Top-k most relevant results are returned144145Popular re-ranking models:146- `BAAI/bge-reranker-base` - Good balance (default)147- `cross-encoder/ms-marco-MiniLM-L-6-v2` - Fast and efficient148- `cross-encoder/ms-marco-TinyBERT-L-2-v2` - Very fast, smaller model149150The server will:151- Create the index directory if it doesn't exist152- Load existing FAISS index from `{index-dir}/faiss.index` (or create a new one)153- Load document metadata from `{index-dir}/metadata.json` (or create new)154- Listen for MCP tool calls via stdin/stdout155156### Available Tools157158The server provides two tools for document management:159160#### 1. ingest_document161162Ingest a document into the vector store.163164**Parameters:**165- `document` (required): Text content OR file path to ingest166- `source` (optional): Identifier for the document source (default: "unknown")167168**Auto-detection**: If `document` looks like a file path, it will be automatically parsed.169170**Supported formats:**171- Native: TXT, MD, PDF172- With pandoc: DOCX, ODT, HTML, RTF, EPUB, and 40+ formats173174**Examples:**175```json176{177 "document": "FAISS is a library for efficient similarity search...",178 "source": "faiss_docs.txt"179}180```181182```json183{184 "document": "./documents/research_paper.pdf"185}186```187188#### 2. query_rag_store189190Query the vector store for relevant document chunks.191192**Parameters:**193- `query` (required): The search query text194- `top_k` (optional): Number of results to return (default: 3)195196**Example:**197```json198{199 "query": "How does FAISS perform similarity search?",200 "top_k": 5201}202```203204### Available Prompts205206The server provides MCP prompts to help extract answers and summarize information from retrieved documents:207208#### 1. extract-answer209210Extract the most relevant answer from retrieved document chunks with proper citations.211212**Arguments:**213- `query` (required): The original user query or question214- `chunks` (required): Retrieved document chunks as JSON array with fields: `text`, `source`, `distance`215216**Use Case:** After querying the RAG store, use this prompt to get a well-formatted answer that cites sources and explains relevance.217218**Example workflow in Claude:**2191. Use `query_rag_store` tool to retrieve relevant chunks2202. Use `extract-answer` prompt with the query and results2213. Get a comprehensive answer with citations222223#### 2. summarize-documents224225Create a focused summary from multiple document chunks.226227**Arguments:**228- `topic` (required): The topic or theme to summarize229- `chunks` (required): Document chunks to summarize as JSON array230- `max_length` (optional): Maximum summary length in words (default: 200)231232**Use Case:** Synthesize information from multiple retrieved documents into a concise summary.233234**Example Usage:**235236In Claude Code, after retrieving documents with `query_rag_store`, you can use the prompts like:237238```239Use the extract-answer prompt with:240- query: "What is FAISS?"241- chunks: [the JSON results from query_rag_store]242```243244The prompts will guide the LLM to provide structured, citation-backed answers based on your vector store data.245246## Command-Line Interface247248The `local-faiss` CLI provides standalone document indexing and search capabilities.249250### Index Command251252Index documents from the command line:253254```bash255# Index single file256local-faiss index document.pdf257258# Index multiple files259local-faiss index doc1.pdf doc2.txt doc3.md260261# Index all files in folder262local-faiss index documents/263264# Index recursively265local-faiss index -r documents/266267# Index with glob pattern268local-faiss index "docs/**/*.pdf"269```270271**Configuration**: The CLI automatically uses MCP configuration from:2721. `./.mcp.json` (local/project-specific)2732. `~/.claude/.mcp.json` (Claude Code config)2743. `~/.mcp.json` (fallback)275276If no config exists, creates `./.mcp.json` with default settings (`./.vector_store`).277278**Supported formats:**279- **Native**: TXT, MD, PDF (always available)280- **With pandoc**: DOCX, ODT, HTML, RTF, EPUB, etc.281 - Install: `brew install pandoc` (macOS) or `apt install pandoc` (Linux)282283### Search Command284285Search the indexed documents:286287```bash288# Basic search289local-faiss search "What is FAISS?"290291# Get more results292local-faiss search -k 5 "similarity search algorithms"293```294295Results show:296- Source file path297- FAISS distance score298- Re-rank score (if enabled in MCP config)299- Text preview (first 300 characters)300301### CLI Features302303- ✅ **Incremental indexing**: Adds to existing index, doesn't overwrite304- ✅ **Progress output**: Shows indexing progress for each file305- ✅ **Shared config**: Uses same settings as MCP server306- ✅ **Auto-detection**: Supports glob patterns and recursive folders307- ✅ **Format support**: Handles PDF, TXT, MD natively; DOCX+ with pandoc308309## Configuration with MCP Clients310311### Claude Code312313Add this server to your Claude Code MCP configuration (`.mcp.json`):314315**User-wide configuration** (`~/.claude/.mcp.json`):316```json317{318 "mcpServers": {319 "local-faiss-mcp": {320 "command": "local-faiss-mcp"321 }322 }323}324```325326**With custom index directory**:327```json328{329 "mcpServers": {330 "local-faiss-mcp": {331 "command": "local-faiss-mcp",332 "args": [333 "--index-dir",334 "/home/user/vector_indexes/my_project"335 ]336 }337 }338}339```340341**With custom embedding model**:342```json343{344 "mcpServers": {345 "local-faiss-mcp": {346 "command": "local-faiss-mcp",347 "args": [348 "--index-dir",349 "./.vector_store",350 "--embed",351 "all-mpnet-base-v2"352 ]353 }354 }355}356```357358**With re-ranking enabled**:359```json360{361 "mcpServers": {362 "local-faiss-mcp": {363 "command": "local-faiss-mcp",364 "args": [365 "--index-dir",366 "./.vector_store",367 "--rerank"368 ]369 }370 }371}372```373374**Full configuration with embedding and re-ranking**:375```json376{377 "mcpServers": {378 "local-faiss-mcp": {379 "command": "local-faiss-mcp",380 "args": [381 "--index-dir",382 "./.vector_store",383 "--embed",384 "all-mpnet-base-v2",385 "--rerank",386 "BAAI/bge-reranker-base"387 ]388 }389 }390}391```392393**Project-specific configuration** (`./.mcp.json` in your project):394```json395{396 "mcpServers": {397 "local-faiss-mcp": {398 "command": "local-faiss-mcp",399 "args": [400 "--index-dir",401 "./.vector_store"402 ]403 }404 }405}406```407408**Alternative: Using Python module** (if the command isn't in PATH):409```json410{411 "mcpServers": {412 "local-faiss-mcp": {413 "command": "python",414 "args": ["-m", "local_faiss_mcp", "--index-dir", "./.vector_store"]415 }416 }417}418```419420### Claude Desktop421422Add this server to your Claude Desktop configuration:423424```json425{426 "mcpServers": {427 "local-faiss-mcp": {428 "command": "local-faiss-mcp",429 "args": ["--index-dir", "/path/to/index/directory"]430 }431 }432}433```434435## Architecture436437- **Embedding Model**: Configurable via `--embed` flag (default: `all-MiniLM-L6-v2` with 384 dimensions)438 - Supports any Hugging Face sentence-transformers model439 - Automatically detects embedding dimensions440 - Model choice persisted with the index441- **Index Type**: FAISS IndexFlatL2 for exact L2 distance search442- **Chunking**: Documents are split into ~500 word chunks with 50 word overlap443- **Storage**: Index saved as `faiss.index`, metadata saved as `metadata.json`444445### Choosing an Embedding Model446447Different models offer different trade-offs:448449| Model | Dimensions | Speed | Quality | Use Case |450|-------|-----------|-------|---------|----------|451| `all-MiniLM-L6-v2` | 384 | Fast | Good | Default, balanced performance |452| `all-mpnet-base-v2` | 768 | Medium | Better | Higher quality embeddings |453| `paraphrase-multilingual-MiniLM-L12-v2` | 384 | Fast | Good | Multilingual support |454| `all-MiniLM-L12-v2` | 384 | Medium | Better | Better quality at same size |455456**Important:** Once you create an index with a specific model, you must use the same model for subsequent runs. The server will detect dimension mismatches and warn you.457458## Development459460### Standalone Test461462Test the FAISS vector store functionality without MCP infrastructure:463464```bash465source venv/bin/activate466python test_standalone.py467```468469This test:470- Initializes the vector store471- Ingests sample documents472- Performs semantic search queries473- Tests persistence and reload474- Cleans up test files475476### Unit Tests477478Run the complete test suite:479```bash480pytest tests/ -v481```482483Run specific test files:484```bash485# Test embedding model functionality486pytest tests/test_embedding_models.py -v487488# Run standalone integration test489python tests/test_standalone.py490```491492The test suite includes:493- **test_embedding_models.py**: Comprehensive tests for custom embedding models, dimension detection, and compatibility494- **test_standalone.py**: End-to-end integration test without MCP infrastructure495496## License497498MIT499
Full transparency — inspect the skill content before installing.