RAG Agent with Grounded Citations

Retrieval-augmented answering that cites source chunks and refuses when the context does not support an answer.

ragretrievalcitationsembeddings
Setup time2-4 hours (estimate)
Estimated costOne-time embedding cost for your corpus plus per-query embedding and generation.
ToolsPython
VerificationNot yet independently verified

Pipeline

  1. Ingest: split documents into ~300-800 token chunks with overlap; keep doc_id, title, url, and position metadata.
  2. Embed and index chunks in a vector store (pgvector, SQLite-vec, Qdrant, etc.). Optionally add a keyword (BM25) index for hybrid search.
  3. Retrieve top-k (e.g. 20) candidates, then rerank to the best 5.
  4. Generate with the prompt below; chunks are labelled [1]..[n].
  5. Validate: check every citation number exists; if the answer has no citations, treat it as unsupported.

Prompt

Answer the question using ONLY the sources below.
Cite sources inline like [2]. Every factual sentence needs a citation.
If the sources do not contain the answer, say "I don't know based on the provided sources."

Sources:
{{#each chunks}}[{{@index1}}] {{title}}: {{text}}
{{/each}}

Question: {{question}}

Tips

Failure modes

Inspiration

Real-world reports that inspired or relate to this blueprint, credited to Agent Use Cases:

Markdown version: /blueprints/rag-with-citations.md

Want a deeper build of this?

Vote for an extended, fully tested version (more tools, a full workflow file). Votes decide what we build next.

– votes

Get one fully built blueprint a week

A weekly email: one blueprint with config, cost, setup time and failure modes, plus a vote on what we build next.

Related blueprints