NutriRAG: Unleashing the Power of Large Language Models for Food Identification and Classification through Retrieval Methods

Huixue Zhou, Lisa S. Chow, Lisa Harnack, Satchidananda Panda, Emily N. C. Manoogian, Minchen Li, Yongkang Xiao, Rui ZhangmedRxiv 2025

Abstract

Objective: This study explores the use of advanced Natural Language Processing (NLP) techniques to enhance food classification and dietary analysis using raw text input from a diet tracking app. Materials and Methods: The study was conducted in three stages: data collection, framework development, and application. Data were collected via the myCircadianClock app, where participants logged their meals in free-text format. We developed the NutriRAG framework, an NLP framework utilizing a Retrieval-Augmented Generation (RAG) approach to retrieve examples and incorporating large language models such as GPT-4 and Llama-2-70b. NutriRAG was designed to identify and classify user-recorded food items into predefined categories and analyzed dietary patterns from free-text entries in a 12-week randomized clinical trial (RCT: NCT04259632). Results: NutriRAG significantly enhanced classification accuracy, with the retrieval-augmented GPT-4 model achieving a Micro F1 score of 82.24. Both interventions showed dietary alterations: CR participants ate fewer snacks and sugary foods, while TRE participants reduced nighttime eating. Conclusion: By using AI, NutriRAG marks a substantial advancement in food classification and dietary analysis of nutritional assessments.

Introduction

In nutrition science, the "gold standard" for tracking intake is the 24-hour dietary recall, but these are limited snapshots. To understand long-term health, researchers prefer mobile apps where users log food in real-time. However, this creates a data challenge: users enter unstructured text like "Gf Pasta Tuna Parsley Garlic Anchovy Oil Tomato Parmesan." Traditional NLP tools struggle with the complex dependencies and variety in these descriptions. NutriRAG addresses this by transforming "messy" logs into high-quality, structured data suitable for clinical analysis using Large Language Models (LLMs).

The NutriRAG Framework

The researchers developed NutriRAG, a framework that moves beyond simple zero-shot prompting. The pipeline consists of four stages: query formulation from raw user text, retrieval of similar examples using an LLM Similarity Calculator, LLM processing with a "few-shot" prompt, and structured output organization.

The NutriRAG framework overview, illustrating the pipeline from data collection to dietary pattern analysis.

Retrieval-Augmented Generation for Nutrition

The core innovation of NutriRAG is the use of RAG to provide context. Instead of asking the LLM to guess, the system finds the most similar examples from a validated dataset using cosine similarity of embeddings. These top-K retrieved examples are fed into the LLM (like GPT-4 or Llama-2) as a prompt context, providing a guiding framework for how similar items were previously classified.

Detailed view of the NutriRAG retrieval process, showing how a raw query is matched with similar examples to produce structured output.

Experimental Results and Clinical Insights

The framework was tested on 32,825 free-text food entries from a 12-week Randomized Clinical Trial (RCT) involving 77 participants. Key findings include:

  • Performance Boost: Standard GPT-4 achieved a Micro F1 score of 73.84. Adding the RAG framework boosted this to 82.24.
  • Open-Source Viability: The RAG-augmented Mixtral 8x7B reached an F1 of 77.93, outperforming the standard GPT-3.5. This suggests that smaller open-source models with RAG are highly viable for researchers with privacy concerns.
  • Clinical Application: The framework successfully detected dietary shifts in the RCT. It confirmed that participants in the Caloric Restriction (CR) group significantly reduced savory snacks and sugary foods, while the Time-Restricted Eating (TRE) group successfully reduced late-night eating.

Conclusion

NutriRAG demonstrates that context is king; even powerful LLMs are significantly better at niche tasks when given relevant examples. While the framework is dependent on the quality of the reference database, it marks a substantial advancement in personalized nutrition and the management of diet-related health issues. Future work will explore integrating image-based recognition with the text-based NutriRAG framework.

Summary updated

BibTeX
@misc{zhou2025nutrirag,
  author = {Huixue Zhou and Lisa S. Chow and Lisa Harnack and Satchidananda Panda and Emily N. C. Manoogian and Minchen Li and Yongkang Xiao and Rui Zhang},
  title = {{NutriRAG: Unleashing the Power of Large Language Models for Food Identification and Classification through Retrieval Methods}},
  year = {2025},
  doi = {10.1101/2025.03.19.25324268},
  howpublished = {medRxiv},
}
Figure