From 61d86477890797560028a6cf073c43fc9250aabc Mon Sep 17 00:00:00 2001 From: ShiHan Wan Date: Sat, 12 Oct 2024 13:04:46 -0400 Subject: [PATCH] fix: issue with recall with no context (#19) * fix recall with no context * fix recall test * format --- memonto/core/recall.py | 15 ++++++++++++--- tests/core/test_recall.py | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/memonto/core/recall.py b/memonto/core/recall.py index 5b5955c..5863d9a 100644 --- a/memonto/core/recall.py +++ b/memonto/core/recall.py @@ -113,12 +113,20 @@ def _find_adjacent_triples( return triple_store.query(query=query, format="turtle") -def _find_all(triple_store: TripleStoreModel) -> str: - return triple_store.query( - query="CONSTRUCT {?s ?p ?o .} WHERE { GRAPH ?g { ?s ?p ?o . }}", +def _find_all(triple_store: TripleStoreModel, id: str) -> str: + result = triple_store.query( + query=f"CONSTRUCT {{?s ?p ?o .}} WHERE {{ GRAPH {{ ?s ?p ?o . }} }}", format="turtle", ) + if isinstance(result, bytes): + result = result.decode("utf-8") + + if not result: + return "" + + return str(result) + def _recall( data: Graph, @@ -156,6 +164,7 @@ def _recall( memory = "" else: memory = _find_all(triple_store=triple_store, id=id) + context = "" logger.debug(f"Contextual Triples\n{memory}\n") diff --git a/tests/core/test_recall.py b/tests/core/test_recall.py index cebfa66..2538cf7 100644 --- a/tests/core/test_recall.py +++ b/tests/core/test_recall.py @@ -79,7 +79,7 @@ def test_fetch_all_memory(mock_find_all, mock_llm, mock_store, id, data_graph): mock_llm.prompt.assert_called_once_with( prompt_name="summarize_memory", - context=None, + context="", memory=all_memory, )