From 184ede4e48915dbbeb975733a2b58cbae7d31623 Mon Sep 17 00:00:00 2001 From: Bearnardd <43574448+Bearnardd@users.noreply.github.com> Date: Fri, 7 Jul 2023 23:19:53 +0200 Subject: [PATCH] Fix buggy output from GraphQAChain (#7372) fixes https://github.com/hwchase17/langchain/issues/7289 A simple fix of the buggy output of `graph_qa`. If we have several entities with triplets then the last entry of `triplets` for a given entity merges with the first entry of the `triplets` of the next entity. --- langchain/chains/graph_qa/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/langchain/chains/graph_qa/base.py b/langchain/chains/graph_qa/base.py index 3082a1d133..2dff76f773 100644 --- a/langchain/chains/graph_qa/base.py +++ b/langchain/chains/graph_qa/base.py @@ -75,9 +75,10 @@ class GraphQAChain(Chain): ) entities = get_entities(entity_string) context = "" + all_triplets = [] for entity in entities: - triplets = self.graph.get_entity_knowledge(entity) - context += "\n".join(triplets) + all_triplets.extend(self.graph.get_entity_knowledge(entity)) + context = "\n".join(all_triplets) _run_manager.on_text("Full Context:", end="\n", verbose=self.verbose) _run_manager.on_text(context, color="green", end="\n", verbose=self.verbose) result = self.qa_chain(