Personal Knowledge Base Q&A Agent
A local-first RAG system that indexes personal documents and enables querying them via an MCP tool, keeping data private with local embeddings.
README
Personal Knowledge Base Q&A Agent (RAG + MCP)
A local-first, lightweight Retrieval-Augmented Generation (RAG) system that indexes and queries your personal documents (PDFs, markdown, text files) and exposes this capability as a Model Context Protocol (MCP) server.
Architecture Overview
- Ingestion: Documents are loaded, split into smaller overlapping segments (800 characters with 150-character overlap), and converted into vector embeddings.
- Local Vector Database: ChromaDB is used to store document chunks and run semantic queries.
- Local ONNX Embeddings: All text embeddings are computed locally using an ONNX-optimized version of
all-MiniLM-L6-v2. This requires no API keys, runs fast on CPUs, and maintains privacy. - Answer Generation: Context is retrieved and sent to OpenAI's
gpt-4o-miniusing strict guidelines (temperature0.0, answer-only-from-context) to prevent hallucination. - MCP Server Integration: Exposes the Q&A logic as a tool (
query_knowledge_base) that LLM clients can execute directly.
Directory Structure
e:\Personal_knowledge_base
├── documents/ # Drop your PDFs, TXT, or MD files here
├── src/
│ ├── config.py # Environment variable configuration
│ ├── document_loader.py # Reads text, markdown, and PDF files
│ ├── chunker.py # Splits documents recursively
│ ├── vector_store.py # Local ChromaDB & ONNX embeddings
│ ├── rag_engine.py # Retrieval & OpenAI prompt generation
│ └── mcp_server.py # FastMCP Server (exposes query tool)
├── query.py # CLI client for ingestion/testing
├── requirements.txt # Dependencies list
├── .env # Config (containing API key)
├── Dockerfile # Container config (pre-caches ONNX)
└── README.md # This documentation file
Prerequisites
- Python 3.10 or higher.
- An OpenAI API Key (
sk-...).
Installation & Setup
-
Clone/Navigate to the project directory:
cd e:\Personal_knowledge_base -
Create a virtual environment and activate it:
python -m venv .venv # On Windows: .venv\Scripts\activate # On macOS/Linux: source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt -
Verify your
.envfile: Ensure you have your OpenAI API key in the.envfile in the project root:OPENAI_API_KEY=your_openai_api_key_here CHROMA_DB_PATH=./chroma_db DOCUMENTS_DIR=./documents OPENAI_MODEL=gpt-4o-mini
CLI Usage
1. Ingest Documents
Place your text, markdown, or PDF files into the documents/ directory. Then, run the ingestion pipeline:
python query.py --ingest
This loads files from documents/, chunks them, generates embeddings, and saves them locally in ./chroma_db.
2. Query the Knowledge Base
Ask questions about your documents:
python query.py "What is the database password for staging?"
3. Clear the Database
If you want to remove all indexed files and start fresh:
python query.py --clear
Model Context Protocol (MCP) Server Setup
You can expose this tool directly to Claude Desktop, allowing the desktop LLM to search your private files whenever you ask a relevant question.
Configuration for Claude Desktop
Add the server definition to your Claude Desktop configuration file.
- Windows Path:
%APPDATA%\Claude\claude_desktop_config.json - macOS Path:
~/Library/Application Support/Claude/claude_desktop_config.json
Add the following to the mcpServers object (ensure you update the paths to match your absolute path, replacing backslashes with double backslashes \\ or forward slashes /):
{
"mcpServers": {
"personal-knowledge-base": {
"command": "python",
"args": [
"E:/Personal_knowledge_base/src/mcp_server.py"
],
"env": {
"OPENAI_API_KEY": "your_actual_openai_key_here"
}
}
}
}
Restart Claude Desktop, and you will see the plug icon indicating that the Personal Knowledge Base Server tool query_knowledge_base is available!
Docker Integration
You can build and run the MCP server inside a Docker container. The Dockerfile is configured to pre-cache the ONNX model files during the build phase.
-
Build the image:
docker build -t personal-knowledge-base . -
Run the container (running a shell or exposing it if running HTTP transport): Since MCP default is stdio, Docker runs it on stdio. To use it with Claude Desktop, configure the desktop configuration to launch the container:
{ "mcpServers": { "personal-knowledge-base-docker": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "OPENAI_API_KEY=your_actual_openai_key_here", "-v", "E:/Personal_knowledge_base/documents:/app/documents", "-v", "E:/Personal_knowledge_base/chroma_db:/app/chroma_db", "personal-knowledge-base" ] } } }
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.