Back to projects
Preview coming soon

Longevity — AI Nutrition Assistant

The idea

A language model asked for calories or for an answer it was never shown will invent them. Longevity splits the work so it never gets the chance: a deterministic engine computes every number, and answers come only from scientific documents the system actually retrieved, with page-accurate citations.

Three parts, all in one Next.js app. A deterministic nutrition engine computes BMI, BMR, TDEE, the calorie target and the macro split from a user profile: pure functions, no model, every constant cited and enforced by a test. A constrained meal-plan pipeline lets the model output only {food, grams} per item; totals are computed server-side from a curated food database, a plan outside tolerance is first repaired without the model and at most once sent back with the computed deltas, and if it still does not land the API returns targets instead of a wrong plan. Retrieval-honest Q&A uses Supabase pgvector with a similarity threshold: below it, the model is not called at all and a deterministic "not in my sources" message is returned; citations come back as structured data, and any marker the model invents is stripped.

The first version had a separate FastAPI backend on Render and a Pinecone index. I retired it in October 2026 and ported everything into the Next.js app as API routes, moving the vector store to pgvector. 285 unit tests run in CI without any API key.

My role

Designed and built solo: the engine, the plan pipeline, the retrieval layer and the chat UI, and later the port from a FastAPI backend to Next.js API routes.