jack 3 weeks ago
parent
commit
4ae301f788
2 changed files with 23 additions and 0 deletions
  1. 20 0
      app/core/tools/file_search_tool.py
  2. 3 0
      app/services/file/impl/r2r_file.py

+ 20 - 0
app/core/tools/file_search_tool.py

@@ -30,10 +30,30 @@ class FileSearchToolInput(BaseModel):
 
 class FileSearchTool(BaseTool):
     name: str = "file_search"
+    """
     description: str = (
         "## 工具说明:这里是用户上传的文件汇总成知识库,可以根据用户输入的问题从文件知识库中检索相关的内容。## 注意:仅允许每次调用一次。"
     )
 
+    """
+    description: str = (
+        "FileSearch Tool Specification"
+        + "Functionality:"
+        + "A specialized knowledge retrieval system that interfaces with user-uploaded document repositories. Implements semantic search algorithms to surface relevant content segments in response to natural language queries."
+        + "Operational Constraints:"
+        + "Singleton operation: Strictly 1 invocation per API call"
+        + "Input Requirements:"
+        + "Natural language question (UTF-8 encoded string)"
+        + "Output Specifications:"
+        + "Returns JSON object containing:"
+        + "relevant_excerpts: ["
+        + "{"
+        + '"text": (filename):(matched text segment),'
+        + '"score": (0.0-1.0 relevance score)'
+        + "}"
+        + "]"
+    )
+
     args_schema: Type[BaseModel] = FileSearchToolInput
 
     def __init__(self) -> None:

+ 3 - 0
app/services/file/impl/r2r_file.py

@@ -132,6 +132,9 @@ class R2RFileService(OSSFileService):
 
         for doc in search_results:
             file_key = doc.get("metadata").get("file_key")
+            file_key = (
+                doc.get("metadata").get("title") if file_key is None else file_key
+            )
             text = doc.get("text")
             if file_key in files and files[file_key]:
                 files[file_key] += f"\n\n{text}"