feat: extract and persist Findings from ToolResults (FactStore Phase 2)#166
Open
luceinaltis wants to merge 2 commits into
Open
feat: extract and persist Findings from ToolResults (FactStore Phase 2)#166luceinaltis wants to merge 2 commits into
luceinaltis wants to merge 2 commits into
Conversation
Phase 2 of the FactStore: discrete Finding records are now extracted from successful ToolResult.data dicts and persisted alongside theses, enabling ticker-based recall of past insights without relying on free-text search. - FactStore schema gains a `findings` table + index on entity, plus `save_finding()` / `get_findings()` CRUD (confidence is clamped to [0,1] at the store boundary so noisy extractor inputs are tolerated). - New `qracer/memory/finding_extractor.py` parses `trade_thesis`, `news`, and `fundamentals` ToolResults into `FindingDraft` records. Zero LLM cost — structured data only. Failed results, unknown tools, and extractor exceptions all yield [] so a bad payload never breaks the persistence pipeline. - `ConversationEngine._persist_facts` loops over analysis.results and persists every extracted draft; per-draft exceptions are isolated so one bad tool doesn't block findings from siblings. - Tests: 6 new CRUD tests on FactStore, 14 extractor tests covering failure paths, sentiment-weighted confidence, article cap, and partial-fundamentals fallback.
Fixes CI code-quality check failure — ruff format wanted to collapse a two-line call in test_missing_catalyst_skips onto one line.
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
Closes #157.
Phase 2 of
FactStore: thefindingstable sketched in Phase 1 is now populated. DiscreteFindingrecords are extracted from every successfulToolResult.datadict inConversationEngine._persist_factsand persisted alongside theses, so ticker-based recall (e.g. "what did we learn about AAPL's earnings last time?") no longer depends on free-text search.What changed
qracer/memory/fact_store.py— newfindingstable +idx_findings_entityindex, plussave_finding()/get_findings()CRUD. Confidence is clamped to[0.0, 1.0]at the store boundary so noisy extractor inputs don't corrupt the schema.qracer/memory/finding_extractor.py— new module.extract_findings(ToolResult) -> list[FindingDraft]with dedicated zero-LLM-cost extractors fortrade_thesis,news, andfundamentals. Unknown tools, failed results, and extractor exceptions all yield[]so a bad payload can never break the persistence pipeline.qracer/conversation/engine.py—_persist_factsnow iterates over everyanalysis.resultsentry and persists each extracted draft; per-draft failures are isolated so one bad tool doesn't prevent siblings being saved.Non-goals (per the issue)
UserPreferenceextraction is out-of-scope (Phase 3).Test plan
uv run pytest tests/memory/test_fact_store.py tests/memory/test_finding_extractor.py— 35 tests covering Finding CRUD (save, clamp, filter, order, limit, event_date) and extractor behaviour (failure paths, sentiment-weighted confidence, article cap, partial fundamentals, missing-ticker guards).uv run pytestfull suite — 798 passed, 14 skipped.uv run ruff check— clean.uv run pyright qracer/memory/finding_extractor.py qracer/memory/fact_store.py qracer/conversation/engine.py— 0 errors.Manual verification