@@ -84,6 +84,8 @@ class ToolRagAlgorithm(Algorithm):
8484 - max_document_size: the maximal size, in characters, of a single indexed document, or None to disable the size limit.
8585 - indexed_tool_def_parts: the parts of the MCP tool definition to be used for index construction, such as 'name',
8686 'description', 'args', etc.
87+ You can also include 'additional_queries' (or 'examples') to append example queries for each tool if provided
88+ via the 'additional_queries' setting (see defaults below).
8789 - hybrid_mode: True to enable hybrid (sparse + dense) search and False to only enable dense search.
8890 - analyzer_params: parameters for the Milvus BM25 analyzer.
8991 - fusion_type: the algorithm for combining the dense and the sparse scores if hybrid mode is activated. Milvus only
@@ -128,7 +130,8 @@ def get_default_settings(self) -> Dict[str, Any]:
128130 "embedding_model_id" : "all-MiniLM-L6-v2" ,
129131 "similarity_metric" : "COSINE" ,
130132 "index_type" : "FLAT" ,
131- "indexed_tool_def_parts" : ["name" , "description" ],
133+ "indexed_tool_def_parts" : ["name" , "description" , "additional_queries" ],
134+
132135
133136 # preprocessing
134137 "text_preprocessing_operations" : None ,
@@ -232,6 +235,14 @@ def _compose_tool_text(self, tool: BaseTool) -> str:
232235 tags = tool .tags or []
233236 if tags :
234237 segments .append (f"tags: { ' ' .join (tags )} " )
238+ elif p .lower () == "additional_queries" :
239+ # Append example queries supplied via settings["additional_queries"][tool.name]
240+ examples_map = self ._settings .get ("additional_queries" ) or {}
241+ examples_list = examples_map .get (tool .name ) or []
242+ if examples_list :
243+ rendered = self ._render_examples (examples_list )
244+ if rendered :
245+ segments .append (f"ex: { rendered } " )
235246
236247 if not segments :
237248 raise ValueError (f"The following tool contains none of the fields listed in indexed_tool_def_parts:\n { tool } " )
@@ -249,7 +260,7 @@ def _create_docs_from_tools(self, tools: List[BaseTool]) -> List[Document]:
249260 documents .append (Document (page_content = page_content , metadata = {"name" : tool .name }))
250261 return documents
251262
252- def _index_tools (self , tools : List [BaseTool ]) -> None :
263+ def _index_tools (self , tools : List [BaseTool ], queries : List [ QuerySpecification ] ) -> None :
253264 self .tool_name_to_base_tool = {tool .name : tool for tool in tools }
254265
255266 self .embeddings = HuggingFaceEmbeddings (model_name = self ._settings ["embedding_model_id" ])
@@ -308,7 +319,7 @@ def _index_tools(self, tools: List[BaseTool]) -> None:
308319 search_params = search_params ,
309320 )
310321
311- def set_up (self , model : BaseChatModel , tools : List [BaseTool ]) -> None :
322+ def set_up (self , model : BaseChatModel , tools : List [BaseTool ], queries : List [ QuerySpecification ] ) -> None :
312323 super ().set_up (model , tools )
313324
314325 if self ._settings ["cross_encoder_model_name" ]:
@@ -320,7 +331,34 @@ def set_up(self, model: BaseChatModel, tools: List[BaseTool]) -> None:
320331 if self ._settings ["enable_query_decomposition" ] or self ._settings ["enable_query_rewriting" ]:
321332 self .query_rewriting_model = self ._get_llm (self ._settings ["query_rewriting_model_id" ])
322333
323- self ._index_tools (tools )
334+ # Build additional_queries mapping from provided QuerySpecifications so YAML is not required.
335+ try :
336+ tool_examples : Dict [str , List [str ]] = {}
337+ for spec in (queries or []):
338+ add_q = getattr (spec , "additional_queries" , None ) or {}
339+ # Flatten wrapper {"additional_queries": {...}} if present
340+ if isinstance (add_q , dict ) and "additional_queries" in add_q and len (add_q ) == 1 :
341+ add_q = add_q ["additional_queries" ]
342+ for tool_name , qmap in add_q .items ():
343+ if isinstance (qmap , dict ):
344+ for _ , qtext in qmap .items ():
345+ if isinstance (qtext , str ) and qtext .strip ():
346+ tool_examples .setdefault (tool_name , []).append (qtext .strip ())
347+ # Dedupe while preserving order
348+ for k , v in list (tool_examples .items ()):
349+ seen = set ()
350+ deduped = []
351+ for s in v :
352+ if s not in seen :
353+ seen .add (s )
354+ deduped .append (s )
355+ tool_examples [k ] = deduped
356+ if tool_examples :
357+ self ._settings ["additional_queries" ] = tool_examples
358+ except Exception :
359+ pass
360+
361+ self ._index_tools (tools , queries )
324362
325363 def _threshold_results (self , docs_and_scores : List [Tuple [Document , float ]]) -> List [Document ]:
326364 """
0 commit comments