mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-07 08:26:06 +00:00
update es store logging system
This commit is contained in:
parent
22683d29ff
commit
24bea8dae6
2 changed files with 21 additions and 7 deletions
|
|
@ -37,7 +37,7 @@ class LlamaIndexEsMemoryStore(BaseMemoryStore):
|
|||
self.index = VectorStoreIndex.from_vector_store(vector_store=self.es_store,
|
||||
embed_model=self.embedding_model.model)
|
||||
|
||||
self.logger = Logger.get_logger()
|
||||
self.logger = Logger.get_logger(Logger.append_timestamp("es_memory_store"))
|
||||
|
||||
def retrieve_memories(self,
|
||||
query: str = "",
|
||||
|
|
@ -65,7 +65,11 @@ class LlamaIndexEsMemoryStore(BaseMemoryStore):
|
|||
text_nodes = retriever.retrieve(query)
|
||||
if text_nodes and text_nodes[0].embedding:
|
||||
self.emb_dims = len(text_nodes[0].embedding)
|
||||
|
||||
self.logger.log_dictionary_info({
|
||||
"action": "retrieve_memories",
|
||||
"query": query,
|
||||
"text_nodes": [f"ID: {n.node_id} |Text: {n.text}" for n in text_nodes]
|
||||
})
|
||||
return [self._text_node_2_memory_node(n) for n in text_nodes]
|
||||
|
||||
async def a_retrieve_memories(self,
|
||||
|
|
@ -115,14 +119,21 @@ class LlamaIndexEsMemoryStore(BaseMemoryStore):
|
|||
|
||||
def insert(self, node: MemoryNode):
|
||||
self.index.insert_nodes([self._memory_node_2_text_node(node)])
|
||||
self.logger.log_dictionary_info({
|
||||
"action": "insert",
|
||||
"node": f"ID: {node.memory_id} | Text: {node.content} | Key: {node.key} | Type: {node.memory_type}"
|
||||
})
|
||||
|
||||
def delete(self, node: MemoryNode):
|
||||
self.logger.log_dictionary_info({
|
||||
"action": "delete",
|
||||
"id": node.memory_id,
|
||||
})
|
||||
return self.es_store.delete(node.memory_id)
|
||||
|
||||
def update(self, node: MemoryNode, update_embedding: bool = True):
|
||||
if update_embedding:
|
||||
node.vector = []
|
||||
|
||||
self.delete(node)
|
||||
self.insert(node)
|
||||
|
||||
|
|
|
|||
|
|
@ -73,15 +73,18 @@ class Logger(logging.Logger):
|
|||
|
||||
self.info(f"logger={name} is inited.") # Logs an initialization message
|
||||
|
||||
def log_dictionary_info(self, dictionary):
|
||||
self.info(self.format_current_context(dictionary))
|
||||
|
||||
def format_current_context(self, context):
|
||||
import pprint
|
||||
pp = pprint.PrettyPrinter()
|
||||
pretty_string = pp.pformat(context)
|
||||
return rich2text(Panel(pretty_string, width=128))
|
||||
|
||||
|
||||
def wrap_in_box(self, context):
|
||||
return rich2text(Panel(context, width=128))
|
||||
|
||||
|
||||
def format_chat_message(self, message):
|
||||
buf = '\n'
|
||||
buf += f"LM Input:\n"
|
||||
|
|
@ -111,7 +114,7 @@ class Logger(logging.Logger):
|
|||
buf += '\n'
|
||||
buf += '\n'
|
||||
return self.wrap_in_box(buf)
|
||||
|
||||
|
||||
def _add_file_handler(self):
|
||||
"""
|
||||
Adds a file handler to the logger which logs messages to a rotating file.
|
||||
|
|
@ -125,7 +128,7 @@ class Logger(logging.Logger):
|
|||
file_path = Path().joinpath(self.dir_path, f"{self.name}.{self.file_type}")
|
||||
file_path.parent.mkdir(exist_ok=True) # Ensure the directory exists
|
||||
file_name = file_path.as_posix() # Get the absolute path as a string
|
||||
Console().print(f"[{self.name}] Registering Logger to file at: " + file_name, style="bold blue")
|
||||
Console().print(f"[{self.name}] Registering logger to file at: " + file_name, style="bold blue")
|
||||
|
||||
# Instantiate a rotating file handler with specified parameters
|
||||
file_handler = RotatingFileHandler(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue