This Python RAG Server with DuckDB provides a powerful document processing and retrieval-augmented generation solution. It offers both a web interface and JSON API for uploading documents, processing them into chunks with embeddings, and storing them in DuckDB for efficient semantic search.
Build the Docker image:
For standard build (with GPU support):
docker build -t rag-duckdb-server .
For CPU-only build (recommended for local development):
docker build --build-arg USE_CPU_ONLY=true -t rag-duckdb-server-cpu .
Run the Docker container:
Standard build:
docker run -p 8000:8000 \
-v "$(pwd)/uploads:/app/uploads" \
-v "$(pwd)/data:/app/data" \
--name rag-server \
rag-duckdb-server
CPU-only build:
docker run -p 8000:8000 \
-v "$(pwd)/uploads:/app/uploads" \
-v "$(pwd)/data:/app/data" \
--name rag-server-cpu \
rag-duckdb-server-cpu
Note: Windows PowerShell users should use ${pwd}
instead of $(pwd)
.
Access the application: Open your browser and navigate to http://localhost:8000
Upload Files: Use the web interface to upload one or more supported files.
Upload Directory: Alternatively, upload entire directories with file extension filtering.
Process Files: Click "Start Processing" to:
Search Documents: Use the semantic search bar to find relevant content across all indexed chunks.
Use API: Interact programmatically via the API endpoints.
.txt
- Plain text files.md
- Markdown files.pdf
- PDF documents.py
- Python.js
, .ts
, .jsx
, .tsx
- JavaScript/TypeScript.java
- Java.c
, .cpp
, .cc
, .cxx
- C/C++.cs
- C#.html
, .htm
- HTML.css
, .scss
, .sass
- CSS and preprocessors.json
- JSON.yaml
, .yml
- YAML.xml
- XML.sql
- SQL.ini
, .toml
- Configuration filesGET /
- Main web interfacePOST /upload-files/
- Upload individual filesPOST /upload-directory/
- Upload directory with extension filteringPOST /process-files/
- Process uploaded filesPOST /search/
- Search interfacePOST /delete-file/
- Delete uploaded filePOST /api/search
- Programmatic search endpointGET /api/stats
- Get collection statisticsGET /health
- Health check endpointquery
(required): Search query stringtop_k
(optional, default: 5): Number of results to return (1-50)search_type
(optional, default: "hybrid"): "hybrid", "semantic", or "keyword"use_reranker
(optional, default: true): Enable/disable result rerankingexpand_query
(optional, default: false): Enable/disable query expansionDocker Build Fails: Try the CPU-only build:
docker build --build-arg USE_CPU_ONLY=true -t rag-duckdb-server-cpu .
Memory Issues: For large document collections:
Database Issues: If you encounter database errors, delete the data/
directory to start fresh.
Monitor service status with:
curl http://localhost:8000/health
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "rag-duckdb" '{"command":"python","args":["-m","rag_duckdb"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"rag-duckdb": {
"command": "python",
"args": [
"-m",
"rag_duckdb"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"rag-duckdb": {
"command": "python",
"args": [
"-m",
"rag_duckdb"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect