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

Metadata

Release files for ring-fenced-rag 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ring-fenced-rag 1.0.0
File Size Uploaded Provenance Actions
ring_fenced_rag-1.0.0.tar.gz 417.2 kB Without provenance Details for ring_fenced_rag-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ring-fenced-rag 1.0.0
File Interpreter ABI Platform Actions
ring_fenced_rag-1.0.0-py3-none-any.whl Python 3 none any Details for ring_fenced_rag-1.0.0-py3-none-any.whl

Total release size: 576.1 kB

Release files / ring_fenced_rag-1.0.0.tar.gz

Download URL ring_fenced_rag-1.0.0.tar.gz
Size 417.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f05c09a87768f80dc86768d735711b660d42fac236724b1b59f2b97fc1632290
BLAKE2b-256 checksum
How to use checksums
7051439e1b36cd45cb8b380164c5780504fb355a204a7f5339cc38d8b7d6ed1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / ring_fenced_rag-1.0.0-py3-none-any.whl

Download URL ring_fenced_rag-1.0.0-py3-none-any.whl
Size 158.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a2063e974c5f2e0b8f5e0d8b0cdc4777b0c2ef132fbff04dfb3c8e20c1086d9
BLAKE2b-256 checksum
How to use checksums
a2a989401470f6fee93bce72e44a292261d7331515bcf392b00a2feacddc73d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.13.14

Security for ring-fenced-rag 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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