News RAG app
Personal project
An AI news overview. It collects the latest articles, writes a short summary and picks a category for each one, and lets you ask questions about the news. Every summary and answer links back to the original article.
Built withPython, FastAPI, LangChain, FAISS, PostgreSQL, Docker
CodeGitHub
Why RAG
A language model on its own doesn't know what happened today, and it can make things up. RAG, short for retrieval-augmented generation, fixes that by first finding relevant text and then asking the model to answer from that text only. The sources come back with the answer, so you can check them.
How it works
- Fetch. Pulls the latest world news from the BBC and New York Times RSS feeds. Articles already in the database are skipped, so only new ones cost API calls.
- Summarize and sort. For each new article the model writes a two-sentence summary and picks one of ten categories, like Politics, Technology or Climate. Everything is stored in PostgreSQL with the link to the source.
- Index. Splits the articles into small chunks and turns them into embeddings with OpenAI. The embeddings are stored in PostgreSQL and loaded into FAISS for fast similarity search, so restarting doesn't mean paying for them again.
- Answer. A question is matched against the index, the four closest chunks are sent to the model, and the answer comes back with the source URLs.
The API
| Endpoint | What it does |
|---|---|
GET /articles | Latest articles with summary, category and link. Filter with ?category=Climate |
GET /categories | Number of articles per category |
POST /ask | Answers a question about the news |
POST /refresh | Fetches, summarizes and indexes new articles |
curl -X POST http://localhost:8000/ask \
-H "Content-Type: application/json" \
-d '{"question": "What is happening in Ukraine?"}'
Run it yourself
There's no public demo, because every question costs money on the OpenAI API. With Docker and your own key it starts with one command, and Docker Compose sets up the database too.
git clone https://github.com/mbilal1005/News-rag-app cd News-rag-app export OPENAI_API_KEY="sk-..." docker compose up --build