Skip to content

feat: migrate general & news search to support Tavily alongside DDG#91

Open
tavily-integrations wants to merge 1 commit into
Somi-Project:masterfrom
Tavily-FDE:feat/tavily-migration/ddg-general-news-search
Open

feat: migrate general & news search to support Tavily alongside DDG#91
tavily-integrations wants to merge 1 commit into
Somi-Project:masterfrom
Tavily-FDE:feat/tavily-migration/ddg-general-news-search

Conversation

@tavily-integrations

Copy link
Copy Markdown

Summary

Adds Tavily as an opt-in, parallel search provider alongside the existing DuckDuckGo paths in general web search, DDG fallback, and news search modules. Tavily is activated only when the TAVILY_API_KEY environment variable is set — existing behavior is fully preserved when the key is absent.

What changed

  • config/settings.py — Added TAVILY_API_KEY config var (read from os.environ, defaults to empty string)
  • requirements.txt — Added tavily-python>=0.5.0,<1.0 dependency
  • generalsearch.py — Added _tavily_text() async helper and _normalize_tavily() normalizer; Tavily results are merged (deduplicated by URL) into the result set before the DDG fallback branch
  • ddg_fallback.py — Added _tavily_search() sync helper; search_ddg() now tries Tavily first when the API key is present, falling through to DDG on failure or missing key
  • news.py — Added _tavily_news() async method and _normalize_tavily_news() normalizer inside NewsHandler; Tavily news runs in parallel with SearXNG via asyncio.gather, with results merged before the DDG news path

Dependency changes

  • Added tavily-python>=0.5.0,<1.0 to requirements.txt

Environment variable changes

  • Added TAVILY_API_KEY — when set to a valid Tavily API key, enables Tavily search; when empty/unset, all existing DDG code paths remain active

Notes for reviewers

  • All existing DDG and SearXNG code paths are untouched — this is purely additive
  • Tavily SDK calls use asyncio.to_thread() since the Python SDK is synchronous
  • The news module runs Tavily and SearXNG concurrently for minimal latency impact
  • No breaking changes; fully backward-compatible when TAVILY_API_KEY is not set

🤖 Generated with Claude Code

Automated Review

  • Passed after 1 attempt(s)
  • Final review: The Tavily migration is additive and correct. All five files are modified as described, the SDK usage is valid, and the opt-in guard (if _TAVILY_API_KEY) ensures zero behavior change when the key is absent. Error handling is consistent (try/except returning []) and imports are lazy, preventing ImportError regressions. Three minor issues found: (1) the Tavily path in generalsearch.py is labeled "parallel" but runs sequentially after SearXNG; (2) import os as _os is placed mid-file; (3) large swaths of whitespace-only diff churn (trailing-space normalization) unrelated to the migration. None of these block approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant