From d082030eef9466a0bf907ba929cf566efb8a0894 Mon Sep 17 00:00:00 2001 From: fengsh27 <123769183+fengsh27@users.noreply.github.com> Date: Tue, 20 Aug 2024 18:47:19 -0400 Subject: [PATCH] fix: Inject kg context even if kg query result is empty (#198) * fix some bugs in reflexion agent * fix an vectorstore issue * introduce use_reflexion to kg RagAgent * prompt LLM not to generate cypher marker * fix test error * change vectorstore collection names to apply previous fix of collection field max length issue * phrasing, formatting, parameter explanations * fix type hinting * prompt LLM even if kg query result is empty --------- Co-authored-by: fengsh Co-authored-by: slobentanzer --- biochatter/database_agent.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/biochatter/database_agent.py b/biochatter/database_agent.py index c9b85434..23695524 100644 --- a/biochatter/database_agent.py +++ b/biochatter/database_agent.py @@ -115,6 +115,21 @@ def get_query_results(self, query: str, k: int = 3) -> list[Document]: # than k if results is None or len(results) == 0 or results[0] is None: return [] + if len(results[0]) == 0: + return [ + Document( + page_content = ( + "I didn't find any result in knowledge graph, " + f"but here is the query I used: {cypher_query}. " + "You can ask user to refine the question, " + "but don't make up anything." + ), + metadata={ + "cypher_query": cypher_query, + }, + ) + ] + for result in results[0]: documents.append( Document(