SuperAPI AI Directory

food-database-query

Data & analytics

View repository

Updated 10-16 06:51

About this skill

Food Database Query Skill

Skill Name: Food Database Query Skill Type: Data Query and Analysis Creation Date: 2026-01-06 Version: v1.0


When to Use

  • Use when querying food nutritional components, comparing food differences, or performing nutritional calculations.
  • Tasks involve food database retrieval, food recommendations, portion conversion, or category filtering.
  • Use when analysis results need to be generated based on structured food data rather than free-text suggestions.

Skill Overview

This skill provides comprehensive nutritional food database query functionality, supporting food nutritional information queries, comparisons, recommendations, and automatic nutritional calculations.

Core Functions:

  • ✅ Food Nutritional Information Query
  • ✅ Food Comparison Analysis
  • ✅ Smart Food Recommendations
  • ✅ Automatic Nutritional Calculation
  • ✅ Category Browsing and Search
  • ✅ Portion Conversion and Estimation

Data Source

Main Database

  • File: data/food-database.json
  • Content: Detailed nutritional data for 50 common foods
  • Structure: Each food contains 30+ nutrient indicators

Classification System

  • File: data/food-categories.json
  • Category: 10 major categories, 30+ subcategories
  • Support: Browse and filter by category

Functional Modules

1. Food Query

1.1 Exact Query

Purpose: Query nutritional information by food name

Supported Input:

  • Chinese names: "Oats", "Broccoli", "Salmon"
  • English names: "Oats", "Broccoli", "Salmon"
  • Aliases: "Oatmeal", "broccoli", "Salmon meat"

Query Process:

  1. Receive food name
  2. Search for matching entries in the database
  3. Support fuzzy matching and alias matching
  4. Return complete nutritional information

Returned Information:

  • Basic information (name, category, standard portion)
  • Macronutrients (calories, protein, carbohydrates, fat, fiber)
  • Micronutrients (vitamins, minerals)
  • Special nutrients (Omega-3/6, choline, etc.)
  • Glycemic index data
  • Health tags and applicable populations
  • Common portions
  • Nutritional advantage description

Example:

# 用户输入: "燕麦"
# 返回:
{
  "name": "燕麦",
  "name_en": "Oats",
  "category": "谷物类",
  "nutrition_per_100g": {
    "calories": 389,
    "protein_g": 16.9,
    "carbs_g": 66.3,
    "fat_g": 6.9,
    "fiber_g": 10.6,
    # ... 更多营养素
  },
  "health_tags": ["高纤维", "低GI"],
  "glycemic_index": {"value": 55, "level": "低"}
}

1.2 Fuzzy Search

Purpose: Search for foods by nutritional characteristics

Search Criteria:

  • Nutrient content: "high protein", "high fiber", "low GI"
  • Nutrient combination: "high protein low calorie", "high fiber low GI"
  • Category filtering: "grains", "vegetables", "protein"
  • Applicable populations: "vegetarian-friendly", "hypertension", "diabetes"

Search Logic:

# 示例: 搜索"高蛋白 低卡路里"
def search_foods(criteria):
    results = []
    for food in database:
        protein = food.nutrition_per_100g.protein_g
        calories = food.nutrition_per_100g.calories

        # 定义阈值
        high_protein = protein >= 15  # 每100g≥15g蛋白质
        low_calorie = calories <= 150  # 每100g≤150卡

        if high_protein and low_calorie:
            results.append(food)

    return sorted(results, key=lambda x: x.protein_g, reverse=True)

Return Format:

  • Sort by match degree
  • Display key nutrients
  • Label matching tags

1.3 Category Browsing

Purpose: Browse all foods by food category

Category Hierarchy:

蛋白质来源
├── 肉类
├── 禽类
├── 鱼虾贝类
├── 蛋类
├── 豆类
├── 坚果种子
└── 乳制品

Browsing Mode:

  • List all foods under a category
  • Sort by nutrient
  • Sort by GI value
  • Filter by health tags

2. Food Comparison

2.1 Two-Food Comparison

Function: Compare the nutritional differences between two foods

Comparison Dimensions:

  • Macronutrients: Calories, protein, carbohydrates, fat, fiber
  • Micronutrients: Major vitamins and minerals
  • Glycemic Index: GI value, glycemic load
  • Nutrient Density: Overall score

Calculation Logic:

def compare_foods(food1, food2):
    comparison = {}

    # 宏量营养素差异
    for nutrient in ["calories", "protein_g", "fiber_g"]:
        val1 = food1.nutrition_per_100g[nutrient]
        val2 = food2.nutrition_per_100g[nutrient]
        diff = val1 - val2
        percent = (diff / val2) * 100

        comparison[nutrient] = {
            "food1": val1,
            "food2": val2,
            "difference": diff,
            "percent_change": percent,
            "better": "food1" if diff > 0 else "food2"
        }

    return comparison

Output Format:

  • Comparison table
  • Difference percentage
  • Advantage annotation
  • Recommendations

2.2 Multi-Dimensional Comparison

Supported Modes:

  • Comprehensive nutritional comparison
  • Compare only specific nutrients
  • Compare only GI value
  • Compare only specific health tags

Examples: /nutrition compare 三文鱼 鸡胸肉 营养素


3. Food Recommendation

3.1 Recommendation Based on Nutrients

Recommendation Logic:

def recommend_by_nutrient(nutrient, min_value=None, max_value=None):
    recommendations = []

    for food in database:
        value = food.nutrition_per_100g[nutrient]

        # 筛选符合条件
        if min_value and value < min_value:
            continue
        if max_value and value > max_value:
            continue

        recommendations.append({
            "food": food,
            "value": value,
            "rda_percent": (value / RDA[nutrient]) * 100
        })

    # 按含量排序
    return sorted(recommendations, key=lambda x: x["value"], reverse=True)

Recommendation Categories:

  • High protein: ≥15g/100g
  • High fiber: ≥5g/100g
  • Low GI: ≤55
  • Rich in vitamin C: ≥50mg/100g
  • Rich in Omega-3: ≥1g/100g
  • High calcium: ≥100mg/100g
  • High iron: ≥3mg/100g

3.2 Multi-Condition Recommendation

Supported combined conditions:

  • "High protein, low calorie"
  • "High fiber, low GI"
  • "Rich in iron, vegetarian-friendly"

Sorting Strategy:

  1. Sort by first priority
  2. Filter those meeting the second condition
  3. Sort by overall score

3.3 Recommendation Based on Health Conditions

Hypertension (DASH diet):

  • Low-sodium foods
  • High-potassium foods
  • High-magnesium, high-calcium foods

Diabetes:

  • Low-GI foods
  • High-fiber foods
  • Low-carbohydrate

Hyperlipidemia:

  • High-Omega-3 foods
  • Low saturated fat
  • High-fiber foods

Osteoporosis:

  • High-calcium foods
  • Rich in vitamin D
  • High magnesium, high zinc

Anemia:

  • Rich in iron
  • Rich in folate
  • Rich in vitamin B12

4. Auto Nutrition Calculation

4.1 Food Recognition

Input Parsing:

def parse_food_input(text):
    # 示例: "燕麦粥 1杯 + 鸡蛋 1个 + 牛奶 250ml"

    foods = []
    portions = []

    # 识别食物名称
    for item in text.split("+"):
        food_name = extract_food_name(item)  # "燕麦粥"
        portion = extract_portion(item)      # "1杯"

        # 标准化食物名称
        standard_name = normalize_food_name(food_name)  # "燕麦"

        # 查询数据库
        food_data = query_database(standard_name)

        foods.append(food_data)
        portions.append(parse_portion(portion))

    return foods, portions

4.2 Portion Conversion

Common Portions:

  • "1 cup": 240ml (liquid) or weight depends on the food
  • "1 piece": egg 50g, apple 150g
  • "1 slice": bread 30g
  • "100g": use directly

Portion Database:

{
  "common_portions": [
    {
      "amount": 1,
      "unit": "个",
      "weight_g": 50,
      "description": "1个大号鸡蛋"
    },
    {
      "amount": 1,
      "unit": "杯",
      "weight_g": 240,
      "description": "1杯牛奶"
    }
  ]
}

4.3 Nutrition Calculation

Calculation Formula:

def calculate_nutrition(food, portion_grams):
    nutrition = {}

    for nutrient, value_per_100g in food.nutrition_per_100g.items():
        # 按100g比例计算
        nutrition[nutrient] = (value_per_100g * portion_grams) / 100

    return nutrition

4.4 Cooking Impact Correction

Factors Considered:

  • Weight change after cooking
  • Vitamin loss
  • Nutrient retention rate

Examples:

  • Raw oats: 100g → cooked: about 300g (3 times the weight)
  • Vitamin retention: 60-80% retained after cooking

5. Smart Search

5.1 Alias Matching

Supports synonyms:

  • "oats" = "oatmeal" = "oats" = "rolled oats"
  • "broccoli" = "broccoli" = "broccoli"

Matching Algorithm:

def find_food(name):
    # 1. 精确匹配主名称
    if name in database:
        return database[name]

    # 2. 匹配别名
    for food in database:
        if name in food.aliases:
            return food

    # 3. 模糊匹配
    matches = fuzzy_search(name)
    if matches:
        return matches[0]

    return None

5.2 Spelling Correction

Edit Distance Algorithm:

def fuzzy_search(name, max_distance=2):
    matches = []

    for food in database:
        # 计算编辑距离
        distance = levenshtein_distance(name, food.name)

        if distance <= max_distance:
            matches.append((food, distance))

    # 按距离排序
    return sorted(matches, key=lambda x: x[1])

Data Structure

Food Data Structure

{
  "id": "FD_001",
  "name": "燕麦",
  "name_en": "Oats",
  "aliases": ["燕麦片", "oats", "rolled oats"],
  "category": "grains",
  "subcategory": "whole_grains",

  "standard_portion": {
    "amount": 100,
    "unit": "g",
    "description": "100克"
  },

  "nutrition_per_100g": {
    "calories": 389,
    "protein_g": 16.9,
    "carbs_g": 66.3,
    "fat_g": 6.9,
    "fiber_g": 10.6,
    "sugar_g": 0.99,
    "saturated_fat_g": 1.4,
    "monounsaturated_fat_g": 2.5,
    "polyunsaturated_fat_g": 2.9,
    "trans_fat_g": 0,
    "water_g": 8.9,

    "vitamin_a_mcg": 0,
    "vitamin_c_mg": 0,
    "vitamin_d_mcg": 0,
    "vitamin_e_mg": 1.1,
    "vitamin_k_mcg": 1.9,
    "thiamine_mg": 0.763,
    "riboflavin_mg": 0.139,
    "niacin_mg": 6.921,
    "vitamin_b6_mg": 0.165,
    "folate_mcg": 56,
    "vitamin_b12_mcg": 0,
    "pantothenic_acid_mg": 1.349,
    "biotin_mcg": 0,

    "calcium_mg": 54,
    "iron_mg": 4.72,
    "magnesium_mg": 177,
    "phosphorus_mg": 523,
    "potassium_mg": 429,
    "sodium_mg": 2,
    "zinc_mg": 3.97,
    "copper_mg": 0.526,
    "manganese_mg": 4.916,
    "selenium_mcg": 2.8,
    "iodine_mcg": 0
  },

  "special_nutrients": {
    "omega_3_g": 0.685,
    "omega_6_g": 1.428,
    "choline_mg": 43.4,
    "beta_carotene_mcg": 0,
    "lutein_mcg": 0,
    "zeaxanthin_mcg": 0
  },

  "glycemic_index": {
    "value": 55,
    "level": "低",
    "glycemic_load": 11
  },

  "common_portions": [
    {
      "amount": 30,
      "unit": "g",
      "description": "1/4杯",
      "approximate_volume": "1/4 cup"
    },
    {
      "amount": 40,
      "unit": "g",
      "description": "1/3杯",
      "approximate_volume": "1/3 cup"
    },
    {
      "amount": 200,
      "unit": "ml",
      "description": "煮熟1杯",
      "notes": "煮熟后体积增加"
    }
  ],

  "cooking_effects": {
    "boiling": {
      "weight_change_percent": 200,
      "nutrient_changes": {
        "vitamin_c_retention": 0,
        "b_vitamins_retention": 60
      }
    }
  },

  "health_tags": ["高纤维", "低GI", "无麸质选项", "心脏健康"],

  "suitable_for": ["素食者", "高血压", "糖尿病", "高血脂"],

  "notes": "富含β-葡聚糖,有助于降低胆固醇"
}

RDA Reference Values

Adult Men (19-50 years)

RDA = {
  # 宏量营养素
  "calories": 2500,  # 中等活动水平
  "protein_g": 56,
  "carbs_g": 130,  # 最低值
  "fiber_g": 38,

  # 维生素
  "vitamin_a_mcg": 900,
  "vitamin_c_mg": 90,
  "vitamin_d_mcg": 15,
  "vitamin_e_mg": 15,
  "vitamin_k_mcg": 120,
  "thiamine_mg": 1.2,
  "riboflavin_mg": 1.3,
  "niacin_mg": 16,
  "vitamin_b6_mg": 1.3,
  "folate_mcg": 400,
  "vitamin_b12_mcg": 2.4,
  "pantothenic_acid_mg": 5,
  "biotin_mcg": 30,

  # 矿物质
  "calcium_mg": 1000,
  "iron_mg": 8,
  "magnesium_mg": 400,
  "phosphorus_mg": 700,
  "potassium_mg": 3400,
  "sodium_mg": 1500,  # 上限
  "zinc_mg": 11,
  "copper_mg": 0.9,
  "manganese_mg": 2.3,
  "selenium_mcg": 55
}

Adult Women (19-50 years)

RDA_FEMALE = {
  "calories": 2000,  # 中等活动水平
  "protein_g": 46,
  "fiber_g": 25,
  "iron_mg": 18,  # 育龄期
  # ... 其他略有差异
}

Integration Features

Integration with Nutrition Module

  1. Log Diet: Automatically query nutrition data
  2. Nutrition Analysis: Precise calculation based on database
  3. Nutrition Advice: Data-driven food recommendations

Integration with Health Module

  1. Hypertension: Recommend DASH diet-friendly foods
  2. Diabetes: Filter low-GI foods
  3. Hyperlipidemia: Recommend high Omega-3 foods

Integration with Exercise Module

  1. Before and After Exercise: Recommend suitable foods
  2. Muscle Gain: High-protein food recommendations
  3. Fat Loss: Low-calorie high-protein foods

Usage Examples

Example 1: Log Breakfast

User Input:

/nutrition record breakfast 燕麦粥 1杯 + 鸡蛋 1个 + 牛奶 250ml

System Processing:

  1. Recognize foods: oats, eggs, milk
  2. Query nutrition data
  3. Calculate nutrition per serving
  4. Summarize nutrition for the whole meal
  5. Log to diary

Return Result:

✅ 早餐已记录

**食物**: 燕麦粥(1杯) + 鸡蛋(1个) + 牛奶(250ml)

**营养汇总**:
- 卡路里: 417 卡
- 蛋白质: 25.1g
- 碳水化合物: 48.5g
- 脂肪: 15.2g
- 膳食纤维: 8.2g

**微量营养素亮点**:
- 维生素D: 3.1 μg (21% RDA)
- 钙: 332 mg (33% RDA)
- 维生素B12: 1.3 μg (54% RDA)

Example 2: Query Food

User Input:

/nutrition food 三文鱼

Return Result:

# 三文鱼 营养信息

## 基本信息
- **名称**: 三文鱼 (Salmon)
- **分类**: 蛋白质来源 > 鱼虾贝类
- **标准份量**: 100克

## 宏量营养素 (每100克)
- **卡路里**: 208 卡
- **蛋白质**: 20g ✅
- **碳水化合物**: 0g
- **脂肪**: 13g
- **Omega-3**: 2.5g ✅✅✅

## 营养亮点
- ✅✅✅ 富含Omega-3脂肪酸 (EPA+DHA)
- ✅✅ 高质量蛋白质
- ✅ 富含维生素D (11μg)
- ✅ 富含维生素B12 (3.2μg)

## 健康标签
- ✅ 高蛋白
- ✅ 富含Omega-3
- ✅ 心脏健康
- ✅ 大脑健康

## 推荐份量
- 100-150g/餐 (每周2-3次)

Example 3: Compare Foods

User Input:

/nutrition compare 鸡胸肉 三文鱼

Return Result:

# 食物比较: 鸡胸肉 vs 三文鱼

## 营养对比 (每100克)

| 营养素 | 鸡胸肉 | 三文鱼 | 差异 |
|--------|--------|--------|------|
| 卡路里 | 165 | 208 | +26% |
| 蛋白质 (g) | 31 | 20 | -35% ✅ |
| 脂肪 (g) | 3.6 | 13 | +261% |
| Omega-3 (g) | 0.1 | 2.5 | +2400% ✅✅✅ |

## 推荐建议

**选择鸡胸肉更适合**:
- ✅ 减脂期间 (低卡高蛋白)
- ✅ 控制脂肪摄入
- ✅ 蛋白质需求高

**选择三文鱼更适合**:
- ✅ 心脏健康 (高Omega-3)
- ✅ 大脑健康 (DHA)
- ✅ 抗炎需求

Expansion Plan

Short Term (1-2 months)

  • ✅ Completed 50 common foods
  • ⏳ Expand to 100 foods
  • ⏳ Add more common servings
  • ⏳ Optimize search algorithm

Medium Term (3-6 months)

  • ⏳ Expand to 300 foods
  • ⏳ Add branded foods
  • ⏳ Support user-defined foods
  • ⏳ Add food photos

Long Term (Ongoing)

  • ⏳ Continuously update database
  • ⏳ Add seasonal foods
  • ⏳ Integrate barcode scanning
  • ⏳ AI food recognition

Quality Assurance

Data Accuracy

  • Source: China Food Composition Tables (6th Edition) + USDA
  • Verification: Cross-validate multiple sources
  • Updates: Regularly update data

Functional Testing

  • Query accuracy testing
  • Calculation precision testing
  • Boundary condition testing
  • Performance testing

Notes

⚠️ Important Limitations

  1. Data Scope: Currently covers only 50 common foods
  2. Cooking Impact: Data is based on raw food/standard cooking
  3. Individual Differences: Actual nutrient absorption varies from person to person
  4. Regional differences: Food nutrition may differ by region

⚠️ Usage recommendations

  1. Balanced diet: Do not rely on a single food
  2. Diversified choices: Rotate different foods
  3. Moderation principle: Even healthy foods should be consumed in moderation
  4. Professional guidance: Consult a dietitian for special needs

Technical implementation

File location

  • Database: data/food-database.json
  • Category: data/food-categories.json
  • Command: .claude/commands/nutrition.md
  • Skill: .claude/skills/food-database-query/SKILL.md

Performance optimization

  • Database index (food name, category)
  • Cache frequently used queries
  • Fuzzy search optimization

Skill version: v1.0 Last updated: 2026-01-06 Maintainer: WellAlly Tech

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.