Back to Blocks
PXL-826Running
Urgent

🎀 Voice logging quality improvements (parsing & matching)

Labels
1-circesearchvoiceImprovement

What we're solving:

When you use voice or text logging to quickly log your meals, the app should understand common foods correctly. There are two critical issues preventing reliable food matching:

  1. ●Food Matching Bug: The search algorithm returns incorrect matchesβ€”for example, typing "butter" matches "butterfish" instead of actual butter, and "blueberries" doesn't find anything even though blueberries exist in the database.
  2. ●Natural Language Parsing: The parser doesn't understand conversational input patterns like "half a cup", "medium apple", or "one and a half cups".

This task fixes both issues to ensure voice logging feels natural and reliable.


Part 1: Fix Food Matching Algorithm (from PXL-826)

Bug Summary

The voice and text logging feature has critical food matching issues where common, everyday foods are not being matched correctly. The semantic search/embedding system appears to be returning semantically similar but incorrect matches, while overlooking exact or near-exact text matches.

Reproduction Steps

Issue 1: Incorrect Match for "butter"

  1. ●Open voice or text logging
  2. ●Say or type "1 tablespoon of butter"
  3. ●Expected: Matches "Butter" or "Butter, salted" or similar butter entry
  4. ●Actual: Matches "Butterfish, raw" - completely wrong food item

Issue 2: No Match for "blueberries"

  1. ●Open voice or text logging
  2. ●Say or type "1 cup of blueberries"
  3. ●Expected: Matches "Blueberries, Raw" which exists in the database
  4. ●Actual: No match found for "Blueberry"

Technical Analysis

This appears to be a search/matching algorithm issue with the following potential root causes:

Likely Causes to Investigate:

  1. ●Embedding Quality Issues
    • ●The embeddings may not be properly weighting exact or near-exact text matches
    • ●"Butterfish" may be semantically closer to "butter" in the embedding space than actual "butter"
    • ●Singular/plural variations ("Blueberry" vs "Blueberries") may not be handled
  2. ●Search Algorithm Issues
    • ●The matching algorithm may rely too heavily on semantic similarity without a text-matching boost
    • ●No fuzzy matching or stemming for singular/plural forms
    • ●Missing a "prefer exact match" or "prefer substring match" heuristic
  3. ●Data Issues
    • ●Verify that "Butter" and "Blueberries, Raw" exist in the database with proper embeddings
    • ●Check if embeddings were generated correctly for these common foods

Suggested Investigation Areas

  • ●Review the food matching/search implementation in the voice logging flow
  • ●Check how embeddings are generated and stored
  • ●Investigate adding a hybrid search approach:
    • ●Text/fuzzy matching for exact/near-exact matches
    • ●Semantic search as a fallback
    • ●Boost scores for exact substring matches
  • ●Consider implementing stemming or lemmatization for word variations

Impact

High - This bug affects core functionality of voice logging, which is a primary feature for quick food entry. Users cannot reliably log common foods like "butter" and "blueberries", which significantly degrades the user experience.


Part 2: Enhance Natural Language Parsing (from PXL-825)

Overview

Enhance the voice logging feature's natural language parsing capabilities to support more conversational and varied input patterns. Currently, the parser handles basic quantity + unit + food patterns, but users naturally speak in more complex ways that need to be supported for a seamless logging experience.

Problem Statement

Users attempting to log food via voice encounter parsing failures or incorrect interpretations when using common natural language patterns such as:

  • ●Fractional words ("half", "quarter")
  • ●Compound quantities ("one and a half")
  • ●Decimal numbers as words ("five point three")
  • ●Size descriptors without units ("medium apple")
  • ●Percentages in food names ("two percent milk")
  • ●Brand names as identifiers ("quest bar")

Technical Requirements

1. Fraction Word Recognition

  • ●Parse "half" as 0.5 (e.g., "half a cup" β†’ 0.5 cups)
  • ●Parse "quarter" as 0.25 (e.g., "quarter cup" β†’ 0.25 cups)
  • ●Handle optional articles ("half a cup" vs "half cup")

2. Compound Quantity Parsing

  • ●Support "X and a half" patterns (e.g., "one and a half cups" β†’ 1.5 cups)
  • ●Support "X and a quarter" patterns
  • ●Handle standalone fractions ("one and a half" without units for countable items)

3. Decimal Number Words

  • ●Parse "point" as decimal separator (e.g., "five point three" β†’ 5.3)
  • ●Support single decimal place patterns common in nutrition (e.g., "five point three ounces")

4. Unit-less Quantities with Size Descriptors

  • ●Recognize size words: "small", "medium", "large"
  • ●Apply to countable foods (e.g., "one medium apple", "one medium banana")
  • ●Map size descriptors to appropriate serving size multipliers in food database lookups

5. Percentage in Food Names

  • ●Preserve percentage words as part of food name (e.g., "two percent milk" β†’ food: "2% milk" or "two percent milk")
  • ●Distinguish between quantity percentages and food name percentages contextually

6. Brand Name Support

  • ●Recognize brand names as valid food identifiers
  • ●Handle brand + product patterns (e.g., "quest bar chocolate chip")
  • ●Support fuzzy matching against food database for branded items

7. Complex Compound Phrases

  • ●Parse multi-item phrases with "with" connector (e.g., "coffee with two tablespoons of half and half")
  • ●Handle the special case where "half and half" is a food name, not a fraction

Test Scenarios

The implementation must correctly parse all of the following scenarios:

Breakfast

InputExpected QuantityExpected UnitExpected Food
"Two scrambled eggs"2countscrambled eggs
"Two slices of whole wheat toast"2sliceswhole wheat toast
"One tablespoon of butter"1tablespoonbutter
"Half a cup of blueberries"0.5cupblueberries
"Twelve ounces of coffee with two tablespoons of half and half"12 oz coffee + 2 tbsp half and half*

| (compound) |

Lunch

InputExpected QuantityExpected UnitExpected Food
"Six ounce grilled chicken breast"6ouncegrilled chicken breast
"Two cups of mixed greens"2cupsmixed greens
"Quarter cup of cherry tomatoes"0.25cupcherry tomatoes
"Two tablespoons of olive oil and vinegar dressing"2tablespoonsolive oil and vinegar dressing
"One medium apple"1mediumapple
"Sixteen ounces of water"16ounceswater

Snack

InputExpected QuantityExpected UnitExpected Food
"One ounce of almonds"1ouncealmonds
"One medium banana"1mediumbanana
"Greek yogurt, five point three ounces"5.3ouncesGreek yogurt

Dinner

InputExpected QuantityExpected UnitExpected Food
"Eight ounces of salmon"8ouncessalmon
"One cup of brown rice"1cupbrown rice
"One and a half cups of steamed broccoli"1.5cupssteamed broccoli
"One teaspoon of sesame oil"1teaspoonsesame oil
"Twelve ounces of sparkling water"12ouncessparkling water

Quick Logging (Mixed Items)

InputExpected Parsing
"Peanut butter sandwich with two tablespoons of peanut butter"Compound: sandwich + 2 tbsp peanut butter
"One cup of two percent milk"1 cup, food: "2% milk"
"Protein bar, quest bar chocolate chip"1 count, food: "Quest Bar Chocolate Chip"

Implementation Notes

  • ●Review existing parsing logic in NutriKit/Voice/ directory
  • ●Key files likely affected: TextLoggingScreen.swift, VoiceLoggingScreen.swift, ParsedFoodRow.swift, VoiceEditSheets.swift
  • ●Consider using a tokenizer approach that identifies quantity tokens, unit tokens, and food name tokens
  • ●May need to maintain a dictionary of fraction words and their numeric equivalents
  • ●Size descriptors (small/medium/large) should be treated as special unit types
  • ●Consider edge cases where food names contain words that could be misinterpreted as quantities

Combined Acceptance Criteria

Food Matching Fix:

  • ● "1 tablespoon of butter" correctly matches a butter food entry (not butterfish)
  • ● "1 cup of blueberries" correctly matches "Blueberries, Raw" or equivalent
  • ● Singular/plural variations of food names match appropriately
  • ● Exact or near-exact text matches prioritized over purely semantic matches
  • ● Add unit tests for common food matching scenarios

Parsing Enhancements:

  • ● All test scenarios in the tables above parse correctly
  • ● Existing voice logging functionality remains intact (no regressions)
  • ● Parser gracefully handles ambiguous inputs with reasonable defaults
  • ● Unit tests cover all new parsing patterns
  • ● Performance remains acceptable (parsing should be near-instantaneous)

Integration:

  • ● Both fixes work seamlessly together
  • ● Users can now reliably voice log with natural language patterns
  • ● Food matching is accurate for common foods

Out of Scope

  • ●Multi-language parsing (English only for this iteration)
  • ●Learning user-specific food preferences (parsing enhancements only)

Build instruction: Use -destination 'platform=iOS Simulator,name=iPhone 17 Pro' when building this project

Comments (1)

Ahmed Khalaf
Ahmed KhalafJan 1, 2026, 10:19 PM

Additional Cases Reported

Two more examples of incorrect food matching:

InputAmount ParsedMatched FoodExpected
"2 cups of steamed broccoli"βœ… 2 cups (correct)❌ "O's MΓΌsli, OREO"Broccoli
"1 tablespoon of sesame oil"βœ… 1 tablespoon (correct)❌ "O's MΓΌsli, OREO"Sesame oil

Note: The amount parsing is working correctly in both cases, but both queries are matching to the same completely unrelated food ("O's MΓΌsli, OREO"). This suggests the search/embedding matching has a more fundamental issue than just preferring similar-sounding foods.

Created Jan 1, 2026, 10:17 PM Β· Updated Jan 6, 2026, 1:01 PM