Skip to content
Pratim/Dasude
05/RAG2 min read

PDReader

Outcome

Answers are grounded in the book text and link back to the source page.

RAGLangGraphpgvectorFull stack

React, FastAPI, PostgreSQL + pgvector, Redis, LangGraph

The PDReader chat interface summarising three uploaded engineering bookschat
PDReader answering a summary question across three uploaded PDFs.

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

  1. 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.

  2. 02

    Hybrid retrieval

    Cosine similarity in pgvector is combined with PostgreSQL full-text search using reciprocal-rank fusion, so exact terms are not missed.

  3. 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.

  4. 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.

01ClientREACT, TYPESCRIPT, VITE02APIFASTAPI03Queue and workerREDIS (RQ)04Storage and searchPOSTGRESQL + PGVECTOR05AgentLANGGRAPH06ModelsOPENAI
  1. 01Client

    React, TypeScript, Vite

    Upload, document list, chat and polling for ingestion status.

  2. 02API

    FastAPI

    Validates uploads, enqueues ingestion and runs the chat agent.

  3. 03Queue and worker

    Redis (RQ)

    Background ingestion: extract, chunk, embed, summarise.

  4. 04Storage and search

    PostgreSQL + pgvector

    Documents, chunks and jobs, with vector and full-text search.

  5. 05Agent

    LangGraph

    Intent routing between cheap replies, precomputed summaries and full retrieval.

  6. 06Models

    OpenAI

    text-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