Assignment

Week 2 homework: RAG on your Week 1 endpoint

Tip

Need step-by-step support?

Use the full Week 2 assignment guide (copy-paste prompts) here: Week 2 RAG assignment guide.

Extend your Week 1 POST /ask on Render into a document-grounded RAG API. Same service, two processes: POST /ingest when data changes, POST /ask when users ask. Use a cloud vector DB (Pinecone — easiest) or self-hosted (ChromaDB, pgvector). A notebook-only demo does not count. Done means both endpoints on your live URL, with citations, refusal, and eval proof in README.

Tip

Start from your Week 1 deploy

Do not rebuild from scratch. Your Week 1 FastAPI service on Render is the base. Add vector store + ingest + retrieval in front of the existing /ask handler.

Architecture

POST /ingest

New

Load docs → chunk with overlap → embed → upsert to vector store with metadata. Repeatable process when data changes — no redeploy.

POST /ask

Week 1 → 2

Embed question → retrieve top-k → grounding prompt (cite + refuse) → generate. Test retrieval alone before wiring the LLM.

Vector store

Pick one

Pinecone (cloud, less ops) or ChromaDB / pgvector (self-hosted). Lock embedding model early.

6 required steps

  1. 1

    Choose corpus + vector store

    Northwind sample docs or your capstone documents. Provision Pinecone (recommended) or self-hosted store. Document in README.

  2. 2

    Build POST /ingest

    Accept files or JSON. Chunk with `RecursiveCharacterTextSplitter` + overlap. Embed and upsert with document_id metadata.

  3. 3

    Test retrieval FIRST

    Debug route or script: question in → top-k chunks + scores out. No LLM yet.

  4. 4

    Upgrade POST /ask

    Retrieve → ground (context-only, cite chunk IDs, refuse when missing) → generate. Keep cost/tokens fields where possible.

  5. 5

    Deploy + prove live

    Same Render service as Week 1. curl ingest + curl ask against public URL.

  6. 6

    Golden-set eval (≥5 questions)

    Score retrieval hit rate, faithfulness, and correctness. Include one refusal case. Put results in README — including what broke.

Live curl sketch (replace YOUR-SERVICE)
# Ingest
curl -s -X POST https://YOUR-SERVICE.onrender.com/ingest \
  -H "Content-Type: application/json" \
  -d '{"text": "...", "document_id": "handbook"}'

# Ask (RAG)
curl -s -X POST https://YOUR-SERVICE.onrender.com/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "What is the remote work policy?"}'

Stretch goals (pick 1+)

  • Chunk size comparison
  • Hybrid search
  • Metadata filtering
  • Reranking
  • Streamlit UI
  • Multi-document / batch ingest

What to submit

README: architecture (ingest vs query), how to add documents, embedding model choice, eval scores, what broke.

Critical

Do NOT share your live URL on LinkedIn

Maven / cohort WhatsApp: live URL, ingest + ask curls, one doc-grounded answer with cited chunk IDs, golden-set pass rate. LinkedIn: screenshots or screen recording only.

Watch out

Common mistakes

  • Rebuilding /ask from scratch instead of extending Week 1.
  • No ingest endpoint — hard-coding docs at deploy is not a pipeline.
  • Skipping retrieval-only testing.
  • No refusal-path question in golden set.
  • Posting live URL publicly.

Done when

  • Vector store chosen and documented (cloud e.g. Pinecone, or self-hosted e.g. ChromaDB)
  • POST /ingest loads, chunks (with overlap), embeds, and upserts documents with metadata
  • Retrieval tested alone before generation — you can show top-k chunks for a known question
  • POST /ask retrieves, grounds (cites + refuses), and answers only from ingested docs
  • Both endpoints work on your live Render URL (curl ingest + curl ask)
  • Golden-set eval (≥5 questions) reports retrieval hit rate, faithfulness, and correctness in README
  • At least one stretch goal attempted, or you explain in README why you deferred advanced retrieval

Share in Maven or WhatsApp: Live URL, a doc-grounded question + answer with cited chunk IDs, and your golden-set pass rate. LinkedIn: screenshots only — never post the live service URL publicly.