feat: Add automatic retry with simpler query for sparse Reddit results

If initial search returns <5 threads, extract core subject and retry:
- "best nano banana prompting practices" → retry with "nano banana"
- Combines results from both searches, deduped by URL

Note: OpenAI's web_search still tends to find old content. This retry
helps cast a wider net but doesn't fully solve the recency issue.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn
2026-01-25 10:44:29 -08:00
parent 2d43571875
commit e1d3570667
2 changed files with 32 additions and 0 deletions
+21
View File
@@ -120,6 +120,27 @@ def run_research(
# Parse response
reddit_items = openai_reddit.parse_reddit_response(raw_openai)
# Quick retry with simpler query if few results
if len(reddit_items) < 5 and not mock:
core = openai_reddit._extract_core_subject(topic)
if core.lower() != topic.lower():
try:
retry_raw = openai_reddit.search_reddit(
config["OPENAI_API_KEY"],
selected_models["openai"],
core,
from_date, to_date,
depth=depth,
)
retry_items = openai_reddit.parse_reddit_response(retry_raw)
# Add items not already found (by URL)
existing_urls = {item.get("url") for item in reddit_items}
for item in retry_items:
if item.get("url") not in existing_urls:
reddit_items.append(item)
except Exception:
pass
if progress:
progress.end_reddit(len(reddit_items))