
VikingRAG SDK is an open-source Python library for retrieval-augmented generation (RAG) over structured documents like manuals, reports, and policies. Most RAG systems cut a document into small chunks and forget where each chunk came from. VikingRAG keeps the full structure: document, section, subsection, and chunk. Every piece gets a stable viking:// address, so each answer can point back to the exact place it came from.
I built it as an independent, production-ready version of the VikingRAG paper by Gao et al. (arXiv:2609.11390). It is released under the Apache-2.0 license. It is not a fork of the paper's research code, which uses the AGPL license.
During indexing, VikingRAG writes short summaries from the bottom up and stores embeddings at three levels: document, section, and chunk. When a question comes in, an agent looks for missing evidence with four tools: Semantic Search on PostgreSQL with pgvector, List to browse the structure, Grep to search inside one section, and Read to pull the original text. The agent runs in a loop with a fixed budget, so it can't keep searching forever.
There are three retrieval modes: vikingrag, vikingrag_e, and vikingrag_e_plus. The system can also learn from past questions through experience edges, and a LearningPolicy setting (off, record_only, learn, or frozen) lets you decide how much it learns. In the paper's experiments, this approach used far fewer tokens than flat RAG baselines.
You install it with pip install vikingrag. Through the VikingRAGClient you can upload Markdown, TXT, or PDF files, index them, ask questions, and see why a certain answer was given. It needs Python 3.12 or newer, is fully typed, and also runs as a FastAPI service.
The stack is FastAPI, PostgreSQL with pgvector, Redis, Alembic migrations, and Docker Compose. The LLM and embedding provider can be swapped: OpenAI, DeepSeek, Gemini, Anthropic, and vLLM all work. It also has an optional auth allowlist and tools for running evaluations. The code is on GitHub at github.com/mhuzaifadev/VikingRAG.