fix: Prevent llm.search from returning huge object lists in list mode

When llm.search is called with an empty query (list mode) to retrieve all
available questions, include_objects=true was returning full object schemas
for all related objects, resulting in massive responses that could fill the
LLM's context and cause rejections.

Fix: include_objects now only works when query is non-empty (search mode).
When query is empty (list mode), only question templates are returned
without object details, regardless of include_objects setting.

This makes semantic sense:
- Empty query = "list all questions" → just titles/bodies (compact)
- Non-empty query = "search for specific questions" → full details including
  object schemas (for answering the question)

Changes:
- Modified fts_search_llm() to check !query.empty() before fetching objects
- Updated tool schema description to clarify this behavior
pull/5318/head
Rene Cannao 1 month ago
parent ba6cfdc8bd
commit ee74384c79

@ -2003,13 +2003,14 @@ std::string Discovery_Schema::fts_search_llm(
}
delete resultset;
// If include_objects, fetch object details
if (include_objects) {
proxy_error("FTS search: include_objects=%d, objects_to_fetch size=%zu\n", include_objects ? 1 : 0, objects_to_fetch.size());
// If include_objects AND query is not empty (search mode), fetch object details
// For list mode (empty query), we don't include objects to avoid huge responses
if (include_objects && !query.empty()) {
proxy_info("FTS search: include_objects=true (search mode), objects_to_fetch size=%zu\n", objects_to_fetch.size());
}
if (include_objects && !objects_to_fetch.empty()) {
proxy_info("FTS search: include_objects=true, objects_to_fetch size=%zu\n", objects_to_fetch.size());
if (include_objects && !query.empty() && !objects_to_fetch.empty()) {
proxy_info("FTS search: Fetching object details for %zu objects\n", objects_to_fetch.size());
// First, build a map of object_name -> schema_name by querying the objects table
std::map<std::string, std::string> object_to_schema;

@ -728,7 +728,7 @@ json Query_Tool_Handler::get_tool_list() {
tools.push_back(create_tool_schema(
"llm.search",
"Full-text search across LLM artifacts. For question_templates, returns example_sql, related_objects, template_json, and confidence. Use include_objects=true to get full object schema details.",
"Full-text search across LLM artifacts. For question_templates, returns example_sql, related_objects, template_json, and confidence. Use include_objects=true with a non-empty query to get full object schema details (for search mode only). Empty query (list mode) returns only templates without objects to avoid huge responses.",
{"run_id"},
{{"query", "string"}, {"limit", "integer"}, {"include_objects", "boolean"}}
));

Loading…
Cancel
Save