Skip to content

Commit

Permalink
return all memory if no message given
Browse files Browse the repository at this point in the history
  • Loading branch information
shihanwan committed Sep 26, 2024
1 parent d17d4aa commit 79c8a0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions memonto/core/retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def _find_adjacent_triples(
return triple_store.query(query=query, format="turtle")


def _find_all(triple_store: TripleStoreModel, id: str = None) -> str:
return triple_store.query(
query="CONSTRUCT {?s ?p ?o .} WHERE { GRAPH ?g { ?s ?p ?o . }}",
format="turtle",
)


def recall_memory(
llm: LLMModel,
vector_store: VectorStoreModel,
Expand All @@ -77,12 +84,24 @@ def recall_memory(
if vector_store is None:
raise Exception("Vector store is not configured.")

matched_triples = vector_store.search(message=message, id=id)
triples = _hydrate_triples(matched_triples, triple_store, id=id)
contextual_memory = _find_adjacent_triples(triples, triple_store, id=id)
if message:
matched_triples = vector_store.search(message=message, id=id)
triples = _hydrate_triples(
triples=matched_triples,
triple_store=triple_store,
id=id,
)
contextual_memory = _find_adjacent_triples(
triples=triples,
triple_store=triple_store,
id=id,
)
if debug:
print(f"Matched triples:\n{triples}\n")
else:
contextual_memory = _find_all(triple_store=triple_store, id=id)

if debug:
print(f"Matched triples:\n{triples}\n")
print(f"Contextual triples:\n{contextual_memory}\n")

summarized_memory = llm.prompt(
Expand Down
2 changes: 1 addition & 1 deletion memonto/prompts/summarize_memory.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ ${memory}
Describe the RDF graph in one paragraph and make sure to follow these rules:
- FOCUS on the telling a story about the who, what, where, how, etc.
- LEAVE OUT anything not explicitly defined, do not make assumptions.
- DO NOT describe the graph schema and DO NOT mention the graph.
- DO NOT describe the RDF graph schema and DO NOT mention the RDF graph at all.
- Make sure to use plain and simple English.

0 comments on commit 79c8a0b

Please sign in to comment.