Skip to main content

Multi-knowledge-base RAG system with MCP integration

Project description

Ragnest

PyPI Python CI License: MIT

Multi-knowledge-base RAG system with MCP integration for Claude Code.

Create multiple knowledge bases, each with its own embedding model, chunk settings, and vector backend. Search them from Claude Code via 27 MCP tools.

Installation

pip install ragnest

Prerequisites

  • Python 3.12+
  • PostgreSQL with pgvector extension
  • Ollama for local embeddings

Quick Start

1. Start PostgreSQL with pgvector

# Using the included Docker Compose
git clone https://github.com/november-pain/ragnest.git
cd ragnest
docker compose up -d

Or use any PostgreSQL 15+ instance with pgvector installed.

2. Configure

cp config.example.yaml config.yaml

Edit config.yaml:

database:
  host: localhost
  port: 5433
  name: ragnest

ollama:
  base_url: http://localhost:11434

Create .env with database credentials:

RAGNEST_DATABASE__USER=ragnest
RAGNEST_DATABASE__PASSWORD=yourpassword

3. Install Ollama and pull an embedding model

brew install ollama && brew services start ollama
ollama pull bge-m3

4. Add to Claude Code

claude mcp add ragnest -- uvx ragnest

Database and schema are auto-initialized when the MCP server starts.

Usage

Initialize a knowledge base from a folder

init_kb("my_docs", "/path/to/docs", "bge-m3", file_patterns="*.py,*.md")

Creates the KB, sets a watch path with file filtering, and queues files for embedding.

Run the worker

ragnest-worker --scan --kb my_docs

The worker processes the queue: reads files, chunks text, generates embeddings via Ollama, and stores vectors in PostgreSQL.

Search

search_kb("my_docs", "how does authentication work", top_k=5)
search_all_kbs("deployment process", top_k_per_kb=3)

Returns ranked results with source filenames, scores, and text chunks.

Architecture

Claude Code ──MCP──▶ MCP Server (27 tools)
                         │
              ┌──────────┼──────────┐
              ▼                     ▼
         SQLite                Vector Backend
       (local state)           (pgvector)
              │                     ▲
              └──────▶ Worker ──────┘
                         │
                      Ollama
                    (embeddings)

Two-layer storage:

Layer Engine Stores Purpose
State SQLite KBs, documents, batches, queue, watch paths Local, zero-config, works offline
Vectors PostgreSQL + pgvector Chunks with embeddings + inline metadata Portable, queryable by external systems

MCP Tools

Category Tools
Search search_kb, search_all_kbs, get_similar_documents
KB Management list_kbs, create_kb, update_kb, delete_kb, init_kb
Watch Paths add_watch_path, remove_watch_path, list_watch_paths, pause_watch_path, resume_watch_path
Ingestion add_file, add_directory, add_text
Batches batch_status, list_batches, undo_batch, worker_status, trigger_scan
Documents list_documents, delete_document
System db_status, list_models, system_info
Export export_knowledge_base

Features

  • Multiple knowledge bases — each with its own embedding model, dimensions, and chunk settings
  • Per-KB backend routing — route different KBs to different PostgreSQL databases
  • External KB support — connect to remote vector stores in read-only or read-write mode
  • Watch paths with file filtering — glob patterns like *.py,*.md to control what gets indexed
  • Batch tracking — view progress, retry failures, undo entire batches
  • Resilient worker — per-file commits, SIGINT/SIGTERM handling, resume on restart
  • Content deduplication — SHA-256 hashing skips unchanged files
  • Cross-KB search — search all knowledge bases in one call
  • Export — Parquet or JSON with model metadata sidecar

Configuration

Basic

# config.yaml
database:
  host: localhost
  port: 5433
  name: ragnest

ollama:
  base_url: http://localhost:11434

defaults:
  chunk_size: 1000
  chunk_overlap: 200
# .env
RAGNEST_DATABASE__USER=ragnest
RAGNEST_DATABASE__PASSWORD=yourpassword

Multiple backends

databases:
  local:
    host: localhost
    port: 5433
    name: ragnest
  cloud:
    host: xyz.supabase.co
    port: 5432
    name: postgres

Then specify backend="cloud" when creating a KB.

Worker

ragnest-worker --scan                 # Scan watch paths + process queue
ragnest-worker --scan --kb my_docs    # Specific KB only
ragnest-worker --retry                # Retry failed files
ragnest-worker --scan --dry-run       # Preview what would be queued

Deploy files for launchd and systemd are included for scheduled runs.

Development

git clone https://github.com/november-pain/ragnest.git
cd ragnest
pip install -e ".[dev]"

make lint             # ruff check + format
make typecheck        # mypy + basedpyright (strict)
make test             # pytest (113 tests)

Project Structure

src/ragnest/
├── app.py                  # Application container + wiring
├── config.py               # Pydantic Settings + YAML
├── exceptions.py           # Exception hierarchy
├── models/                 # Pydantic domain + DB row models
├── db/
│   ├── backends/           # PostgreSQL, SQLite implementations
│   ├── repositories/       # 6 data access repositories
│   ├── schema.py           # Vector DDL + index management
│   └── sqlite_schema.py    # Local state DDL
├── services/               # Business logic (7 services)
├── mcp/
│   ├── server.py           # FastMCP app factory
│   └── tools/              # 8 tool modules (27 tools)
└── cli/                    # Worker + DB setup entrypoints

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ragnest-0.2.0.tar.gz (57.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ragnest-0.2.0-py3-none-any.whl (68.9 kB view details)

Uploaded Python 3

File details

Details for the file ragnest-0.2.0.tar.gz.

File metadata

  • Download URL: ragnest-0.2.0.tar.gz
  • Upload date:
  • Size: 57.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ragnest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fca4597bba8306d1f743fdbaa6ad3851a976540f58f0410287cc8f65cc80ad35
MD5 97b9bd833e38cde415346b24520b8c8c
BLAKE2b-256 88fb750d73e4e2f37d992a1f1372caa4bafabbb2b6397c08e71e96a1149b977b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ragnest-0.2.0.tar.gz:

Publisher: release.yml on november-pain/ragnest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ragnest-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ragnest-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 68.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ragnest-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d638bb7e5dd89d165840921fe2ebc24b425082b7c8bcdbf838d91719e1f22e
MD5 7a4a440e431010939b6cc5096350586e
BLAKE2b-256 3c5ea463f5f1f33f6432fc0113fb334b5bebea254547fb7bc167ed663c266cd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ragnest-0.2.0-py3-none-any.whl:

Publisher: release.yml on november-pain/ragnest

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page