Skip to main content

Ring-Fenced RAG

Self-hosted, zero-trust RAG with role-based access control enforced at the database level.

CI CodeQL Dependabot Python License PyPI

What is Ring-Fenced RAG?

Ring-Fenced RAG (RFR) is a self-hosted document Q&A system where access control is enforced at the database level — not the application layer. Every document chunk is tagged with role metadata at ingestion time. When a user queries the system, the vector database mathematically refuses to return chunks the user isn't authorized to see.

No cloud APIs. No data egress. No "we promise to filter after retrieval."

pip install ring-fenced-rag
rfr init
rfr up
rfr ingest ./docs/ --role senior_engineer
rfr query "How do I restart Nginx?"

Key Features

  • 🔒 Ring-Fenced Retrieval — PostgreSQL JSONB @> operator enforces role-based access at query time. Unauthorized queries return zero results.
  • 🏠 100% Local — Embedding (sentence-transformers), storage (pgvector), and generation (Ollama/vLLM/LM Studio) all run on your hardware. Zero data egress by default.
  • ♻️ Idempotent Ingestion — LangChain SQLRecordManager tracks content hashes. Ingest the same doc 10 times, get exactly 1 copy.
  • 🔌 Pluggable LLMs — Supports vLLM, Ollama, LM Studio, and any OpenAI-compatible API. Configure in ~/.rfr/config.toml.
  • 🎛️ Four Interfaces — CLI, Web UI, TUI, REST API.
  • 🐧 AMD ROCm Support — Works on AMD GPUs via ROCm vLLM or Ollama.

Quick Start

Prerequisites

  • Python 3.13+
  • Docker & Docker Compose (for production mode)
  • Or: just Python (for standalone mode with SQLite)

Installation

pip install ring-fenced-rag

Initialize

cd my-project
rfr init

This creates:

  • ~/.rfr/config.toml — your configuration
  • docker-compose.yml — ready to run

Start the Stack

# Production mode (Docker — recommended)
rfr up

# Standalone mode (no Docker)  
rfr standalone

Access the Web UI

Once the stack is running, open http://localhost:8080 in your browser.

The Web UI provides:

  • Dashboard — Ask questions against your documents
  • Documents — Browse and manage indexed documents
  • Ingest — Upload documents with role metadata
  • Settings — Manage API keys and view system health

The Web UI is a React + TypeScript SPA served by the FastAPI backend. To develop it locally: cd src/rfr/web && npm install && npm run dev (runs on port 5173 with API proxy).

Ingest Documents

rfr ingest ./manuals/ --role senior_engineer
rfr ingest ./onboarding/ --role junior_engineer

Ask Questions

rfr query "How do I restart the Nginx server?"

CLI Reference

All CLI commands at a glance:

Command Description
rfr init Generate config + docker-compose.yml
rfr up [-d] Start Docker services
rfr down Stop Docker services
rfr status Show component health
rfr version Show version, git commit, platform
rfr --version Show version (short)
rfr standalone Run in standalone mode (SQLite, no Docker)
rfr config show Print current config
rfr config set <k> <v> Update config value
rfr ingest <path> Ingest documents from file/directory
rfr query <question> Ask a question against your docs
rfr keys create/list/revoke Manage API keys
rfr docs list/delete Browse and delete indexed documents
rfr logs [service] Tail Docker service logs
rfr tui Launch terminal UI (Textual)

Configuration

Edit ~/.rfr/config.toml or use RFR_* environment variables:

[llm]
provider = "ollama"        # vllm, ollama, lm-studio, openai
base_url = "http://localhost:11434/v1"
model = "llama3.2:3b"

[embedding]
model = "all-MiniLM-L6-v2"  # 384-dim, CPU-friendly

[ingestion]
chunk_size = 512
default_role = "user"

Architecture

User (CLI/Web/TUI) → FastAPI API → LCEL Pipeline
                                        │
                              ┌─────────▼──────────┐
                              │  pgvector (PostgreSQL)
                              │  JSONB @> role filter
                              │  HNSW vector index
                              └─────────┬──────────┘
                                        │
                              ┌─────────▼──────────┐
                              │  LLM (Ollama/vLLM)  │
                              │  Zero egress        │
                              └────────────────────┘

Development

# Clone
git clone https://github.com/iknowkungfubar/ring-fenced-rag.git
cd ring-fenced-rag

# Install with dev dependencies
uv sync --group dev

# Run tests
uv run pytest tests/ -q --tb=short --cov=src/rfr

# Format and lint
uv run ruff format src/ tests/
uv run ruff check src/ tests/

# Install TUI dependencies (optional)
uv pip install textual

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for detailed guidelines on our development process, coding standards, PR workflow, and code of conduct.

License

MIT

Download files

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

Source Distribution

ring_fenced_rag-1.0.0.tar.gz (417.2 kB view details)

Uploaded Source

Built Distribution

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

ring_fenced_rag-1.0.0-py3-none-any.whl (158.9 kB view details)

Uploaded Python 3

File details

Details for the file ring_fenced_rag-1.0.0.tar.gz.

File metadata

  • Download URL: ring_fenced_rag-1.0.0.tar.gz
  • Upload date:
  • Size: 417.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for ring_fenced_rag-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f05c09a87768f80dc86768d735711b660d42fac236724b1b59f2b97fc1632290
MD5 afa6b78c26fdb03c240ff996249a9df2
BLAKE2b-256 7051439e1b36cd45cb8b380164c5780504fb355a204a7f5339cc38d8b7d6ed1a

See more details on using hashes here.

File details

Details for the file ring_fenced_rag-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ring_fenced_rag-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 158.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for ring_fenced_rag-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a2063e974c5f2e0b8f5e0d8b0cdc4777b0c2ef132fbff04dfb3c8e20c1086d9
MD5 11d737b81c04ee536cfd37fd63e2180c
BLAKE2b-256 a2a989401470f6fee93bce72e44a292261d7331515bcf392b00a2feacddc73d2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page