VikingRAG SDK — Accurate, Token-Efficient Hierarchical RAG for Structured Documents

RAG
Hierarchical Retrieval
Python SDK
pgvector
Token Efficiency
Agentic AI

How this was built: RAG

VikingRAG SDK
VikingRAG SDK is an independent Apache-2.0 production stack for accurate and token-efficient retrieval-augmented generation over structured documents. Inspired by the VikingRAG paper (Gao et al., arXiv:2609.11390), it keeps document → section → subsection → chunk hierarchy with stable viking:// URIs instead of flattening everything into an unrelated bag of chunks — so answers stay grounded in provenance and structure.
The system pairs multi-granular indexing (bottom-up abstracts plus embeddings at document, section, and chunk) with evidence-gap tools — Semantic Search on PostgreSQL/pgvector, structural List, scoped Grep, and authoritative Read — plus a bounded agentic loop (Algorithm 1) and modes vikingrag / vikingrag_e / vikingrag_e_plus. Experience edges and LearningPolicy (off / record_only / learn / frozen) make retrieval budgets and learning controllable. Paper experiments report large token savings versus flat RAG baselines; this repo is a production-oriented reimplementation, not a fork of the AGPL research artifacts.
Shipped as a typed Python 3.12+ SDK and FastAPI service: pip install vikingrag, ingest Markdown/TXT/PDF, index, ask, and explain via VikingRAGClient. Stack includes FastAPI, PostgreSQL + pgvector, Redis, Alembic migrations, Docker Compose, replaceable LLM/embedding providers (OpenAI, DeepSeek, Gemini, Anthropic, vLLM), optional auth allowlist, and evaluation scaffolding. Open source at github.com/mhuzaifadev/VikingRAG.

Tech Stack

Python logo
FastAPI logo
PostgreSQL logo
Docker logo