Educational Retrieval-Augmented Generation project for the homework pipeline: ingest → chunking → index → retrieval → demo answer → Streamlit UI.
The project uses the Kaggle dataset BBC News Articles by Bhavik Jikadara: bhavikjikadara/bbc-news-articles. It contains about 35,860 news rows with article text and metadata. The default normalized subset is 1,200 documents, which is enough for the "excellent" scale requirement.
- Ingest from Kaggle with
kagglehub. - Normalization into
data/processed/datasets.json. - Sentence-aware chunking with overlap.
- Local TF-IDF index using scikit-learn.
- Retrieval with cosine similarity.
- Grounded extractive answer generation.
- Negative-question refusal when retrieval confidence is too low.
- Streamlit UI that displays answer,
doc_id, score and source chunk text. - Tests for data loading, chunking, retrieval and refusal behavior.
.
├── app/main.py # Streamlit UI
├── data/raw/sample_news.csv # small fallback dataset for offline smoke tests
├── data/processed/datasets.json # generated normalized dataset
├── data/index/ # generated vector index
├── doc/ # planning and data documentation
├── homework/SUBMISSION.md # file to add to the required PR
├── scripts/download_dataset.py # Kaggle ingest
├── scripts/build_index.py # chunking + index build
├── scripts/demo_answer.py # demo questions and answers
├── scripts/check_submission.py # local checklist
├── src/rag/ # RAG package
└── tests/ # pytest tests
Install uv if it is not installed:
pip install uvInstall dependencies:
uv syncRecommended full run with Kaggle data:
uv run python scripts/download_dataset.py --limit 1200
uv run python scripts/build_index.pyThe homework statement requires the following command to build the index:
uv run python scripts/build_index.pyIf Kaggle data has not been downloaded yet, this command still works on the included small fallback sample. For final submission, run download_dataset.py first so that datasets.json contains 1,000+ real Kaggle records.
uv run streamlit run app/main.pyIn the UI:
- Build the index if it is missing.
- Enter a question.
- Check that the answer is shown together with source chunks, scores and
doc_id.
Run:
uv run python scripts/demo_answer.pyThe script writes results to artifacts/demo_results.md.
Use these questions in the UI or demo script:
What does the dataset say about artificial intelligence or technology in education?What are the main issues discussed about climate, weather, or the environment?What does the dataset say about health monitoring or public health campaigns?- Negative question:
What is my professor's private phone number?
Expected behavior for the negative question: the system refuses to answer because the indexed dataset does not contain relevant evidence.
uv run pytestThere are 6 tests covering chunking, data normalization, retrieval, source-grounded answers and refusal behavior.
- Create your own GitHub repository.
- Copy all files from this project into that repository.
- Run the commands below and make sure they pass:
uv sync
uv run python scripts/download_dataset.py --limit 1200
uv run python scripts/build_index.py
uv run python scripts/demo_answer.py
uv run pytest- Commit and push:
git init
git add .
git commit -m "Add Kaggle news RAG homework"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git
git push -u origin main- Open the course repository from the homework statement.
- Create a new branch in that course repository.
- Add
homework/SUBMISSION.mdthere. - In
SUBMISSION.md, paste the link to your GitHub repository with this completed project. - Open a Pull Request into the course repository.
The answer generation is intentionally deterministic and local. It does not require OpenAI, Anthropic or other paid LLM APIs. The answer is built only from retrieved source chunks, which makes the refusal behavior easy to test.