Skip to content

feat(brave): add BraveWebSearch integration#3237

Merged
anakin87 merged 8 commits into
deepset-ai:mainfrom
SyedShahmeerAli12:feat/brave-search-integration
May 6, 2026
Merged

feat(brave): add BraveWebSearch integration#3237
anakin87 merged 8 commits into
deepset-ai:mainfrom
SyedShahmeerAli12:feat/brave-search-integration

Conversation

@SyedShahmeerAli12
Copy link
Copy Markdown
Contributor

@SyedShahmeerAli12 SyedShahmeerAli12 commented Apr 27, 2026

Related Issues

Proposed Changes:

Adds BraveWebSearch, a new Haystack component that wraps the Brave Search API.

Follows the same structure as the existing TavilyWebSearch integration:

  • run() for sync usage, run_async() for async usage (both via httpx)
  • Returns documents (content = result description) and links (result URLs)
  • top_k, country, search_lang, and extra_params configurable at init time
  • Per-run top_k override supported

API response mapping:
Brave Search returns results under web.results. Each result's description becomes the Document content, with title and url stored in meta.

How did you test it?

11 unit tests covering:

  • Default and custom init parameters
  • Serialization round-trip (to_dict / from_dict)
  • run() returns correct documents and links
  • Correct query parameters forwarded to the API (count, country, search_lang)
  • Per-run top_k override
  • Async run_async() returns correct results
  • Empty results and missing web key handled gracefully
  • HTTP errors propagated correctly

2 integration tests skipped unless BRAVE_API_KEY is set.

Notes for the reviewer

Uses httpx (sync Client for run(), AsyncClient for run_async()) rather than a dedicated SDK, since Brave Search has no official Python client. httpx is a well-maintained library already used widely in the Python ecosystem.

Checklist

Implements BraveWebSearch component for Haystack using the Brave Search
API. Follows the same structure as TavilyWebSearch.

- sync run() and async run_async() via httpx
- top_k, country, search_lang, extra_params configuration
- per-run top_k override
- returns documents (content = description) and links
- 11 unit tests, 2 integration tests (skipped without API key)

Closes deepset-ai#3236
@SyedShahmeerAli12 SyedShahmeerAli12 requested a review from a team as a code owner April 27, 2026 11:50
@SyedShahmeerAli12 SyedShahmeerAli12 requested review from anakin87 and removed request for a team April 27, 2026 11:50
@github-actions github-actions Bot added the type:documentation Improvements or additions to documentation label Apr 27, 2026
@SyedShahmeerAli12
Copy link
Copy Markdown
Contributor Author

Hey @anakin87 all CI checks are now passing (including the API reference build). Whenever you have a chance to review, that would be great!

Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left two initial comments.

Have you run yourself tests using the Brave API key?

Comment thread integrations/brave/CHANGELOG.md Outdated
Comment thread integrations/brave/README.md
@SyedShahmeerAli12
Copy link
Copy Markdown
Contributor Author

Left two initial comments.

Have you run yourself tests using the Brave API key?

umm no let me address the comments then check via Brave Api key , would you refer me the documention so it would be easy for me too..

@SyedShahmeerAli12
Copy link
Copy Markdown
Contributor Author

SyedShahmeerAli12 commented Apr 28, 2026

Hey @anakin87 I tried to get a Brave API key for testing, but Brave has removed their free tier as of late 2025 and now requires a credit card for the $5/month metered plan. Would it be possible to verify the integration tests via a CI secret, or would you like me to proceed another way? The integration tests are already gated with @pytest.mark.skipif(not os.environ.get("BRAVE_API_KEY"), ...) so they won't affect CI.

@anakin87
Copy link
Copy Markdown
Member

Hey @anakin87 I tried to get a Brave API key for testing, but Brave has removed their free tier as of late 2025 and now requires a credit card for the $5/month metered plan. Would it be possible to verify the integration tests via a CI secret, or would you like me to proceed another way? The integration tests are already gated with @pytest.mark.skipif(not os.environ.get("BRAVE_API_KEY"), ...) so they won't affect CI.

I'll proceed with review and testing when I have some time.

For the future, I'd like to invite you to only contribute to integrations you can test completely locally.

Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests pass but:

  1. .github/workflows/brave.yml - no CI workflow exists
  2. .github/labeler.yml - no integration:brave label rule
  3. .github/workflows/CI_coverage_comment.yml - brave isn't registered. Add it.
  4. Root README.md - brave isn't listed in the integrations table.

- Add .github/workflows/brave.yml CI workflow
- Register 'Test / brave' in CI_coverage_comment.yml
- Add integration:brave label rule to labeler.yml
- Fix README.md: remove stale CHANGELOG link
- Add brave-search-haystack row to root README table
Comment thread README.md Outdated
Comment thread integrations/brave/README.md Outdated
- Fix broken doc links: api.search.brave.com -> api-dashboard.search.brave.com
- Add timeout and max_retries params to BraveWebSearch.__init__()
- Replace httpx.Client/AsyncClient with request_with_retry/async_request_with_retry
- Update tests to mock request_with_retry instead of httpx directly
- Restore CHANGELOG link in README.md (keep this)
- Fix alphabetical order of brave row in root README.md
Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two final comments.

I'd invite you, if you use code agents, to review their outputs yourself before committing.

Copy link
Copy Markdown
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added license.

Merging now

@anakin87 anakin87 merged commit 9d93d0f into deepset-ai:main May 6, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:CI type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants