Enterprise-grade, local-first RAG for Python
Project description
RagZen
RagZen is a local-first, permission-aware RAG framework for Python. It provides durable ingestion, hybrid or graph-assisted retrieval, pluggable providers, grounded generation, a CLI, and an optional FastAPI server.
RagZen 0.2 is an alpha release. Its public API is usable, but production users should pin the exact version and validate their own retrieval and security policies.
Features
- Persistent local mode: SQLite document registry, SQLite vectors, and durable BM25.
- Retrieval modes:
dense,sparse,hybrid,graph, andhybrid_graph. - Vector backends: zero-config SQLite, in-memory development backend, and Qdrant.
- RRF or weighted fusion and optional cross-encoder reranking.
- TXT, Markdown, CSV, JSON, HTML, PDF, DOCX, and XLSX ingestion.
- Tenant, department, role, group, permission, owner, and declared ABAC filtering.
- Idempotent ingestion, content deduplication, document versions, scoped deletion, complete local backup bundles, and restart-safe indexes.
- OpenAI-compatible providers including Ollama, plus a dependency-free extractive mode.
- Native async APIs, provider token streaming, Prometheus text metrics, health probes, API-key principals, audit events, Redis search cache, and plugin entry-point discovery.
Install
pip install ragzen
Optional capabilities:
pip install "ragzen[local]" # sentence-transformers and cross-encoder reranking
pip install "ragzen[documents]" # PDF, DOCX and XLSX loaders
pip install "ragzen[qdrant]" # Qdrant vector backend
pip install "ragzen[redis]" # distributed search cache
pip install "ragzen[server]" # FastAPI server
pip install "ragzen[all]"
Zero-config quickstart
from ragzen import RagZen, SecurityContext
with RagZen.local("./data/ragzen") as rag:
document = rag.add_text(
"The refund period is 30 days.",
metadata={"tenant_id": "acme", "department": "support"},
)
context = SecurityContext(
tenant_id="acme",
user_id="user-1",
departments=["support"],
)
results = rag.search("refund period", security_context=context)
response = rag.ask("How long is the refund period?", security_context=context)
print(document.document_id, results[0].content, response.answer)
Local mode uses durable SQLite vectors and a dependency-free extractive generator. The same search results remain available after the process restarts.
Semantic embeddings and Ollama
# ragzen.yaml
embedding:
provider: sentence_transformers
model: sentence-transformers/all-MiniLM-L6-v2
llm:
provider: ollama
base_url: http://localhost:11434/v1
model: llama3.2
timeout_seconds: 60
from ragzen import RagZen
rag = RagZen.from_config("ragzen.yaml")
Qdrant and graph-assisted retrieval
vector_store:
provider: qdrant
url: http://localhost:6333
collection: company_documents
retrieval:
mode: hybrid_graph
fusion: rrf
graph:
enabled: true
path: .ragzen/graph.json
max_hops: 2
The built-in graph index is a deterministic entity co-occurrence graph with chunk provenance. Applications needing ontology extraction or a remote graph database can inject a custom graph index or retriever.
Server security
Server principals are configured on the server, not supplied by request bodies:
environment: production
security:
require_security_context: true
fail_closed: true
abac_keys: [region, clearance]
server:
allowed_ingest_roots: [/srv/ragzen/imports]
principals:
- api_key: ${RAGZEN_API_KEY}
tenant_id: acme
user_id: service-account
roles: [reader]
departments: [support]
Start the server:
ragzen --config ragzen.yaml serve --host 0.0.0.0 --port 8000
Use Authorization: Bearer <api-key>. Production server mode refuses to start
without a configured principal. Filesystem ingestion is disabled unless
allowed_ingest_roots is configured.
The Docker Compose deployment uses the production config and Qdrant. Set
RAGZEN_API_KEY before running docker compose; startup fails if it is absent.
CLI
ragzen init --path .ragzen
ragzen ingest ./documents --tenant acme
ragzen search "refund policy" --tenant acme
ragzen query "Summarize the refund policy" --tenant acme
ragzen stats
ragzen doctor
ragzen backup ./backups/ragzen
ragzen restore ./backups/ragzen.zip
Provider plugins
Third-party packages can expose a class through the ragzen.plugins Python entry-point
group. Set plugin_capability to embedding, vector_store, or llm, and
plugin_name to the corresponding config provider name. A plugin may implement
from_config(config) or a constructor accepting config=.
Quality gates
The repository CI runs Ruff, Mypy, Bandit, dependency auditing, the full pytest suite
with branch coverage, package build, Twine metadata validation, and a Python 3.11-3.13
matrix on Linux and Windows.
The dependency-free evaluate_retrieval helper provides Recall@K, reciprocal rank and
nDCG@K for application-specific evaluation sets.
See documentation, architecture, security model, and contributing guide.
License
Apache-2.0. See LICENSE.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ragzen-2.3.8.tar.gz.
File metadata
- Download URL: ragzen-2.3.8.tar.gz
- Upload date:
- Size: 104.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d16f18c0a40987d90f63ffe46eb08a6380d09fad13dead378861e486a0c037c9
|
|
| MD5 |
329b85969837c2da7f85c919b5f1dffb
|
|
| BLAKE2b-256 |
57ae5a49c00b6b1e2689f063f409889164291f2a5d9699248b80542ba194d51e
|
File details
Details for the file ragzen-2.3.8-py3-none-any.whl.
File metadata
- Download URL: ragzen-2.3.8-py3-none-any.whl
- Upload date:
- Size: 101.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3e94a6afee59ee9cf2cc97d78a118819ea8e4bd827d8160e6b3dd5f792b3d78
|
|
| MD5 |
556518651bb27e741702e6cd93b6f9d6
|
|
| BLAKE2b-256 |
7409784369dbc06c00bdfe45b019052b081d2ed0422a0dac6580ff2cfd2e82a7
|