BM25Search#
Build extensions, choose hooks, and manage request-scoped state. See the guide.
- class zett_agent.extensions.tool_search.BM25Search(tools, *, limit=20, min_score=0.0, k1=1.5, b=0.75)[源代码]#
Rank a set of tools with BM25 over their names and descriptions.
Every model-facing text of a tool is indexed: its name (split on
_), its description, its parameter descriptions from the input schema, its snippet, and its guidelines. Terms that appear in no document score zero, so a query that matches nothing returns an empty list. Ties keep tool order, andlimitcaps how many definitions one search sends back.The catalog is fixed at construction, so term counts, document frequencies, and the average document length are computed once and reused by every search.
- 参数:
tools (Sequence[AgentTool]) -- Tools this index may return.
limit (int) -- Maximum number of tools to return.
min_score (float) -- Minimum BM25 score a tool must exceed to be returned.
k1 (float) -- Term-frequency saturation.
b (float) -- Length-normalization strength.
示例
Rank a catalog for one query:
matches = BM25Search([warehouse_stock, billing_lookup]).search(["warehouse stock"])