Skip to main content

A Haystack component integrating Duckduckgo API for WebSearch

Project description

DuckduckgoApiWebSearch

Haystack component to use Websearch via the freely available Duckduckgo API.


Table of Contents

Installation

pip install duckduckgo-api-haystack

Overview

This repository implements a module in the style of SearchApiWebSearch and SerperDevWebSearch, but using the freely-available duckduckgo API.

When you give DuckduckgoWebSearch a query, it returns a list of the URLs most relevant to your search. It uses page snippets (pieces of text displayed under the page title in search results) to find the answers, not the whole pages.

Basic Usage

Here's a simple example of how to use the DuckduckgoApiWebSearch component:

from duckduckgo_api_haystack import DuckduckgoApiWebSearch

# Create an instance of DuckduckgoApiWebSearch
websearch = DuckduckgoApiWebSearch(top_k=3)

# Perform a search
results = websearch.run(query="What is frico?")

# Access the search results
documents = results["documents"]
links = results["links"]

print("Found documents:")
for doc in documents:
    print(f"Content: {doc.content}")
    print("\n\n")

print("Search Links:")
for link in links:
    print(link)

Configuration Parameters

The DuckduckgoApiWebSearch component accepts several parameters to customize its behavior:

  • top_k (int, optional): Maximum number of documents to return (default: 10).
  • max_results (int, optional): Maximum number of documents to consider in the search (default: 10).
  • region (str): Search region (default: "wt-wt" for worldwide).
  • safesearch (str): SafeSearch setting ("on", "moderate", or "off"; default: "moderate").
  • timelimit (str, optional): Time limit for search results (e.g., "d" for day, "w" for week, "m" for month).
  • backend (str): Search backend to use ("api", "html", or "lite"; default: "api").
  • allowed_domain (str): Restrict search to a specific domain (default: "").
  • timeout (int): Timeout for each search request in seconds (default: 10).
  • use_answers (bool): Include DuckDuckGo's answer box in results (default: False).
  • proxy (str, optional): Web address to use as a proxy.
  • max_search_frequency (float, optional): Minimum time in seconds between searches (defaults to no limit)

Remark: The difference between top_k and max_results is that, if use_answers is True, then the number of answers and pages is considered together and only the top_k are then used. Otherwise they work in the same way.

The top_k and max_results parameters serve different purposes:

max_results: This parameter determines the maximum number of search results to retrieve from DuckDuckGo. top_k: This parameter limits the number of results returned by the component.

The interaction between these parameters depends on the use_answers setting:

  • use_answers=False: The component retrieves up to max_results search results.
  • use_answers=True: The component returns the top_k results from a list containing answers and search results.

License

duckduckgo-api-websearch is distributed under the terms of the Apache-2.0 license.

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

duckduckgo_api_haystack-0.1.13.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

duckduckgo_api_haystack-0.1.13-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file duckduckgo_api_haystack-0.1.13.tar.gz.

File metadata

File hashes

Hashes for duckduckgo_api_haystack-0.1.13.tar.gz
Algorithm Hash digest
SHA256 cc4aad20c40c9eda62fa5c290cda5cb4aa9c0c7e088b359557dee277fa03cf2a
MD5 a759e601aff5dc08adffeb9898e30b21
BLAKE2b-256 d5a47b7d18a735a46521465482a6368478df886aa61209f53abd2c38255bdd33

See more details on using hashes here.

File details

Details for the file duckduckgo_api_haystack-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for duckduckgo_api_haystack-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 2b5bbc0101d16264104a5ae65f64ebe31f46f5a298ee949623a4f52d40b266f6
MD5 4b31a22fff5dee7b336890964b12a469
BLAKE2b-256 1a39d7dc95511642238720684a8ff12de4810dc7e8d18d9bd01f5e77636a502d

See more details on using hashes here.

Supported by

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