* fix: correct off-by-one in BM25 average document length calculation
In `write_documents`, the average document length formula used
`len(self._bm25_attr)` after the new document was already inserted,
leading to an incorrect calculation:
Before (wrong): (new_len + avg * N) / (N + 1) — where N already includes new doc
After (fixed): (new_len + avg * (N - 1)) / N
This caused _avg_doc_len to be systematically underestimated, which
affects BM25 scoring accuracy (the length normalization term `b *
doc_len / avg_doc_len` would be too large, over-penalizing longer
documents).
The delete path was already correct since it adjusts `len` after
popping from `_bm25_attr`.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: update BM25 tokenization regex to match single char tokens
* Add tests
* update BM25 tokenization regex across multiple retriever tests
* add release note
* Update score values in tests
* Update release note
---------
Co-authored-by: gambletan <tan@echooo.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
* feat: Add ToolSearchToolset for dynamic tool discovery from large catalogs
Implements ToolSearchToolset - a Toolset subclass that enables dynamic tool
discovery from large catalogs. Tools are discovered via `search_tools` bm25
based special search tool and become available to the LLM.
Key features:
- Single discovery mode: "bm25", postpone "embedding" for future
- Passthrough mode for small catalogs (< search_threshold)
- Self-contained BM25L search engine implementation
- Full serialization support (to_dict/from_dict)
- Auto warm-up when iterating to ensure bootstrap tool availability
* fix: Correct misleading search_tools description about return value
The description claimed to return "a JSON array of tool definitions"
but actually returns a plain text confirmation message with tool names.
* fix: Warm up discovered tools before making them available
Tools discovered via search_tools were added to _discovered_tools
without calling warm_up(), causing tools that require initialization
(connections, model loading) to fail when invoked.
* fix: Override __getitem__ to return tools from dynamic iteration
The inherited __getitem__ accessed self.tools which is always empty
in ToolSearchToolset. This caused IndexError for valid indexes even
when tools were available through __iter__.
* fix: Warm up catalog tools in passthrough mode
* feat: Add clear method to reset discovered tools
* docs: Add release note for ToolSearchToolset
* fix: reno note format
* Improve search_tools prompt to elicit tool keywords over user intent
Renamed the `query` parameter to `tool_keywords` and refined the
description to guide LLMs toward providing vocabulary from tool
names/descriptions rather than echoing user requests.
Before: LLMs often passed user intent like "south of france highlights"
After: LLMs provide tool vocabulary like "route weather search"
This improves BM25 matching since it relies on lexical overlap with
indexed tool names and descriptions.
* Rename ToolSearchToolset to SearchableToolset
Rename class and module for clarity:
- tool_search_toolset.py -> searchable_toolset.py
- ToolSearchToolset -> SearchableToolset
- Update all imports, tests, and release notes
* Replace _BM25SearchEngine with InMemoryDocumentStore
Remove the hand-rolled BM25L engine (~107 lines) and delegate to
Haystack's built-in InMemoryDocumentStore.bm25_retrieval(), which
uses the same algorithm and tokenization. Update tests accordingly.
* Use create_tool_from_function for search_tools and test fixtures
Replace manual Tool construction with create_tool_from_function and
Annotated type hints in _create_search_tool. Reduce test duplication
by using create_tool_from_function for fixtures and large_catalog.
Consolidate 4 integration tests into 1 deterministic math test and
remove the redundant integration_catalog fixture.
* Simplify SearchableToolset
* Minor fix
* Add support for lazy toolsets like MCPToolset with lazy flag
* improvements
* fix and simplify
* more unit tests
* amke is_passthrough private
* raise notimplementederror
* improve/simplify serde
* do not mention clear in relnote
---------
Co-authored-by: anakin87 <stefanofiorucci@gmail.com>
* Treat optional types properly during compatibility checks
* Fix unit test
* Add reno
* Use pep 604 union type building
* Refactor and expand tests
* More refactoring and parameterization
* fix: Raise error when async function is passed to Tool
- Added validation in Tool.__post_init__ to check if function is async
- Added validation in create_tool_from_function for early error detection
- Updated docstring to clarify that functions must be synchronous
- Added tests for both Tool init and @tool decorator with async functions
Closes#9580
* fix: Remove redundant async check from create_tool_from_function
Per reviewer feedback, the async validation is only needed in the
Tool class itself, since create_tool_from_function creates a Tool.
- Remove async check from create_tool_from_function
- Update docstrings to remove async-related notes
- Remove redundant tests for async functions in from_function tests
- Add release note
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Add docstring note and tests for async function validation
- Updated Tool class docstring to indicate function must be synchronous
- Added test_from_function_async_raises_error test
- Added test_tool_decorator_async_raises_error test
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
* Update default OpenAI model to gpt-5-mini
* Update tests
* Fix tool invoker tests
* Update integration tests
* Update fragile test
* More robust tests
* Harden test
* More test improvements
* Better prompting, to trigger tools
* Simplify
* Simplify more
* Simplify even more, less maintenance in the future
* Mark two integration tests flaky
* Fixing fine details
* Add release note for OpenAI default model update to gpt-5-mini
* Add upgrade section to OpenAI default model release note
* fix: warm up individual tools inside Toolsets in warm_up_tools()
Related Issues:
* Follows up on PR #9942 (feat: Add warm_up() method to ChatGenerators)
* Addresses bug discovered during implementation of PR #9942 for issue #9907
Proposed Changes:
The warm_up_tools() utility function was only calling warm_up() on
Toolset objects themselves, but not on the individual Tool instances
contained within them. This meant tools inside a Toolset were not
properly initialized before use.
This PR modifies warm_up_tools() to iterate through Toolsets and call
warm_up() on each individual tool, in addition to calling warm_up() on
the Toolset itself.
Changes:
- Modified warm_up_tools() in haystack/tools/utils.py to iterate through
Toolsets when encountered (both as single argument and within lists)
- Added iteration to call warm_up() on each individual Tool inside Toolsets
- Added comprehensive test class TestWarmUpTools with 7 test cases
How did you test it:
- Added 7 comprehensive unit tests in test/tools/test_tools_utils.py:
* test_warm_up_tools_with_none - handles None input
* test_warm_up_tools_with_single_tool - single tool in list
* test_warm_up_tools_with_single_toolset - KEY TEST: verifies both
Toolset and individual tools are warmed
* test_warm_up_tools_with_list_containing_toolset - toolset within list
* test_warm_up_tools_with_multiple_toolsets - multiple toolsets
* test_warm_up_tools_with_mixed_tools_and_toolsets - mixed scenarios
* test_warm_up_tools_idempotency - safe to call multiple times
Notes for the reviewer:
I discovered this bug while implementing PR #9942 (for issue #9907).
When a Toolset object is passed to a component's tools parameter, the
warm_up_tools() function only calls Toolset.warm_up(), which is a no-op.
It doesn't iterate through the individual tools inside the Toolset to
warm them up.
acknowledged by @vblagoje and @sjrl
This implementation:
- Modified warm_up_tools() to iterate through Toolsets and call warm_up() on each individual tool
- Added comprehensive tests for Toolset warming behavior
- Verified both the Toolset and its contained tools are warmed up
Checklist:
I have read the contributors guidelines and the code of conduct
I have updated the related issue with new insights and changes
I added unit tests and updated the docstrings
I've used one of the conventional commit types for my PR title: fix:
I documented my code
I ran pre-commit hooks and fixed any issue
* added release note
* refactor: move tool warm-up iteration to Toolset.warm_up()
Addresses architectural feedback - moved iteration logic from warm_up_tools()
to base Toolset.warm_up() for better encapsulation. Subclasses can now
override warm_up() to customize initialization without breaking the contract.
- Toolset.warm_up() now iterates and warms tools by default
- warm_up_tools() simplified to delegate to warm_up()
- Updated tests and release notes
---------
Co-authored-by: HamidOna13 <abdulhamid.onawole@aizatron.com>
Docker image release / Build base image (push) Has been cancelled
* Tools warmup initial
* Fix lint
* Improve pydocs for warm_up
* Further improve pydocs for warm_up
* No need to warm_up tools in Agent as they are warmed up by ToolInvoker
* Simplify Toolset __add__ logic
* Simplify _ToolsetWrapper
* Add unit tests
* ToolInvoker warm_up
* Improve Tool pydoc
* Resurrect serde_utils.py
* Update tests
* Call ToolInvoker warm_up in agent warm_up
* Lint
* Move warm_up tests to ToolInvoker
* Update tests
* Remove tests
* Pydoc nit
* PR feedback
* ToolInvoker's warm_up is idempotent
* Add reno note
* Update releasenotes/notes/tools-warm-up-support-e16cc043fed3653f.yaml
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>
* Make ComponentTool warm_up idempotent
* Update warm_up_tools to use ToolsType
* Linting
* Add warm up test for mixed list of Tool/Toolset instances
---------
Co-authored-by: Sebastian Husch Lee <10526848+sjrl@users.noreply.github.com>