Skip to content

About

Hybrid RAG (DuckDB vector + BM25 + RRF + recency/keyword priors + optional cross-encoder rerank) as an installable library + CLI.

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

redevops-rag

License: AGPL-3.0 + Commons Clause Python NVIDIA Inception  ·  self-hosted  ·  no lock-in  ·  source-available

🚀 NVIDIA Inception Program Member — ReDevOps is a member of the NVIDIA Inception Program, supporting startups advancing AI and accelerated computing. Membership provides access to NVIDIA technology, technical resources, and the startup ecosystem. It does not imply product endorsement by NVIDIA. Program membership is not product endorsement.

  • What it does: hybrid retrieval (DuckDB vector + BM25 + RRF, optional rerank) as a Python library and CLI, plus a pure-Python structural citation_graph change-closure primitive.
  • Who it's for: developers who want to index a folder (docs tree, repo, notes vault) and query it locally.
  • Maturity: alpha (0.x; see STATUS.md).
  • 3-minute example: Install from git, then run examples/quickstart.py or the redevops-rag index / search commands in CLI. Embedding models are downloaded on first use.
  • Evidence: benchmarks/ holds the retrieval eval scripts and benchmarks/results/; the citation_graph numbers below are not in this repo. Unit tests: tests/.
  • Limitations: see STATUS.md. Validate on your own data.
  • Docs: ARCHITECTURE.md, CONTRIBUTING.md, SECURITY.md.

Hybrid RAG as a small, installable library + CLI — DuckDB vector + BM25 fused via Reciprocal Rank Fusion, recency & keyword priors, and an optional cross-encoder rerank.

It's the retrieval pipeline from a ReDevOps application repository that is not public carved out of its multi-tenant SaaS shell (no Auth0/Stripe/Kubernetes/workspace coupling) so you can drop the same retrieval over any folder — a docs tree, a repo, an Obsidian vault — in three lines.

Versioning — backwards-compatible across all five index/format generations (v1–v5). (These vN are architecture generations, not release versions — releases are semver, e.g. v0.2.0.) Version note: the latest git tag is v0.4.0, but the package's redevops_rag.__version__ (and therefore the installed wheel version) still reports 0.2.0; this is a documentation note, tracked in STATUS.md. The library API, CLI, and on-disk index/store format from every prior generation keep working — upgrade in place, no migration.

Pipeline

query
  ├─ dense   : embedding → DuckDB array_cosine_similarity (threshold = the encoder's sim_floor; bge 0.4, Nemotron/ReasonIR 0.1)
  └─ sparse  : DuckDB FTS BM25
        └─ Reciprocal Rank Fusion   score = Σ 1 / (k + rank),  k = 60
              └─ recency prior       0.5 ** (age_days / 90)
              └─ keyword prior       ×(1 + 0.05·term_hits), capped 1.5
                    └─ (optional) cross-encoder rerank  BAAI/bge-reranker-v2-m3  → top-k

For change-closure retrieval (the set affected by an edit, not the set resembling a query) there is a separate structural arm, citation_graph, that composes with this pipeline — see below.

Install

Not on PyPI yet — install from git:

pip install "git+https://github.com/redevops-io/redevops-rag.git"                          # core
pip install "redevops-rag[rerank] @ git+https://github.com/redevops-io/redevops-rag.git"   # + cross-encoder rerank
pip install "redevops-rag[llm]    @ git+https://github.com/redevops-io/redevops-rag.git"   # + answer synthesis

CLI

redevops-rag index ~/obsidian-vault              # chunk + embed + index into ./redevops_rag.duckdb
redevops-rag search "how do we rotate API keys"  # hybrid search, top chunks
redevops-rag --rerank search "..."               # add the cross-encoder rerank stage
redevops-rag ask "what's our incident process?"  # search + synthesized answer (needs an LLM, below)

Answer synthesis (ask) talks to any OpenAI-compatible endpoint — a local MLX/llama.cpp server, OpenAI, or Anthropic behind a gateway:

export REDEVOPS_RAG_LLM_BASE_URL=http://localhost:8080/v1   # e.g. a Mac running mlx_lm.server
export REDEVOPS_RAG_LLM_MODEL=DeepSeek-V4-Flash
export REDEVOPS_RAG_LLM_API_KEY=EMPTY                       # or sk-... for a cloud endpoint
redevops-rag ask "summarize our on-call runbook"

Library (the 3 lines)

from redevops_rag import RAG

rag = RAG(db_path="vault.duckdb")          # add use_reranker=True for the cross-encoder stage
rag.index("~/obsidian-vault")              # chunk + embed + index (content-addressed ids; re-run anytime)
hits = rag.search("zero-downtime deploys", k=8)
# answer = rag.ask("zero-downtime deploys")["answer"]   # if an LLM env is set

Structural change-closure retrieval (citation_graph)

Hybrid search finds what resembles a query. Some retrieval targets are structural, not lexical: the set of provisions/clauses/symbols affected by an edit is its dependency closure — everything that cites, incorporates, uses the defined term of, or calls the edited unit — and a dependent that shares no surface text with the edit is invisible to any similarity method. citation_graph is that structural primitive: a dependency graph with reverse-closure retrieval, composable with hybrid search under a token budget. It is pure-Python + stdlib-only (no torch/duckdb) and imported lazily.

from redevops_rag import ChangeClosureGraph, Node

g = ChangeClosureGraph(
    nodes=[Node("s362", "automatic stay …"), Node("s541", "property of the estate is subject to §362 …")],
    edges={"s541": {"s362"}},                      # s541 DEPENDS ON s362
)
g.closure("s362")                                  # {"s541", …} — who is affected if §362 is edited
g.retrieve("s362", budget=4000)                    # closure, hop-ordered, budget-filled (the seed excluded)

# compose with content retrieval: closure first, a hybrid ranking fills the remaining budget
content = [h["chunk_id"] for h in rag.search(edited_text, k=50)]
g.union_retrieve("s362", budget=4000, content_order=content)

In ReDevOps' own benchmark runs, measured against BM25 / dense / HippoRAG-style PageRank at a matched 4000-token budget, citation_graph won or tied on every case across statutes (0.556 vs 0.159), regulations→statutes (0.484 vs 0.066), real contracts (0.302 vs 0.209) and defined-terms (1.000 vs 0.206). Not reproducible from this repo: these results are not reproducible from this repository and no script or result file in this repo regenerates them. Treat them as unverified by third parties; see the blog for the write-up. The defined-terms 1.000 is a ceiling value, and the benchmark set is not described in this repo. The ceiling is edge coverage; where genuinely-implicit edges have no parseable reference, PrecisionEdgeExtractor recovers them from an injectable LLM — precision-gated (confidence + verbatim-trigger grounding) so the edges help the closure rather than bloat it, and fail-soft when no endpoint is reachable. Which representation (graph, content, or their union) to spend the budget on for a given task is a Context-Runtime decision, not a fixed retriever.

Retrieval budgets are hard limits: the returned nodes never exceed budget tokens (an oversize node is skipped so smaller later ones can still fit), and ordering is deterministic (hop, then in-degree, then id).

Tenant scoping and namespaces

Tenant isolation is the caller's job. A Store, PgStore or ChangeClosureGraph holds one corpus, and document_ids=None means unscoped (every document). To get a cheap safety net, construct the component with namespace="tenant-a"; any request that passes a different (or no) namespace — e.g. hybrid_search(store, q, namespace="tenant-a"), graph.retrieve(seed, budget, namespace="tenant-a") — raises NamespaceMismatch. Without a namespace on the component, no check is made. The guard is opt-in and covers hybrid_search and the graph retrieval methods only; calling Store/PgStore search methods directly is unguarded.

Re-indexing and deleted sources

Deletion happens only on re-index (there are no tombstones): rag.index(path) removes documents previously indexed under path whose source file no longer exists. Safeguards: pruning is skipped when path is missing; it is refused (prune_refused in the result) when the scan finds no files or when more than max_prune_fraction (default 0.5) of the indexed documents would go, unless allow_empty=True; pass prune=False to keep everything. Symbolic links that resolve outside the indexed root are not followed.

Why a folder, not a sync

Point it at one central copy of the knowledge base and query it — you don't copy 200k files to every machine, you index once and retrieve. For a team, run it on one box (or behind a thin service) so everyone hits a single index. Configuration and skills files are small — those belong in git, not in a RAG.

Configuration

env default meaning
REDEVOPS_RAG_EMBED_MODEL BAAI/bge-small-en-v1.5 sentence-transformers embedding model
REDEVOPS_RAG_RERANK_MODEL BAAI/bge-reranker-v2-m3 cross-encoder for --rerank
REDEVOPS_RAG_LLM_BASE_URL / _MODEL / _API_KEY — OpenAI-compatible endpoint for ask

Content-addressed chunk identity. Chunk ids are content-hash derived ({document_ref}::{content_hash[:16]}), not position-based — identical content yields identical ids regardless of ingest order, and re-ingesting an edited source is orphan-safe: a content_hash column is stored and a re-ingest sweep prunes chunks whose content no longer exists, so no stale vector survives a shrunk or edited document.

Status: runnable, benchmarked library. The retrieval logic is a faithful port of the production pipeline; the packaging/CLI are new. The benchmarks/ suite evaluates recall/NDCG across PopQA · MuSiQue · LongMemEval · TEMPO · Nutrition (bge / ReasonIR / Nemotron-3-Embed encoders, hybrid / DIVER / graph methods). Validate on your own data.

Architecture

The ReDevOps runtimes use a functional-core / imperative-shell design: deterministic transformations (fusion, scoring, canonicalization) are pure functions over frozen value contracts, while stores and providers sit behind small interfaces at the boundary. See ARCHITECTURE.md.

AGPL-3.0-or-later · redevops.io

Note: the repository's LICENSE.md is titled "License" and describes the project as "source-available, not open source in the OSI sense", licensed under AGPL-3.0-or-later "as modified by the Commons Clause License Condition v1.0". The one-line footer above omits the Commons Clause; it is under counsel review and the wording is intentionally unchanged here.

Parquet / S3 retrieval (optional)

redevops_rag.parquet_index (extra parquet) retrieves over Parquet instead of the DuckDB store: BM25 computed with Polars over a scan_parquet (local path, glob or s3:// prefix, with projection and predicate pushdown), and a ChangeClosureGraph loaded from an edge table. content_led(...) composes a content ranking with the seed's forward (what governs it) and reverse (what it affects) closure under a token budget. It is a primitive: the composition policy stays with the caller.

About

Hybrid RAG (DuckDB vector + BM25 + RRF + recency/keyword priors + optional cross-encoder rerank) as an installable library + CLI.

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages