P.01RAG
Build an assistant that answers questions over a private document set, retrieves the passages it relies on and cites them in every answer. You own the full pipeline, from ingestion to source-aware responses.
01
Teams keep their knowledge in PDFs, wikis and markdown files that no one can search well. A general-purpose model cannot answer questions about that material, and when asked anyway it tends to produce confident answers with no way to check where they came from.
In this project you build a retrieval-augmented assistant that grounds every answer in retrieved passages, shows its sources, and says so when the documents do not contain an answer. The emphasis is on the parts that decide answer quality: how documents are parsed and chunked, how retrieval is tuned, and how citations are tied back to the exact text used.
02
A Python ingestion job parses and chunks documents into Postgres with pgvector. A FastAPI service retrieves candidate passages for each question, assembles a bounded context and asks the model for an answer that references passage IDs, which are then validated and rendered as citations.
Ingestion · offline
documents/
PDF, Markdown, HTML
parse + clean
keep headings & ids
chunk
structure-aware, overlap
embed
vector per chunk
index
vectors + metadata
Query · online
question
user input
retrieve top-k
hybrid: vector + keyword
rerank
keep the best 4
generate
answer only from sources
answer + [1][2]
citations to chunks
Ingest
Parse PDFs, HTML and markdown into clean text, keeping titles, headings and page numbers as metadata.
Chunk & embed
Split documents with heading-aware chunking and overlap, then store embeddings and metadata in pgvector.
Retrieve
Run a similarity search with metadata filters and return the top passages with scores and stable IDs.
Assemble context
Fit the selected passages into a token budget, label each with its ID and add instructions for citing sources.
Generate
Request a structured answer containing the response text, cited passage IDs and an explicit 'not found' flag.
Validate & cite
Check that every cited ID was actually retrieved, then render citations that link back to the source document.
03
Suggested stack. Equivalent tools are fine; document the choice in your decision record.
04
Stage 01
Choose a public document set, write a repeatable ingestion script and inspect the parsed output for broken tables and lost headings.
Stage 02
Implement chunking and vector search, then write a small set of questions with known source passages to measure recall.
Stage 03
Add the generation step with structured output, passage-level citations and a clear response when the answer is not in the corpus.
Stage 04
Compare chunk sizes, overlap and top-k settings against your question set and record what changed and why.
Stage 05
Containerize the service, add a minimal chat UI and document setup so a reviewer can run it locally.
05
06
Build the foundations, projects, and habits needed to design more dependable AI applications.