Skip to main content

A Haystack component for web search via the Brave Search API

Project description

haystack-brave-search

PyPI version Python versions License: MIT

A Haystack component for web search using the Brave Search API.

Installation

pip install haystack-brave-search

Requirements

  • Python 3.12+
  • A Brave Search API key

Usage

Standalone

from haystack_brave_search import BraveWebSearch

searcher = BraveWebSearch(api_key="your-api-key", top_k=5, country="BE", language="en")
result = searcher.run(query="Haystack AI framework")

for doc in result["documents"]:
    print(doc.meta["title"])
    print(doc.meta["url"])
    print(doc.content)

In a Haystack Pipeline

from haystack import Pipeline
from haystack.components.builders import PromptBuilder
from haystack_brave_search import BraveWebSearch

prompt_template = """
Given the following search results:
{% for doc in documents %}
- {{ doc.meta.title }}: {{ doc.content }}
{% endfor %}

Answer the question: {{ query }}
"""

pipe = Pipeline()
pipe.add_component("search", BraveWebSearch(api_key="your-api-key", top_k=5))
pipe.add_component("prompt", PromptBuilder(template=prompt_template))

pipe.connect("search.documents", "prompt.documents")

result = pipe.run({
    "search": {"query": "What is RAG?"},
    "prompt": {"query": "What is RAG?"}
})

print(result["prompt"]["prompt"])

With AsyncPipeline

from haystack import AsyncPipeline
from haystack_brave_search import BraveWebSearch

pipe = AsyncPipeline()
pipe.add_component("search", BraveWebSearch(api_key="your-api-key", top_k=5))

Parameters

Parameter Type Default Description
api_key str required Your Brave Search API key
top_k int 5 Number of results to return
country str None Country code to localise results (e.g. "BE", "GR")
language str None Language code for search results using ISO 639-1 (e.g. "en", "el", ...)

Output

The run() method returns a dict with a documents key containing a list of Haystack Document objects:

  • document.content — snippet/description of the result

  • document.meta["title"] — page title

  • document.meta["url"] — page URL

Environment Variable

You can avoid hardcoding the API key by using an environment variable:

import os
from haystack_brave_search import BraveWebSearch

searcher = BraveWebSearch(api_key=os.environ["BRAVE_API_KEY"])

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haystack_brave_search-0.1.2.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haystack_brave_search-0.1.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file haystack_brave_search-0.1.2.tar.gz.

File metadata

  • Download URL: haystack_brave_search-0.1.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for haystack_brave_search-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2d8ce5c255e8f08d42446456b62eb027f71252b3da4f1ea584ac836ad5088428
MD5 cc22208a5e824a2e57293a90057d5b45
BLAKE2b-256 6d7e40f293b6f0c1dcfc276613ba7eaff7af9a27325f97f634f9389dcca61f61

See more details on using hashes here.

File details

Details for the file haystack_brave_search-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: haystack_brave_search-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for haystack_brave_search-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c950a20af69e819d45256a450183c98ebca11a632f7f4a2aab0c62e62d48456
MD5 f18e6315488bdbb282532b017b3b1ecf
BLAKE2b-256 c8b8dc0247fd9d2c577888b9a4bd20fde46fcc2dbd28a6dee8700a25ba14408b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page