TanayHingane/nutrigenius-recsys
About
A reproducible Indian recipe search benchmark comparing keyword overlap, TF-IDF, and MiniLM, with a live FastAPI + Next.js demo.
Web & App DevelopmentMeasured star growth
- in 24h
- +17
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalNutriGenius Recipe Search
Can a search engine find samosa from “a crispy snack shaped like a triangle”? On this query, MiniLM ranked it first and both lexical rankers missed it. Across the held-out set, TF-IDF had the highest Precision@5, with a median ranking time of 0.391 ms in one CPU run.
Try the live demo · API docs · Reproduce the results
The benchmark covers 96 Indian recipes and 70 manually labeled queries. The live demo lets you switch between keyword overlap and TF-IDF. MiniLM is available in the offline benchmark. The demo is hosted on Render’s free tier, so the first request after inactivity can take longer.
V2 benchmark
Results on 40 held-out queries. The other 30 queries form the development split and include the 10 original v1 queries.
| Ranker | Precision@5 | Recall@5 | Median ranking time |
|---|---|---|---|
| Keyword overlap | 0.215 | 0.929 | 0.036 ms |
| TF-IDF + cosine similarity | 0.220 | 0.946 | 0.391 ms |
| MiniLM + cosine similarity | 0.210 | 0.921 | 4.262 ms |
TF-IDF led overall. The differences are small on this hand-labeled dataset, and MiniLM was better on some queries that describe a dish indirectly.
- “a crispy snack shaped like a triangle” · MiniLM ranked samosa first. Both lexical rankers missed it in their top five.
- “Maharashtrian besan main dish” · TF-IDF retrieved both zunka and pithla. Keyword overlap missed pithla, and MiniLM missed zunka.
Reproduce the results
Use Python 3.11 or later.
git clone https://github.com/TanayHingane/nutrigenius-recsys.git
cd nutrigenius-recsys
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements-embeddings.txt
python evaluate.py --split dev --embeddings
python evaluate.py --split test --embeddings --verbose
On Windows PowerShell, activate with .venv\Scripts\Activate.ps1. The first embedding run downloads all-MiniLM-L6-v2 through FastEmbed. The model runs on CPU with one ONNX inference thread. For a lexical-only run, install requirements.txt and omit --embeddings.
All three methods rank the same recipe titles and descriptions. Keyword overlap counts shared unique tokens. TF-IDF weights tokens by their frequency across the catalog and ranks by cosine similarity. MiniLM embeds each recipe once and compares query and recipe vectors with cosine similarity. Ties break by recipe ID.
Precision@5 divides relevant hits by five, even when fewer results are returned. Recall@5 divides hits by the number of labeled relevant recipes. Both scores are macro-averaged over queries. Timing measures warmed-up, in-process ranking, including query encoding and sorting, with model loading, catalog indexing, and HTTP overhead excluded. The reported latency is from one local CPU run.
The recipe descriptions and query labels were written for this demo. Query texts are disjoint between splits, and both splits search the same catalog. Many queries have only one labeled relevant recipe, which caps their Precision@5 at 0.20. The benchmark is small and the relevance labels may omit valid matches, so the scores measure agreement with this fixture.
Run the demo locally
Use Python 3.11+ and Node.js 24. From the repository root, with your Python environment active:
python -m pip install -r requirements.txt
npm ci --prefix frontend
npm run build --prefix frontend
python -m uvicorn app:app --reload
Open the search demo or the interactive API docs. The demo starts with TF-IDF because it led the held-out benchmark. The API keeps keyword overlap as its default and accepts either lexical method.
curl "http://127.0.0.1:8000/recommend?query=quick%20Maharashtrian%20breakfast&limit=3&method=tfidf"
The Python service can also run by itself. With the frontend built, FastAPI serves the static Next.js export and API on the same origin.
Deployment and checks
The root Dockerfile builds one service for the frontend and API. For Render, use the included render.yaml Blueprint or create a Docker web service from this repository and set its health check to /healthz. The service binds to the port supplied by the host.
docker build -t nutrigenius-recsys .
docker run --rm -p 8000:8000 nutrigenius-recsys
GitHub Actions runs the API tests, both lexical benchmark splits, and the Next.js production build. MiniLM is available through the separate reproduction commands above.
Repository layout
| Path | Purpose |
|---|---|
data/recipes.csv |
Recipe titles and searchable descriptions |
data/queries.json |
Relevance judgments, query categories, and development/test split |
recommender.py |
Keyword and TF-IDF rankers |
embeddings.py |
Optional pretrained MiniLM ranker |
evaluate.py |
Per-split, per-category, and per-query evaluation |
app.py |
FastAPI service and static demo hosting |
frontend/ |
Next.js search interface |
tests/ |
API regression checks |
Suggest a benchmark query
Try a regional spelling, ingredient synonym, or indirect description in the demo. If a match is missing, open an issue with the query, ranker, actual result, and the recipe you expected. This helps identify useful additions to the benchmark.
If you use the benchmark as a reference, consider starring the repository so you can find it again.
Explore related projects
Loading…
