A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.
audit: fix rock_music_rag - add env comment, rewrite em dash sentences, add missing docstrings
Tiioluwani96e5a640bde4
diff --git a/rag_apps/rock_music_rag/.env.example b/rag_apps/rock_music_rag/.env.exampleindex 39bb49f..8ab6be0 100644--- a/rag_apps/rock_music_rag/.env.example+++ b/rag_apps/rock_music_rag/.env.example@@ -1 +1,2 @@+# Google GenAI API key used to authenticate requests to Gemma 4. Get yours free at https://aistudio.google.comGOOGLE_API_KEY=your_google_api_key_herediff --git a/rag_apps/rock_music_rag/README.md b/rag_apps/rock_music_rag/README.mdindex 6d75aca..6c5cf9f 100644--- a/rag_apps/rock_music_rag/README.md+++ b/rag_apps/rock_music_rag/README.md@@ -14,7 +14,7 @@ Start with the 10 default bands or build a completely custom knowledge base by a## Features-- **Custom knowledge base:** Add or remove any band at runtime — the index rebuilds instantly+- **Custom knowledge base:** The index rebuilds instantly whenever you add or remove a band- **BM25 retrieval:** Fast keyword-based retrieval that finds the most relevant Wikipedia chunks for each query- **Grounded answers:** Gemma 4 answers only from retrieved context and cites the source URL- **Retrieved chunk viewer:** See exactly which passages the model used to form its answer@@ -43,7 +43,7 @@ Gemma 4 (`gemma-4-26b-a4b-it`) is Google DeepMind's open model family with capab## Prerequisites- Python 3.10 or later-- A Google API key — get one free at [aistudio.google.com](https://aistudio.google.com)+- A Google API key, available free at [aistudio.google.com](https://aistudio.google.com)## Installationdiff --git a/rag_apps/rock_music_rag/app.py b/rag_apps/rock_music_rag/app.pyindex 5d1672c..b760fc7 100644--- a/rag_apps/rock_music_rag/app.py+++ b/rag_apps/rock_music_rag/app.py@@ -1,5 +1,5 @@"""-Rock Music RAG — Streamlit UI+Streamlit UI for the Rock Music RAG app."""import osdiff --git a/rag_apps/rock_music_rag/rag.py b/rag_apps/rock_music_rag/rag.pyindex 47b2b4b..0a002f5 100644--- a/rag_apps/rock_music_rag/rag.py+++ b/rag_apps/rock_music_rag/rag.py@@ -1,5 +1,5 @@"""-Rock Music RAG — core pipeline.+Core RAG pipeline for the Rock Music app.Fetches Wikipedia pages for rock bands, indexes them with BM25,and answers questions using Gemma 4 via the Google GenAI API.@@ -87,6 +87,8 @@ def _clean_text(text: str) -> str:# ── Main class ─────────────────────────────────────────────────────────────────class RockRAG:+ """Manages a BM25-indexed rock music knowledge base and answers questions with Gemma 4."""+def __init__(self, api_key: str):self.client = genai.Client(api_key=api_key)self.bands: dict[str, dict] = {} # band_name -> {url, raw_content}@@ -125,6 +127,7 @@ class RockRAG:self._rebuild_index()def band_titles(self) -> list[str]:+ """Return an alphabetically sorted list of indexed band titles."""return sorted(self.bands.keys())# ── Indexing ───────────────────────────────────────────────────────────────@@ -150,6 +153,7 @@ class RockRAG:self.bm25 = BM25Okapi(self._tokenized)def index_size(self) -> int:+ """Return the total number of chunks currently in the BM25 index."""return len(self.chunks)# ── Retrieval ──────────────────────────────────────────────────────────────