This workspace contains 2 Python applications to compare NoRAG (full-context prompting) versus RAG (retrieval-augmented generation) using Google Gemini via the OpenAI SDK.
ask_norag_google.py
- NoRAG with Google Gemini via OpenAI SDK (
gemini-3.5-flash-lite). - Loads
docs/CrimeAndPunishment.txt, injects a "needle" passage, and runs two direct large-context questions:- a baseline question about Marmeladov (present in the original book)
- a needle question about Denis (the injected passage)
ask_rag_google.py
- RAG with Google Gemini for generation via OpenAI SDK.
- Uses local embeddings (
all-MiniLM-L6-v2) + local ChromaDB (chroma_db/) to retrieve relevant chunks before asking the model. - Default retrieval uses
n_results=5for the question:What does this say about Denis?
docs/CrimeAndPunishment.txt: main source text used by the scripts.docs/CrimeAndPunishment-shorter.txt: shortened version of the main source text for quicker testing and rapid experimentation in Gemini online at https://gemini.google.com/app (See note below)chroma_db/: persistent local vector database (used by RAG scripts).requirements.txt: Python dependencies.
- Python 3.10+ (recommended)
- API key:
GOOGLE_API_KEYfrom Google AI Studio
- Create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Configure environment variables:
cp .env.example .envThen edit .env and set your real keys.
With your virtual environment activated:
python ask_norag_google.pypython ask_rag_google.py-
Both applications use the OpenAI SDK to interact with Google Gemini via Google's OpenAI-compatible endpoint.
-
The RAG app splits the text into fixed-size chunks with an overlap (
CHUNK_SIZE,OVERLAP_PERCENTandMIN_PARAGRAPH_LENGTHat the top of the script), indexes them intochroma_db/and reuses them across runs. -
There is one index per document (
DOCUMENT_FILE) and chunking configuration. When no index exists for the current document and settings, the script asks before building one (this takes a little while). -
Debug prompt printing can be enabled by passing
debug=Truein the NoRAG app. -
RAG app prints retrieved context for verification.
-
Streaming output is enabled by default in both applications (controlled by
STREAM_ONvariable). -
Using the shortened version of the text (
docs/CrimeAndPunishment-shorter.txt)- Go online at https://gemini.google.com/app
- At the prompt, start writing "Here is a story: ",
- Then paste the content of docs/CrimeAndPunishment-shorter.txt into the Gemini chat app and then, at the end of the prompt, ask "What can you tell me about Denis Amselemovitch?"
- Observe the response from Gemini.