🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101

Chat with your PDF (RAG)

Upload notes or a textbook PDF and ask questions; answers come only from the document, with page citations.

Intermediate⏱ 10–14 hoursđŸĒœ 7 stepsPythonLLM APIEmbeddingsVector store

What you'll learn

  • ◆Retrieval-augmented generation (RAG)
  • ◆Chunking and embeddings
  • ◆Grounding answers and citing sources

What you'll build

  • ✓PDF upload
  • ✓Answers with page references
  • ✓Says "not in the document" when unsure
  • ✓Chat history

Step-by-step guide

  1. 1

    Extract text by page

    pypdf: keep (page_number, text) pairs.

  2. 2

    Chunk

    Split into ~500-word chunks with 50-word overlap; keep the page number on each chunk.

  3. 3

    Embed

    Create embeddings with an embedding model (from your LLM provider or sentence-transformers) and store them in a vector store (Chroma, FAISS or pgvector).

  4. 4

    Retrieve

    Embed the question and fetch the top 4 similar chunks.

  5. 5

    Prompt

    Send the chunks plus the question to an LLM API (for example Claude, GPT or Gemini) with instructions: answer only from the context, cite pages, say if the answer is not there.

  6. 6

    UI

    Streamlit chat (st.chat_input, st.chat_message) showing cited pages under each answer.

  7. 7

    Evaluate

    Write 20 questions with known answers; check accuracy and whether citations are correct. Keep the API key in an environment variable, never in code.

🚀 Make it stand out

  • +Multiple documents
  • +Hybrid search (keyword + vector)
  • +Show the source passage highlighted