Build a RAG app

Chapter 10 of 1140 min

Share it

  1. Load
  2. Chunk
  3. Embed
  4. Search
  5. Ask the AI
  6. App

In this chapter you will:

  • put your project on your own GitHub
  • write the list of packages a server needs to run your app
  • put your app online, with your API key kept secret, and get a link anyone can open

Put it on your GitHub

Your project was cloned from the JrCodex starter, so Git still points there. Point it at your own copy instead.

  1. On github.com, sign in (or sign up), click New repository, name it ask-my-docs, keep it Public, and leave every box below unticked. Create it.
  2. In your terminal, with your own user name in place of YOUR-NAME:
git remote set-url origin https://github.com/YOUR-NAME/ask-my-docs.git
git push -u origin main

Open your repository page. Your code is there, and so is your history: every chapter's commit. That history is part of what makes it a portfolio project: it shows how you built it.

Look through the files on GitHub once more. .env must not be there.

List what the app needs

Your laptop has the packages installed; a server starting from nothing doesn't. Create requirements.txt in the project folder:

requirements.txt
--extra-index-url https://download.pytorch.org/whl/cpu
torch
sentence-transformers
google-genai
python-dotenv
streamlit

The first line tells pip where to find the small version of PyTorch for computers without a graphics card, which is what free servers are. Without it the install is several times bigger and may not fit.

git add requirements.txt
git commit -m "Chapter 10: requirements"
git push

Put it online

Streamlit Community Cloud runs Streamlit apps for free, straight from GitHub.

  1. Sign in with your GitHub account.
  2. Click Create app, then choose to deploy from GitHub.
  3. Pick your ask-my-docs repository, branch main, and main file app.py.
  4. Open Advanced settings. Choose Python 3.12. In Secrets, paste one line with your key:
GEMINI_API_KEY = "paste-your-key-here"
  1. Click Deploy. The first build installs everything, so it takes a few minutes.

Your .env file never left your laptop, so the server gets the key from these secrets instead. Streamlit hands each secret to your app as an environment variable, which is exactly where genai.Client() looks. No code change needed.

When it's done, you get a link like https://your-app-name.streamlit.app. Open it on your phone. That's your app, live.

Anyone with the link uses your free Gemini quota. That's fine for showing friends or an interviewer. Don't post it somewhere thousands of people will click it. If the build fails, the log on the right of the page shows the error; the most common cause is a typo in requirements.txt.

Make the README yours

Your repository's README.md still describes the starter. Rewrite it for someone visiting your GitHub: what the app does, the link to the live app, how it works (load, chunk, embed, search, ask the AI), and how to run it locally. A screenshot of the app makes it much stronger. Commit and push.

Predict, then check

An interviewer asks: "Why didn't you just send the whole handbook to Gemini?" What do you answer?

Show answer

Something like: "For five files I could have. But real document sets are far bigger than a model can take in, and sending everything is slow and costly. Retrieval sends only the three most relevant chunks, so the answer stays fast, cheap and grounded in the right passages, and the app can cite its source." That's the whole idea of RAG, in your own words.

Save your progress

git add .
git commit -m "Chapter 10: shared online"
git push

Stuck, or want to compare? The finished code for this chapter is tagged ch10: run git diff ch10, or see it on GitHub.