Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kaggle BBC News RAG Homework

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.

What is implemented

  • 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.

Project structure

.
├── 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

Setup

Install uv if it is not installed:

pip install uv

Install dependencies:

uv sync

Build data and index

Recommended full run with Kaggle data:

uv run python scripts/download_dataset.py --limit 1200
uv run python scripts/build_index.py

The homework statement requires the following command to build the index:

uv run python scripts/build_index.py

If 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.

Run UI

uv run streamlit run app/main.py

In the UI:

  1. Build the index if it is missing.
  2. Enter a question.
  3. Check that the answer is shown together with source chunks, scores and doc_id.

Demo questions

Run:

uv run python scripts/demo_answer.py

The script writes results to artifacts/demo_results.md.

Use these questions in the UI or demo script:

  1. What does the dataset say about artificial intelligence or technology in education?
  2. What are the main issues discussed about climate, weather, or the environment?
  3. What does the dataset say about health monitoring or public health campaigns?
  4. 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.

Tests

uv run pytest

There are 6 tests covering chunking, data normalization, retrieval, source-grounded answers and refusal behavior.

How to submit

  1. Create your own GitHub repository.
  2. Copy all files from this project into that repository.
  3. 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
  1. 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
  1. Open the course repository from the homework statement.
  2. Create a new branch in that course repository.
  3. Add homework/SUBMISSION.md there.
  4. In SUBMISSION.md, paste the link to your GitHub repository with this completed project.
  5. Open a Pull Request into the course repository.

Notes

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages