Draft write-up
PDReader lets you upload several PDFs through a React interface and chat with them. Ingestion runs in the background so large books never block a request. Retrieval combines vector similarity with full-text search, and a LangGraph agent decides how to handle each question. Answers show collapsible source snippets linked to the original page.
01Problem
A basic RAG demo breaks on real books: big files time out on upload, and exact terms such as API names and acronyms get lost when you rely on embeddings alone. A single retrieval step is also wasteful for questions that do not need it, such as greetings or a request for an overview.
02Approach
- 01
Ingest in the background
Uploads are validated and persisted, then a Redis queue hands them to a worker that extracts, chunks and embeds the text, and generates a summary and topic map for each document.
- 02
Hybrid retrieval
Cosine similarity in pgvector is combined with PostgreSQL full-text search using reciprocal-rank fusion, so exact terms are not missed.
- 03
Route questions with an agent
A LangGraph agent classifies intent first. Greetings stay cheap, overview and study questions reuse the precomputed summary and topic map, and code or search questions run the full retrieval pipeline.
- 04
Guard the citations
A citation guard flags answers that have no supporting source, and answers expose source snippets linked back to the page.
03Architecture
A React client, a FastAPI backend, a background worker, and Postgres with pgvector for both search modes.
01Client
React, TypeScript, ViteUpload, document list, chat and polling for ingestion status.
02API
FastAPIValidates uploads, enqueues ingestion and runs the chat agent.
03Queue and worker
Redis (RQ)Background ingestion: extract, chunk, embed, summarise.
04Storage and search
PostgreSQL + pgvectorDocuments, chunks and jobs, with vector and full-text search.
05Agent
LangGraphIntent routing between cheap replies, precomputed summaries and full retrieval.
06Models
OpenAItext-embedding-3-small for embeddings and GPT-4o-mini for answers.
- Multiple PDFs, with non-blocking background ingestion
- Hybrid vector and full-text retrieval with rank fusion
- Intent-aware chat that avoids retrieval when it is not needed
- Per-document summaries and topic maps, plus cited source snippets
04Challenges
Large books timed out on upload.
FixIngestion moved to a background queue so the request returns immediately and the UI polls for progress.
Embeddings alone missed exact terms like API names and acronyms.
FixAdded PostgreSQL full-text search and fused the two rankings.
05Learnings
Outcomes
- A local-first study assistant with cited answers across several books
- A containerised stack: React, FastAPI, Postgres, Redis and Docker
What I learned
- Routing by intent saves cost and latency before retrieval even starts.
- Hybrid search is a cheap fix for exact-term misses.
06Next
- 01Add an evaluation set of questions with known page answers
- 02Support more file types beyond PDF
