Home/Expertise
RAG engineering
Retrieval-augmented systems for structured documents and ops — including VikingRAG (hierarchical, token-efficient RAG), a Gemini legal assistant, and n8n workflows. Written from shipped work by Muhammad Huzaifa Shahbaz, AI Systems Engineer at Digital Dividend Global.
What I build
- Hierarchical RAG that preserves document structure instead of flattening sections into unrelated chunks.
- Document assistants that answer from a private corpus and return the passage they used.
- Operational RAG wired into n8n so repetitive internal lookups do not depend on someone pasting context into a chat window.
Architecture
- VikingRAG SDK indexes document → section → subsection → chunk with multi-granular embeddings on PostgreSQL/pgvector, then retrieves via Search, List, Grep, and Read with shared token budgets.
- The legal assistant uses Gemini for generation, LangChain to orchestrate retrieval, and MongoDB for documents and embeddings.
- Queries hit vector search first. The model answers from retrieved passages instead of from the prompt alone.
- Ops automation pairs the same retrieval idea with n8n. At Digital Dividend that workflow is credited with about 8 hours saved per week.
Production constraints
- Flat chunk RAG loses section context and burns tokens on irrelevant neighbors. VikingRAG keeps hierarchy and escalates only when evidence is insufficient.
- Legal answers without a source are not usable. The assistant is built to retrieve case material and contracts, not to freestyle.
- Published results on the legal assistant: 95%+ accuracy on classification and question answering in their evaluation, and about a 70% reduction in document review time versus manual research.
- Token cost and stale embeddings are the ongoing bills. Retrieval has to be scoped to the documents that matter for the question.
Stack
Python · FastAPI · PostgreSQL · pgvector · Redis · Gemini · LangChain · MongoDB · Next.js · n8n · RAG
Tradeoffs
- Hierarchy-aware indexing costs more at ingest and pays back at query time when structure matters; flat RAG is simpler when documents have no real outline.
- A vector store over a full-document prompt is cheaper and easier to cite, and it fails when the chunking splits the clause that actually answers the question.
- n8n is the right tool for an ops workflow a small team can edit. It is the wrong place for a latency-sensitive user-facing agent.
Projects
- VikingRAG SDK — Open-source hierarchical RAG SDK (PyPI) inspired by the VikingRAG paper.
- AI Legal Assistant — Gemini RAG assistant for legal document search and cited answers.
External verification
Questions
What RAG systems has he shipped?
VikingRAG, an Apache-2.0 Python SDK and FastAPI service for hierarchical RAG over structured documents (pip install vikingrag); a Gemini and LangChain legal assistant with MongoDB vector search; plus operational RAG workflows automated with n8n at Digital Dividend Global.
What is VikingRAG?
An independent production implementation of structure-aware retrieval inspired by the VikingRAG paper (arXiv:2609.11390). It preserves document hierarchy, uses pgvector search with List/Grep/Read tools, and exposes a typed SDK plus Answers API — not a fork of the AGPL research repo.
How is the legal assistant grounded?
It retrieves from stored legal documents and embeddings before answering, and the public write-up describes citation-backed answers rather than ungrounded chat.