Add semantic YMYL classification via LLM extraction#16
Merged
Conversation
Two-stage YMYL pipeline:
- Stage 1 (fast): Regex strong patterns for definitive matches
(blood type, 401k, DNR order). No LLM call needed.
- Stage 2 (smart): LLM classifies YMYL during fact extraction.
Zero additional API calls (piggybacks on existing extraction).
Catches implied YMYL ("my chest hurts") and rejects metaphorical
usage ("bank of the river").
Changes:
- Add ymyl_category field to Fact, ActionItem, and Memory models
- Update extraction prompt to ask LLM for ymyl_category per fact
- Thread ymyl_category through resolver -> pipeline -> metadata
- Scoring uses stored ymyl_category for decay immunity (falls back
to regex for memories created before this change)
- 8 new tests for semantic YMYL classification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two-stage YMYL pipeline that catches implied health/legal/financial content and rejects false positives from metaphorical keyword usage.
Stage 1 (fast): Regex strong patterns for definitive matches (blood type, 401k, DNR order). No LLM call.
Stage 2 (smart): LLM classifies YMYL during fact extraction. Zero additional API calls; the classification piggybacks on the extraction call that already happens for every add().
What it catches that regex misses
What it skips that regex falsely flags
Files changed
core/types.py- Addymyl_categoryto Fact, ActionItem, Memoryextraction/prompts.py- Updated extraction prompt with YMYL examplesextraction/llm_extractor.py- Two-stage: regex override + LLM classificationconflict/batch_resolver.py- Thread ymyl_category through actionscore/pipeline.py- Store ymyl_category in metadata, use in YMYL-triggered active retrievalcore/memory.py- Reconstruct ymyl_category from metadata at search timeretrieval/temporal.py- Use stored ymyl_category for decay immunitytests/test_ymyl_topics.py- 8 new testsTest plan