Skip to content

Commit

Permalink
fix: issue with recall with no context (#19)
Browse files Browse the repository at this point in the history
* fix recall with no context

* fix recall test

* format
  • Loading branch information
shihanwan authored Oct 12, 2024
1 parent ac44c3c commit 61d8647
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions memonto/core/recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <data-{id}> {{ ?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,
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down

0 comments on commit 61d8647

Please sign in to comment.