feat: +similarity_search

This commit is contained in:
莘权 马 2024-09-12 12:25:32 +08:00
parent 12d643ab3d
commit 513d1317d6
4 changed files with 26 additions and 5 deletions

View file

@ -41,7 +41,7 @@ class Architect(RoleZero):
instruction: str = ARCHITECT_INSTRUCTION
max_react_loop: int = 1 # FIXME: Read and edit files requires more steps, consider later
tools: list[str] = [
"Editor:write,read,write_content",
"Editor:write,read,write_content,similarity_search",
"RoleZero",
"WriteDesign",
]

View file

@ -31,7 +31,7 @@ class ProjectManager(RoleZero):
instruction: str = """Use WriteTasks tool to write a project task list"""
max_react_loop: int = 1 # FIXME: Read and edit files requires more steps, consider later
tools: list[str] = ["Editor:write,read,write_content", "RoleZero", "WriteTasks"]
tools: list[str] = ["Editor:write,read,write_content,similarity_search", "RoleZero", "WriteTasks"]
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)

View file

@ -937,15 +937,16 @@ class Editor(BaseModel):
@staticmethod
async def similarity_search(query: str, file_or_path: Union[str, Path]) -> List[str]:
"""Performs a similarity search for a given query across specified files or paths.
"""Given a filename or a pathname, performs a similarity search for a given query across the specified file or path.
This method searches the index repository for the provided query, classifying the specified
files or paths. It performs a search on each cluster of files and handles non-indexed files
separately, merging results from structured indices with any direct results from non-indexed files.
This function call does not depend on other functions.
Args:
query (str): The search query string to look for in the indexed files.
file_or_path (Union[str, Path]): A path or filename to search within.
file_or_path (Union[str, Path]): A pathname or filename to search within.
Returns:
List[str]: A list of results as strings, containing the text from the merged results
@ -953,7 +954,7 @@ class Editor(BaseModel):
Example:
>>> query = "The problem to be analyzed from the document"
>>> file_or_path = "The document or folder you want to query"
>>> file_or_path = "The pathname or filename you want to search within"
>>> texts: List[str] = await Editor.similarity_search(query=query, file_or_path=file_or_path)
>>> print(texts)
"""