From 889b7ee166711160f354c2b3d202b494bf67d887 Mon Sep 17 00:00:00 2001 From: akhisud3195 Date: Fri, 9 May 2025 10:26:16 +0530 Subject: [PATCH] Add RAG tool logging and update to use chunks toggle, ragK value --- apps/rowboat_agents/src/graph/execute_turn.py | 10 +++++----- apps/rowboat_agents/src/graph/tool_calling.py | 20 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/rowboat_agents/src/graph/execute_turn.py b/apps/rowboat_agents/src/graph/execute_turn.py index 1fa43232..353078ce 100644 --- a/apps/rowboat_agents/src/graph/execute_turn.py +++ b/apps/rowboat_agents/src/graph/execute_turn.py @@ -153,7 +153,7 @@ def get_rag_tool(config: dict, complete_request: dict) -> FunctionTool: """ project_id = complete_request.get("projectId", "") if config.get("ragDataSources", None): - print("rag_search") + print(f"Creating rag_search tool with params:\n-Data Sources: {config.get('ragDataSources', [])}\n-Return Type: {config.get('ragReturnType', 'chunks')}\n-K: {config.get('ragK', 3)}") params = { "type": "object", "properties": { @@ -168,10 +168,10 @@ def get_rag_tool(config: dict, complete_request: dict) -> FunctionTool: ] } tool = FunctionTool( - name="rag_search", - description="Get information about an article", - params_json_schema=params, - on_invoke_tool=lambda ctx, args: call_rag_tool(project_id, json.loads(args)['query'], config.get("ragDataSources", []), "chunks", 3) + name="rag_search", + description="Get information about an article", + params_json_schema=params, + on_invoke_tool=lambda ctx, args: call_rag_tool(project_id, json.loads(args)['query'], config.get("ragDataSources", []), config.get("ragReturnType", "chunks"), config.get("ragK", 3)) ) return tool else: diff --git a/apps/rowboat_agents/src/graph/tool_calling.py b/apps/rowboat_agents/src/graph/tool_calling.py index cc3ae012..6457d6c9 100644 --- a/apps/rowboat_agents/src/graph/tool_calling.py +++ b/apps/rowboat_agents/src/graph/tool_calling.py @@ -75,18 +75,19 @@ async def call_rag_tool( "active": True }).to_list(length=None) - print(sources) + print(f"Sources: {sources}") # Filter sources to those in source_ids valid_source_ids = [ str(s["_id"]) for s in sources if str(s["_id"]) in source_ids ] - print(valid_source_ids) + print(f"Valid source ids: {valid_source_ids}") # If no valid sources are found, return empty results if not valid_source_ids: return '' # Perform Qdrant vector search + print(f"Calling Qdrant search with limit {k}") qdrant_results = qdrant_client.search( collection_name="embeddings", query_vector=embed_result["embedding"], @@ -112,11 +113,13 @@ async def call_rag_tool( for point in qdrant_results ] - print(return_type) - print(results) + print(f"Return type: {return_type}") + print(f"Results: {results}") # If return_type is 'chunks', return the results directly if return_type == "chunks": - return json.dumps({"Information": results}, indent=2) + chunks = json.dumps({"Information": results}, indent=2) + print(f"Returning chunks: {chunks}") + return chunks # Otherwise, fetch the full document contents from MongoDB doc_ids = [ObjectId(r["docId"]) for r in results] @@ -132,10 +135,9 @@ async def call_rag_tool( ] # Convert results to a JSON string - formatted_string = json.dumps({"Information": results}, indent=2) - print(formatted_string) - return formatted_string - + docs = json.dumps({"Information": results}, indent=2) + print(f"Returning docs: {docs}") + return docs if __name__ == "__main__": asyncio.run(call_rag_tool(