Skip to content

Commit

Permalink
refactor id into a class variable
Browse files Browse the repository at this point in the history
  • Loading branch information
shihanwan committed Sep 26, 2024
1 parent 22dbf4e commit d17d4aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
9 changes: 5 additions & 4 deletions memonto/core/retrieve.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from rdflib import Graph

from memonto.llms.base_llm import LLMModel
from memonto.utils.rdf import is_rdf_schema
from memonto.stores.triple.base_store import TripleStoreModel
from memonto.stores.vector.base_store import VectorStoreModel

Expand Down Expand Up @@ -70,12 +67,12 @@ def _find_adjacent_triples(


def recall_memory(
data: Graph,
llm: LLMModel,
vector_store: VectorStoreModel,
triple_store: TripleStoreModel,
message: str,
id: str,
debug: bool,
) -> str:
if vector_store is None:
raise Exception("Vector store is not configured.")
Expand All @@ -84,6 +81,10 @@ def recall_memory(
triples = _hydrate_triples(matched_triples, triple_store, id=id)
contextual_memory = _find_adjacent_triples(triples, 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(
prompt_name="summarize_memory",
memory=contextual_memory,
Expand Down
19 changes: 10 additions & 9 deletions memonto/memonto.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class Memonto(BaseModel):
id: Optional[str] = Field(None, description="Unique identifier for a memory group.")
ontology: Graph = Field(..., description="Schema describing the memory ontology.")
namespaces: dict[str, Namespace] = Field(
..., description="Namespaces used in the memory ontology."
Expand Down Expand Up @@ -67,7 +68,7 @@ def configure(self, config: dict) -> None:
"""
self.triple_store, self.vector_store, self.llm = configure(config=config)

def retain(self, message: str, id: str = None) -> None:
def retain(self, message: str) -> None:
"""
Analyze a text for relevant information that maps onto an RDF ontology then commit them to the memory store.
Expand All @@ -84,27 +85,27 @@ def retain(self, message: str, id: str = None) -> None:
triple_store=self.triple_store,
vector_store=self.vector_store,
message=message,
id=id,
id=self.id,
debug=self.debug,
auto_expand=self.auto_expand,
)

def recall(self, message: str = None, id: str = None) -> str:
def recall(self, message: str = None) -> str:
"""
Return a text summary of all memories currently stored in context.
:return: A text summary of the entire current memory.
"""
return recall_memory(
data=self.data,
llm=self.llm,
triple_store=self.triple_store,
vector_store=self.vector_store,
message=message,
id=id,
id=self.id,
debug=self.debug,
)

def remember(self, id: str = None) -> None:
def remember(self) -> None:
"""
Load existing memories from the memory store to a memonto instance.
Expand All @@ -115,7 +116,7 @@ def remember(self, id: str = None) -> None:
self.ontology, self.data = load_memory(
namespaces=self.namespaces,
store=self.triple_store,
id=id,
id=self.id,
debug=self.debug,
)

Expand All @@ -125,7 +126,7 @@ def forget(self):
"""
pass

def query(self, id: str = None, uri: URIRef = None, query: str = None) -> list:
def query(self, uri: URIRef = None, query: str = None) -> list:
"""
Perform query against the memory store to retrieve raw memory data rather than a summary.
Expand All @@ -138,7 +139,7 @@ def query(self, id: str = None, uri: URIRef = None, query: str = None) -> list:
return query_memory_data(
ontology=self.ontology,
store=self.triple_store,
id=id,
id=self.id,
uri=uri,
query=query,
debug=self.debug,
Expand Down

0 comments on commit d17d4aa

Please sign in to comment.