Skip to content

Conversation

albertvillanova
Copy link
Member

Implement rate limit mechanism in DuckDuckGoSearchTool.

Follow-up to:

Fix #1501.

@@ -104,9 +104,12 @@ class DuckDuckGoSearchTool(Tool):
inputs = {"query": {"type": "string", "description": "The search query to perform."}}
output_type = "string"

def __init__(self, max_results=10, **kwargs):
def __init__(self, max_results=10, rate_limit: float | None = 1.0, **kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

So the default rate limit will be to wait 1s between calls, not 0?

Copy link
Member Author

@albertvillanova albertvillanova Jul 3, 2025

Choose a reason for hiding this comment

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

Apparently, users reported they get a rate limit error: see the associated issue:

However, I don't know what the exact value of the rate limit implemented on the DuckDuckGo Search side is. I tried this value, but we could tweak it if users have a better guess.

@aymeric-roucher
Copy link
Collaborator

@albertvillanova maybe it would be worth switching to rate limit per minute to conform with what we use for models?

@albertvillanova
Copy link
Member Author

albertvillanova commented Jul 4, 2025

@aymeric-roucher thanks for the suggestion.

I think using a rate limit expressed in queries per second is more widely used in the case of web search APIs, since their resource usage is generally lower than that of model inference. This makes finer-grained control via per-second limits more appropriate.

While we do not have the exact information for DuckDuckGo, Brave Search API documents their rate limits in queries per second: https://brave.com/search/api/

Free plan: 1 query/second
Base Plan: 20 queries/second
Pro Plan: 50 queries/second

To make this explicit and reduce ambiguity, maybe I could rename the parameter rate_limit to queries_per_second.
Let me know what you think and I can do it for both web search tools in a subsequent PR.
Alternatively, I could add a docstring to explain that rate_limit value is queries per second.

@albertvillanova albertvillanova merged commit 40ddff6 into huggingface:main Jul 4, 2025
3 checks passed
@albertvillanova albertvillanova deleted the duckduckgo-search-rate-limit branch July 4, 2025 08:51
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.

Add robust error handling for duckduckgo_search.RatelimitException-HTTP-202
2 participants