Skip to content
back to the cosmos

Retrieval, measured in milliseconds

DHARA

An agentic RAG engine for legal research over 10,000+ documents — 97% retrieval accuracy, citation-traced answers at sub-500ms P95 — with multi-agent query decomposition, reranking, and deterministic grounding on AWS microservices.

Legal research is liability-bearing: an answer is only useful if every claim traces to a source, and only usable if it lands while the lawyer is still reading the question. DHARA had to hold that bar over 10,000+ legal documents — agentically decomposing compound questions so nothing is missed and nothing is invented.

retrieval accuracy
97%
citation-traced
P95 latency
<500ms
AWS microservices
legal documents
10,000+
retrieval
agentic
multi-agent decomposition

the bar it had to clear

how it actually works

per sub-queryQueryDecomposeLangGraph agentEmbedderbatched, 384-dVector indexPinecone · HNSWRerankerrelevance re-scoringLLMgrounded generationResponse

hover or tab a step to see how it works — or trace a route above.

  1. 01

    Query ingress

    A compound legal question enters — often several sub-questions bundled into one.

  2. 02

    Split the question first

    A LangGraph agent breaks a compound legal question into focused sub-questions, so each gets its own targeted retrieval instead of one blurry search over the whole thing.

  3. 03

    Text to vector

    Each sub-question is embedded for vector search over the document index.

  4. 04

    Vector search over 10,000+ docs

    Each decomposed sub-query runs its own vector search over the document index, returning a candidate set for the reranker to score.

  5. 05

    Search narrows, reranking decides

    The reranker reads query and candidate together to pick the passages that actually answer the sub-question — decisive over a candidate set, too expensive over the whole index.

  6. 06

    Deterministic grounding

    Generation is constrained to retrieved spans; every claim carries a citation back to its source document — no invented law.

  7. 07

    Citation-traced answer

    A grounded answer over 10,000+ legal documents at sub-500ms P95, on AWS microservices.

peek inside the vector search

The retrieval step is HNSW approximate nearest-neighbour. Here it is for real — drop a query and watch it hop.

Drop a query — watch HNSW hop to it. It examined 10 of 140 vectors · a linear scan checks all 140.

Each hop moves to the neighbour closest to the query, then drops a layer — logarithmic-ish hops, not a scan. The larger dots are the upper-layer “express lanes.”

the problem

Legal research questions are rarely atomic — one query bundles several sub-questions, each needing its own grounded, citation-traced answer, fast enough to keep a researcher in flow. Naive single-shot RAG fumbles this: it retrieves against the whole compound question at once, ranks by vector similarity alone, and cannot guarantee that a generated claim actually traces to a retrieved source.

the approach

  • A LangGraph agent decomposes each compound question into sub-queries before retrieval, so every part of the question gets its own targeted search.
  • Each sub-query runs vector search over the document index; a reranker then re-scores candidates so the strongest passages win, not just the nearest vectors.
  • Deterministic grounding stamps every claim in the answer with its source span — the model can only assert what retrieval actually returned.
  • Runs as containerized microservices on AWS, holding sub-500ms P95 at 97% retrieval accuracy.

the calls that mattered

Every architecture is a set of trade-offs taken on purpose. These are the load-bearing ones.

Make retrieval agentic — decompose before you search.

A compound legal question searched as one blob retrieves mush. A LangGraph agent splits it into sub-questions first, so each gets a focused retrieval — the single biggest lever on the 97% accuracy.

the trade-offMore retrieval calls per question and an agent loop to orchestrate — paid for by answers that actually address every part of the question.

Rerank after vector search — never instead of it.

Vector similarity finds the roughly-relevant fast; a reranker reads query and passage together to decide which are actually decisive. Order matters: search narrows, reranking picks.

the trade-offA second scoring pass per sub-query — worth it because in legal, the right passage beats more passages every time.

Ground deterministically — the model may only cite what retrieval returned.

In legal, an ungrounded claim is a liability. Binding generation to retrieved spans makes every sentence citation-traced by construction, not by hope.

the trade-offThe model can’t “fill in” missing context — correct, since a confident-but-unsourced legal answer is worse than an honest gap.

what shipped

DHARA answers over 10,000+ legal documents at 97% retrieval accuracy and sub-500ms P95, every claim citation-traced by deterministic grounding — multi-agent query decomposition and reranking running as containerized microservices on AWS.

what’s next

  • Streaming citations: emit each source span with the first token instead of after generation completes.
  • A learned reranker fine-tuned on legal relevance judgments to push past 97%.
  • Cross-document synthesis so an answer can weave several sources into one grounded argument.

built with

FastAPILangGraphLangChainVector SearchAWS