Co-authored-by: Saket Aryan <94069182+whysosaket@users.noreply.github.com> Co-authored-by: Saket Aryan <saketaryan2002@gmail.com>
52 lines
1.1 KiB
Python
52 lines
1.1 KiB
Python
import os
|
|
|
|
from mem0 import Memory
|
|
|
|
|
|
memory_client = None
|
|
|
|
|
|
def get_memory_client(custom_instructions: str = None):
|
|
"""
|
|
Get or initialize the Mem0 client.
|
|
|
|
Args:
|
|
custom_instructions: Optional instructions for the memory project.
|
|
|
|
Returns:
|
|
Initialized Mem0 client instance.
|
|
|
|
Raises:
|
|
Exception: If required API keys are not set.
|
|
"""
|
|
global memory_client
|
|
|
|
if memory_client is not None:
|
|
return memory_client
|
|
|
|
try:
|
|
config = {
|
|
"vector_store": {
|
|
"provider": "qdrant",
|
|
"config": {
|
|
"collection_name": "openmemory",
|
|
"host": "mem0_store",
|
|
"port": 6333,
|
|
}
|
|
}
|
|
}
|
|
|
|
memory_client = Memory.from_config(config_dict=config)
|
|
except Exception:
|
|
raise Exception("Exception occurred while initializing memory client")
|
|
|
|
# Update project with custom instructions if provided
|
|
if custom_instructions:
|
|
memory_client.update_project(custom_instructions=custom_instructions)
|
|
|
|
return memory_client
|
|
|
|
|
|
def get_default_user_id():
|
|
return "default_user"
|