Change dependency to mem0ai (#1476)
This commit is contained in:
@@ -9,7 +9,7 @@ import requests
|
||||
import yaml
|
||||
from tqdm import tqdm
|
||||
|
||||
from mem0 import Mem0
|
||||
from mem0 import Memory
|
||||
from embedchain.cache import (
|
||||
Config,
|
||||
ExactMatchEvaluation,
|
||||
@@ -131,9 +131,9 @@ class App(EmbedChain):
|
||||
self._init_cache()
|
||||
|
||||
# If memory_config is provided, initializing the memory ...
|
||||
self.mem0_client = None
|
||||
self.mem0_memory = None
|
||||
if self.memory_config is not None:
|
||||
self.mem0_client = Mem0(api_key=self.memory_config.api_key)
|
||||
self.mem0_memory = Memory()
|
||||
|
||||
# Send anonymous telemetry
|
||||
self._telemetry_props = {"class": self.__class__.__name__}
|
||||
|
||||
@@ -53,7 +53,7 @@ class EmbedChain(JSONSerializable):
|
||||
self.config = config
|
||||
self.cache_config = None
|
||||
self.memory_config = None
|
||||
self.mem0_client = None
|
||||
self.mem0_memory = None
|
||||
# Llm
|
||||
self.llm = llm
|
||||
# Database has support for config assignment for backwards compatibility
|
||||
@@ -598,8 +598,8 @@ class EmbedChain(JSONSerializable):
|
||||
contexts_data_for_llm_query = contexts
|
||||
|
||||
memories = None
|
||||
if self.mem0_client:
|
||||
memories = self.mem0_client.search(
|
||||
if self.mem0_memory:
|
||||
memories = self.mem0_memory.search(
|
||||
query=input_query, agent_id=self.config.id, session_id=session_id, limit=self.memory_config.top_k
|
||||
)
|
||||
|
||||
@@ -641,8 +641,8 @@ class EmbedChain(JSONSerializable):
|
||||
# Add to Mem0 memory if enabled
|
||||
# TODO: Might need to prepend with some text like:
|
||||
# "Remember user preferences from following user query: {input_query}"
|
||||
if self.mem0_client:
|
||||
self.mem0_client.add(data=input_query, agent_id=self.config.id, session_id=session_id)
|
||||
if self.mem0_memory:
|
||||
self.mem0_memory.add(data=input_query, agent_id=self.config.id, session_id=session_id)
|
||||
|
||||
# add conversation in memory
|
||||
self.llm.add_history(self.config.id, input_query, answer, session_id=session_id)
|
||||
|
||||
Reference in New Issue
Block a user