Contextual news data retrieval system with LLM-powered query parsing.
Design document: See
docs/DESIGN.mdfor architecture, assumptions, tradeoffs, and alternative approaches for scaling.
- uv (Python package manager)
- Python 3.13+
- Docker & Docker Compose
uv synccp .env.example .envThen edit .env and set your values:
MONGODB_URL– Full MongoDB URL (optional; when empty, built from below)MONGO_DB– Database name (default: news)MONGO_HOST– Host (default: localhost; usemongodbwhen app runs in Docker)MONGO_PORT– Port (default: 27017)MONGO_USER/MONGO_PASSWORD– Auth (required when MongoDB has auth)OPENAI_API_KEY– Required for unified query and summariesOPENAI_MODEL– LLM model (default: gpt-4o-mini)VALKEY_URL– Valkey/Redis URL for geocode cache (optional; useCACHE_BACKEND=memorywhen unset)CACHE_BACKEND–valkeyormemory(default: memory whenVALKEY_URLunset)MAX_RADIUS_KM– Max radius for nearby search in km (default: 1500)
Start MongoDB and Valkey:
docker compose up -dMongo Express: http://localhost:8081 (if MONGO_EXPRESS_PORT=8081).
With the app running on the host, set VALKEY_URL=redis://localhost:6379 for geocode cache, or leave CACHE_BACKEND=memory.
Load data:
uv run python -m app.cli load news_data.jsonOr load data and summarize:
Options:
--summarize/-s– Summarize articles via LLM (default: false)--n-summarize/-n– Number of articles to summarize, 1–n (default: 10)
uv run python -m app.cli load news_data.json --summarize -n 20uv run uvicorn app.main:app --reloadDeterministic:
GET /api/v1/news/category?category=...– By categoryGET /api/v1/news/search?query=...– Text searchGET /api/v1/news/nearby?lat=...&lon=...&radius_km=10– Nearby articlesGET /api/v1/news/source?source=...– By sourceGET /api/v1/news/score?threshold=...– By relevance threshold (0–1)
Non-deterministic:
GET /api/v1/news?query=...– Unified; LLM routes to category/search/nearbyGET /api/v1/news/trending?lat=...&lon=...&radius_km=10&limit=5&offset=0– Location-based trending (cached 5 min, supports pagination)
Docs: http://localhost:8000/docs
After loading articles, generate simulated events for trending testing:
uv run python -m app.cli generate-eventsOptions: --count / -n (default 10000), --users / -u (default 500), --lat and --lon to cluster events at a location for focused trending tests.
uv run python -m app.cli generate-events --lat 18.96 --lon 72.82 -n 100000