Skip to content

✨ Add display name to index name mapping for KnowledgeBaseSearchTool#2781

Open
Zhi-a wants to merge 1 commit intodevelopfrom
develop_fix_kb_3
Open

✨ Add display name to index name mapping for KnowledgeBaseSearchTool#2781
Zhi-a wants to merge 1 commit intodevelopfrom
develop_fix_kb_3

Conversation

@Zhi-a
Copy link
Copy Markdown
Contributor

@Zhi-a Zhi-a commented Apr 15, 2026

  • Introduced get_knowledge_name_map_by_index_names function to retrieve a mapping of index names to their corresponding display names.
  • Updated create_agent_config and create_tool_config_list to utilize the new mapping for generating user-friendly summaries.
  • Enhanced KnowledgeBaseSearchTool to support conversion from display names to index names during queries.
  • Added tests to verify the functionality of the new mapping and its integration within the tool configuration process.

- Introduced `get_knowledge_name_map_by_index_names` function to retrieve a mapping of index names to their corresponding display names.
- Updated `create_agent_config` and `create_tool_config_list` to utilize the new mapping for generating user-friendly summaries.
- Enhanced `KnowledgeBaseSearchTool` to support conversion from display names to index names during queries.
- Added tests to verify the functionality of the new mapping and its integration within the tool configuration process.
Copilot AI review requested due to automatic review settings April 15, 2026 07:09
@Zhi-a Zhi-a requested review from Phinease and WMC001 as code owners April 15, 2026 07:09
Comment thread test/backend/agents/test_create_agent_info.py Dismissed
Comment thread test/backend/agents/test_create_agent_info.py Dismissed
Comment thread test/backend/agents/test_create_agent_info.py Dismissed
Comment thread test/backend/agents/test_create_agent_info.py Dismissed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a display-name ↔ index-name mapping flow for knowledge bases so prompts can show user-friendly KB names while the search tool still queries by internal index names.

Changes:

  • Introduces get_knowledge_name_map_by_index_names() (index_name → knowledge_name) and uses it to render KB summaries with display names.
  • Propagates a reversed display_name_to_index_map (knowledge_name → index_name) into KnowledgeBaseSearchTool configs and local tool instantiation.
  • Updates KnowledgeBaseSearchTool to convert index_names passed by the LLM from display names to internal index names; adds/updates tests across backend+sdk.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/nexent/core/tools/knowledge_base_search_tool.py Adds display_name_to_index_map and _convert_to_index_names() used by forward() to translate display names into index names.
backend/agents/create_agent_info.py Uses index→display mapping to render KB summaries with display names; injects display→index mapping into tool metadata.
backend/database/knowledge_db.py Adds get_knowledge_name_map_by_index_names() to fetch index→display mapping with fallback behavior.
backend/services/tool_configuration_service.py Adds mapping generation during local tool validation so KB tool can accept display names.
sdk/nexent/core/agents/nexent_agent.py Ensures display_name_to_index_map is set post-instantiation for KnowledgeBaseSearchTool.
test/sdk/core/tools/test_knowledge_base_search_tool.py Extends tests for conversion behavior and related KBSearch behaviors.
test/sdk/core/agents/test_nexent_agent.py Adds tests validating metadata injection of display_name_to_index_map for local tool creation.
test/backend/services/test_tool_configuration_service.py Updates mocks/patching and adds coverage for mapping injection during local tool validation.
test/backend/database/test_knowledge_db.py Adds unit tests for get_knowledge_name_map_by_index_names() including fallback and error paths.
test/backend/agents/test_create_agent_info.py Updates/extends tests to expect the new mapping behavior in tool metadata and agent config generation.
Comments suppressed due to low confidence (1)

backend/services/tool_configuration_service.py:46

  • This import block now contains duplicate imports (e.g., minio_client is imported twice and get_embedding_model/get_vector_db_core are imported twice). Please deduplicate/merge these imports to avoid confusion and keep the module tidy.
from database.knowledge_db import get_knowledge_name_map_by_index_names
from mcpadapt.smolagents_adapter import _sanitize_function_name
from services.file_management_service import get_llm_model
from services.vectordatabase_service import get_embedding_model, get_rerank_model, get_vector_db_core
from database.client import minio_client
from services.image_service import get_vlm_model
from services.vectordatabase_service import get_embedding_model, get_vector_db_core
from utils.langchain_utils import discover_langchain_modules

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +814 to +818
"""Test that cite_index in results starts from record_ops + index + 1."""
mock_results = create_mock_search_result(2)
knowledge_base_search_tool.vdb_core.hybrid_search.return_value = mock_results

# record_ops starts at 1, so cite_index should be 1+0+1=1, 1+1+1=2
# Handle FieldInfo case (smolagents doesn't expand Field defaults)
display_map = self.display_name_to_index_map
if isinstance(display_map, FieldInfo):
display_map = display_map.default
Comment on lines +265 to 270
# Batch query to get display names (knowledge_name) for all index_names
knowledge_name_map = get_knowledge_name_map_by_index_names(index_names)
for index_name in index_names:
try:
display_name = knowledge_name_map.get(index_name, index_name)
message = ElasticSearchService().get_summary(index_name=index_name)
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 93.61702% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...dk/nexent/core/tools/knowledge_base_search_tool.py 85.71% 1 Missing and 1 partial ⚠️
backend/database/knowledge_db.py 93.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

3 participants