Lesson Complete
Exit
Lesson Complete!
Generate Answers and Finish the App
What you built
A command-line RAG application that:
- Loads any PDF from your file system
- Extracts and chunks its text
- Embeds every chunk using the Gemini API — once, then caches to disk
- Finds the most relevant chunks for any question
- Generates a grounded, accurate answer using Gemini Flash
- Shows the source passages alongside the answer
The functions you wrote
| Function | Lesson | Purpose |
|---|---|---|
load_pdf | 1 | Count pages in a PDF |
extract_text | 2 | Pull all text from a PDF |
chunk_text | 2 | Split text into overlapping pieces |
preview_chunks | 2 | Inspect chunking output |
create_client | 3 | Authenticate with the Gemini API |
embed_text | 3 | Convert one chunk to a vector |
embed_all_chunks | 3 | Embed an entire list of chunks |
cosine_similarity | 4 | Score two vectors for closeness |
search | 4 | Retrieve the top matching chunks |
build_prompt | 5 | Assemble context + question into a prompt |
generate_answer | 5 | Call Gemini and return the answer |
print_result | 5 | Display the answer and sources |
save_embeddings | 5 | Write chunks and vectors to disk |
load_embeddings | 5 | Read chunks and vectors from disk |
main | 5 | Wire the full pipeline from CLI arguments |
Where to go next
- Add a web UI — replace the CLI with a
gradiointerface in about 10 lines - Support multiple PDFs — index a folder of files and search across all of them
- Use a local model — swap Gemini for a model running on your machine with
ollama