Suraj Suresh
AI / MLJun to Jul 2026Solo buildPublished Jul 10, 2026

Agentic RAG over LLM Inference-Optimization Literature

An agent that answers questions about LLM inference papers from an arXiv corpus and cites its sources, with retrieval tuned on a 300-question benchmark.

My contribution
Solo. I designed and built ingestion, hybrid retrieval, the LangGraph agent, the FastAPI service, the retrieval benchmark, the RAGAS harness, Docker packaging, and CI.

  • Python
  • LangGraph
  • Qdrant
  • FastAPI
  • Docker
  • RAGAS
  • Weights & Biases
  • Ollama
Architecture diagram. A question enters a FastAPI service that routes to single-shot RAG or a LangGraph ReAct agent. Both retrieve from a Qdrant collection built from an arXiv corpus with dense plus BM25 hybrid search, generate with Qwen2.5-14B through Ollama, and return an answer with citations to a Streamlit UI.

Results

Each row shows how I measured the number and links to the file in the repo that produced it.

MeasureValueMethodSource
Hybrid retrieval, MRR0.594 to 0.639rag-mini-wikipedia, 3,200 passages, 300 factoid questions, relevance measured as answer-string containment. Dense bge-large alone vs dense plus BM25 hybrid.experiments.md (opens in a new tab)
Hybrid retrieval, Hit@50.697 to 0.717Same benchmark and configurations as the MRR row.experiments.md (opens in a new tab)
Reranker effect on MRR0.639 to 0.520bge-reranker-base cross-encoder, fetch 20 then keep top 5, same benchmark. Traced to a mismatch between the answer-containment metric and the reranker objective, so reranking is off by default.experiments.md (opens in a new tab)

Problem

Most RAG demos retrieve over Wikipedia. I wanted to answer questions over a narrow technical corpus: recent arXiv work on LLM inference optimization, covering vLLM, quantization, KV-cache management, continuous batching, speculative decoding, and GPU serving economics. That domain changes the engineering problem. The vocabulary is dense and overloaded, so the discriminating signal is often an exact term or a number rather than fuzzy topicality. Questions are multi-hop, so evidence has to be assembled from more than one passage. A confident wrong answer about a serving optimization is also worse than saying the corpus does not cover it.

My contribution

I built the whole system. Ingestion streams a 500-paper arXiv slice into about 1,477 chunks behind a quality gate (minimum length, whitespace normalization) and indexes them in an isolated Qdrant collection. Retrieval is dense bge-large embeddings, with BM25 hybrid fusion and a cross-encoder rerank stage as config-gated options. Generation runs in one of two modes behind a feature flag: a single-shot RAG baseline, or a LangGraph ReAct agent that decides when to search and cites what it used. A FastAPI service exposes the answer endpoint, and a Streamlit UI shows the answer next to a citation ledger. Around that I wrote the retrieval benchmark, a NaN-tolerant RAGAS harness with a local judge by default and a hosted-judge fallback, Weights & Biases tracking, multi-stage Docker and compose files, and a GitHub Actions workflow that runs ruff and pytest on every push.

Architecture

The diagram above shows the path from a question to a cited answer. Everything runs locally and free by default (local embeddings, a local Qwen2.5-14B through Ollama), and every provider is swappable to a hosted API by changing one config value.

Key decisions

Hybrid retrieval as the default. BM25 catches the entity and number questions that dense embeddings blur, and that is where lexical signal matters in this corpus. The ablation below shows the difference.

Reranking off by default. The cross-encoder lowered MRR on the benchmark. I traced that to the metric, not the code. Answer-string containment rewards passages that literally contain the answer, while the reranker promotes passages that are topically relevant but answerless. I recorded the trade-off and a follow-up plan (judge reranking with a relevance-aware metric) as an architecture decision record.

LangGraph after deepagents failed a smoke test. The agent was first built on deepagents. A live smoke test showed its heavy built-in middleware overwhelmed the local 14B model: it never called the search tool and produced off-topic output. A control test confirmed the same model calls tools reliably in a lighter harness, so I migrated to LangGraph's ReAct agent. That kept the local-first constraint intact.

Local-first evaluation. The RAGAS loop uses a local judge so the project does not depend on a paid API, and it tolerates the NaN scores that local judges produce when they fail to return strict JSON.

Evidence

Retrieval ablation on rag-mini-wikipedia (3,200 passages indexed, 300 factoid questions, answer-recall at k):

ConfigurationHit@5MRRRecall@5
Dense (bge-large)0.6970.5940.487
Dense + BM25 hybrid0.7170.6390.496
Hybrid + cross-encoder rerank0.6900.5200.470

The numbers are deterministic given the same corpus, gold sample, and models, and the configurations are flags in the repo so anyone can reproduce them.

Generation quality is measured with the RAGAS harness, but I do not quote those scores here. They came from a three-question sample with a local judge and are not stable enough to stand behind. The deliverable here is the harness itself, with its judge fallback and tracking.

Tradeoffs and next steps

Answer-containment is a cheap proxy that under-credits reranking; the next step is a relevance-aware metric or gold passage labels so the reranker can be judged fairly. The RAGAS sample needs to grow before any generation number is worth publishing. Two pull requests are open on the repo as of this writing: one caps agent citations at the requested top-k across multi-search runs, and one makes the RAGAS harness two-stage and config-driven with persisted runs.