Messy sources: PDFs, tables and keeping the index fresh
RAG & Vector Search · 10 questions
Short notes
Key idea
Real documents are messy: scanned PDFs, tables, headers on every page, duplicates and constant updates. Good extraction and an index that stays current matter as much as the model.
Syntax
- PDF text: a text extractor for digital PDFs; OCR for scans. Check the output, don't trust it.
- Remove noise: repeated headers, footers, page numbers, boilerplate.
- Tables: convert to Markdown or "column: value" rows so headers stay with values.
- Metadata: source, page, version, updated date.
- Freshness: store a hash per document; on change, delete its old chunks and re-index; remove chunks of deleted documents.
Example
A rate card PDF has a table of courier prices. Extracted as plain text, the numbers lose their columns. Converted to rows like "Zone: South | Weight: 1 kg | Price: ₹60", the question "1 kg to the South zone?" retrieves the exact row.
Traps
- Old versions left in the index give answers from last year's policy.
- Duplicates fill the top results with the same text.
- OCR mistakes (0 vs O, ₹ lost) break numbers; spot-check.
- Images and charts carry no text unless you describe them.
Want the full lesson with step-by-step examples, a project and a certificate? RAG & Vector Search course, ₹180 →
- Question 1easy
PdfReader("scan.pdf").pages[0].extract_text()returns an empty string for a scanned form. Why? - Question 2hard
Find lines that appear on every page of
pagesand remove them from each page. Store the list of cleaned pages (lines joined with "\n") inresult.Store your answer in
result. - Question 3easy
What does this print?
row = {"product_name": "Yoga Mat", "category": "Sports", "price": 699.0, "stock": 0} stock = "in stock" if row["stock"] > 0 else "out of stock" print(f"{row['product_name']} ({row['category']}) costs {row['price']:.0f} and is {stock}.") - Question 4medium
What does this print?
import hashlib h = lambda t: hashlib.sha256(t.encode()).hexdigest() print(h("Refunds within 3 days.") == h("Refunds within 3 days."), h("Refunds within 3 days.") == h("Refunds within 2 days.")) - Question 5medium
What does this print?
import re norm = lambda t: re.sub(r"[^a-z0-9 ]", "", t.lower()).strip() texts = ["Gift cards can't be returned.", "gift cards cant be returned", "Returns in 10 days."] print(len({norm(t) for t in texts}))
Messy sources: PDFs, tables and keeping the index fresh
Messy sources: PDFs, tables and keeping the index fresh
Messy sources: PDFs, tables and keeping the index fresh
Messy sources: PDFs, tables and keeping the index fresh
Messy sources: PDFs, tables and keeping the index fresh
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.