mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 13:18:18 +00:00
Do not search documents when default tool selected by agent
What Explicit selection of notes tool/conversation command by agent is required now. Why - Newer models are good at deciding when to look up notes - Modern khoj is less of a notes only chat to search notes by default
This commit is contained in:
@@ -1071,8 +1071,8 @@ async def event_generator(
|
||||
logger.debug(f"Researched Results: {''.join(r.summarizedResult or '' for r in research_results)}")
|
||||
|
||||
# Gather Context
|
||||
## Extract Document References
|
||||
if ConversationCommand.Research not in conversation_commands:
|
||||
## Gather Document References
|
||||
if ConversationCommand.Notes in conversation_commands:
|
||||
try:
|
||||
async for result in search_documents(
|
||||
q,
|
||||
@@ -1190,7 +1190,7 @@ async def event_generator(
|
||||
):
|
||||
yield result
|
||||
|
||||
## Gather Code Results
|
||||
## Run Code
|
||||
if ConversationCommand.Code in conversation_commands:
|
||||
try:
|
||||
context = f"# Iteration 1:\n#---\nNotes:\n{compiled_references}\n\nOnline Results:{online_results}"
|
||||
@@ -1216,6 +1216,8 @@ async def event_generator(
|
||||
f"Failed to use code tool: {e}. Attempting to respond without code results",
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
## Operate Computer
|
||||
if ConversationCommand.Operator in conversation_commands:
|
||||
try:
|
||||
async for result in operate_environment(
|
||||
|
||||
@@ -1143,7 +1143,7 @@ async def search_documents(
|
||||
user: KhojUser,
|
||||
chat_history: list[ChatMessageModel],
|
||||
conversation_id: str,
|
||||
conversation_commands: List[ConversationCommand] = [ConversationCommand.Default],
|
||||
conversation_commands: List[ConversationCommand] = [ConversationCommand.Notes],
|
||||
location_data: LocationData = None,
|
||||
send_status_func: Optional[Callable] = None,
|
||||
query_images: Optional[List[str]] = None,
|
||||
@@ -1161,19 +1161,12 @@ async def search_documents(
|
||||
if agent:
|
||||
agent_has_entries = await sync_to_async(EntryAdapters.agent_has_entries)(agent=agent)
|
||||
|
||||
if (
|
||||
ConversationCommand.Notes not in conversation_commands
|
||||
and ConversationCommand.Default not in conversation_commands
|
||||
and not agent_has_entries
|
||||
):
|
||||
if ConversationCommand.Notes not in conversation_commands and not agent_has_entries:
|
||||
yield compiled_references, inferred_queries, q
|
||||
return
|
||||
|
||||
# If Notes or Default is not in the conversation command, then the search should be restricted to the agent's knowledge base
|
||||
should_limit_to_agent_knowledge = (
|
||||
ConversationCommand.Notes not in conversation_commands
|
||||
and ConversationCommand.Default not in conversation_commands
|
||||
)
|
||||
# If Notes is not in the conversation command, then the search should be restricted to the agent's knowledge base
|
||||
should_limit_to_agent_knowledge = ConversationCommand.Notes not in conversation_commands
|
||||
|
||||
if not await sync_to_async(EntryAdapters.user_has_entries)(user=user):
|
||||
if not agent_has_entries:
|
||||
|
||||
@@ -317,7 +317,7 @@ async def research(
|
||||
user=user,
|
||||
chat_history=construct_tool_chat_history(previous_iterations, ConversationCommand.SemanticSearchFiles),
|
||||
conversation_id=conversation_id,
|
||||
conversation_commands=[ConversationCommand.Default],
|
||||
conversation_commands=[ConversationCommand.Notes],
|
||||
location_data=location,
|
||||
send_status_func=send_status_func,
|
||||
query_images=query_images,
|
||||
|
||||
@@ -435,7 +435,6 @@ class ConversationCommand(str, Enum):
|
||||
command_descriptions = {
|
||||
ConversationCommand.General: "Only talk about information that relies on Khoj's general knowledge, not your personal knowledge base.",
|
||||
ConversationCommand.Notes: "Only talk about information that is available in your knowledge base.",
|
||||
ConversationCommand.Default: "The default command when no command specified. It intelligently auto-switches between general and notes mode.",
|
||||
ConversationCommand.Online: "Search for information on the internet.",
|
||||
ConversationCommand.Webpage: "Get information from webpage suggested by you.",
|
||||
ConversationCommand.Code: "Run Python code to parse information, run complex calculations, create documents and charts.",
|
||||
@@ -476,7 +475,6 @@ terrarium_tool_description = dedent(
|
||||
).strip()
|
||||
|
||||
tool_descriptions_for_llm = {
|
||||
ConversationCommand.Default: "To use a mix of your internal knowledge and the user's personal knowledge, or if you don't entirely understand the query.",
|
||||
ConversationCommand.General: "To use when you can answer the question without any outside information or personal knowledge",
|
||||
ConversationCommand.Notes: "To search the user's personal knowledge base. Especially helpful if the question expects context from the user's notes or documents.",
|
||||
ConversationCommand.Online: "To search for the latest, up-to-date information from the internet. Note: **Questions about Khoj should always use this data source**",
|
||||
|
||||
Reference in New Issue
Block a user