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:
Debanjum
2025-08-25 00:40:18 -07:00
parent a52a06ad9d
commit a99eb841ff
4 changed files with 10 additions and 17 deletions

View File

@@ -1071,8 +1071,8 @@ async def event_generator(
logger.debug(f"Researched Results: {''.join(r.summarizedResult or '' for r in research_results)}") logger.debug(f"Researched Results: {''.join(r.summarizedResult or '' for r in research_results)}")
# Gather Context # Gather Context
## Extract Document References ## Gather Document References
if ConversationCommand.Research not in conversation_commands: if ConversationCommand.Notes in conversation_commands:
try: try:
async for result in search_documents( async for result in search_documents(
q, q,
@@ -1190,7 +1190,7 @@ async def event_generator(
): ):
yield result yield result
## Gather Code Results ## Run Code
if ConversationCommand.Code in conversation_commands: if ConversationCommand.Code in conversation_commands:
try: try:
context = f"# Iteration 1:\n#---\nNotes:\n{compiled_references}\n\nOnline Results:{online_results}" 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", f"Failed to use code tool: {e}. Attempting to respond without code results",
exc_info=True, exc_info=True,
) )
## Operate Computer
if ConversationCommand.Operator in conversation_commands: if ConversationCommand.Operator in conversation_commands:
try: try:
async for result in operate_environment( async for result in operate_environment(

View File

@@ -1143,7 +1143,7 @@ async def search_documents(
user: KhojUser, user: KhojUser,
chat_history: list[ChatMessageModel], chat_history: list[ChatMessageModel],
conversation_id: str, conversation_id: str,
conversation_commands: List[ConversationCommand] = [ConversationCommand.Default], conversation_commands: List[ConversationCommand] = [ConversationCommand.Notes],
location_data: LocationData = None, location_data: LocationData = None,
send_status_func: Optional[Callable] = None, send_status_func: Optional[Callable] = None,
query_images: Optional[List[str]] = None, query_images: Optional[List[str]] = None,
@@ -1161,19 +1161,12 @@ async def search_documents(
if agent: if agent:
agent_has_entries = await sync_to_async(EntryAdapters.agent_has_entries)(agent=agent) agent_has_entries = await sync_to_async(EntryAdapters.agent_has_entries)(agent=agent)
if ( if ConversationCommand.Notes not in conversation_commands and not agent_has_entries:
ConversationCommand.Notes not in conversation_commands
and ConversationCommand.Default not in conversation_commands
and not agent_has_entries
):
yield compiled_references, inferred_queries, q yield compiled_references, inferred_queries, q
return return
# If Notes or Default is not in the conversation command, then the search should be restricted to the agent's knowledge base # 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 = ( should_limit_to_agent_knowledge = ConversationCommand.Notes not in conversation_commands
ConversationCommand.Notes not in conversation_commands
and ConversationCommand.Default not in conversation_commands
)
if not await sync_to_async(EntryAdapters.user_has_entries)(user=user): if not await sync_to_async(EntryAdapters.user_has_entries)(user=user):
if not agent_has_entries: if not agent_has_entries:

View File

@@ -317,7 +317,7 @@ async def research(
user=user, user=user,
chat_history=construct_tool_chat_history(previous_iterations, ConversationCommand.SemanticSearchFiles), chat_history=construct_tool_chat_history(previous_iterations, ConversationCommand.SemanticSearchFiles),
conversation_id=conversation_id, conversation_id=conversation_id,
conversation_commands=[ConversationCommand.Default], conversation_commands=[ConversationCommand.Notes],
location_data=location, location_data=location,
send_status_func=send_status_func, send_status_func=send_status_func,
query_images=query_images, query_images=query_images,

View File

@@ -435,7 +435,6 @@ class ConversationCommand(str, Enum):
command_descriptions = { command_descriptions = {
ConversationCommand.General: "Only talk about information that relies on Khoj's general knowledge, not your personal knowledge base.", 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.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.Online: "Search for information on the internet.",
ConversationCommand.Webpage: "Get information from webpage suggested by you.", ConversationCommand.Webpage: "Get information from webpage suggested by you.",
ConversationCommand.Code: "Run Python code to parse information, run complex calculations, create documents and charts.", ConversationCommand.Code: "Run Python code to parse information, run complex calculations, create documents and charts.",
@@ -476,7 +475,6 @@ terrarium_tool_description = dedent(
).strip() ).strip()
tool_descriptions_for_llm = { 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.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.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**", ConversationCommand.Online: "To search for the latest, up-to-date information from the internet. Note: **Questions about Khoj should always use this data source**",