Build a RAG app

Chapter 2 of 1130 min

Set up your project

In this chapter you will:

  • install the tools every Python developer uses
  • download the starter project
  • make a virtual environment, and run your first file

Install three tools

  1. Python 3.10 or newer from python.org. On Windows, tick Add python.exe to PATH on the first screen of the installer.
  2. VS Code from code.visualstudio.com. Once it's open, install the Python extension from the Extensions panel.
  3. Git from git-scm.com. Git saves snapshots of your code, so you can always go back, and later put your project on GitHub.

Download the starter project

Open a terminal (on Windows, PowerShell; on a Mac, Terminal), go to the folder where you keep your work, and run:

git clone https://github.com/jrcodex-learning/ask-my-docs.git

In VS Code, choose File → Open Folder and open the new ask-my-docs folder. Then open a terminal inside VS Code with Terminal → New Terminal. From now on, type commands there.

Look around

In the folderWhat it is
data/The Brightpath Studio handbook: five text files. Your app will answer questions about them
README.mdA short description of the project
.gitignoreA list of files Git should never save. It already lists your secrets file, which you'll create in chapter 8

Open data/leave.txt. It's plain text: paragraphs separated by empty lines. Remember that, because chapter 4 depends on it.

There is no code yet. You'll write all of it.

Make a virtual environment

A virtual environment is a private set of Python packages for one project, so the packages you install for this project can't break another one. Make one called .venv:

python -m venv .venv

Then switch it on. On Windows:

.venv\Scripts\activate

On macOS or Linux:

source .venv/bin/activate

The start of your terminal line now shows (.venv). Switch it on again each time you open a new terminal.

On Windows, if python isn't found, try py instead. If PowerShell says running scripts is disabled, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, then try again.

Run your first file

Create a file called main.py in the project folder:

main.py
print("Hello, RAG!")

Run it:

python main.py

You should see

Hello, RAG!

Save your progress

Tell Git who you are (only once, ever):

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Then save a snapshot, called a commit:

git add .
git commit -m "Chapter 2: set up"

You'll commit at the end of every chapter. By the end, your Git history shows the whole app growing, step by step.

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