The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Code Formatting (#1828)
Dev Khanta972d2fb0743
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 291271262..f3cac96fb 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -3,7 +3,7 @@ repos:hooks:- id: ruffname: Ruff- entry: ruff+ entry: ruff checklanguage: systemtypes: [python]args: [--fix]diff --git a/cookbooks/add_memory_using_qdrant_cloud.py b/cookbooks/add_memory_using_qdrant_cloud.pyindex c2500ff88..d71427522 100644--- a/cookbooks/add_memory_using_qdrant_cloud.py+++ b/cookbooks/add_memory_using_qdrant_cloud.py@@ -1,6 +1,8 @@# This example shows how to use vector config to use QDRANT CLOUDimport os+from dotenv import load_dotenv+from mem0 import Memory# Loading OpenAI API Keydiff --git a/embedchain/embedchain/app.py b/embedchain/embedchain/app.pyindex ede9ec75e..b4d051607 100644--- a/embedchain/embedchain/app.py+++ b/embedchain/embedchain/app.py@@ -9,7 +9,6 @@ import requestsimport yamlfrom tqdm import tqdm-from mem0 import Memoryfrom embedchain.cache import (Config,ExactMatchEvaluation,@@ -26,7 +25,11 @@ from embedchain.embedchain import EmbedChainfrom embedchain.embedder.base import BaseEmbedderfrom embedchain.embedder.openai import OpenAIEmbedderfrom embedchain.evaluation.base import BaseMetric-from embedchain.evaluation.metrics import AnswerRelevance, ContextRelevance, Groundedness+from embedchain.evaluation.metrics import (+ AnswerRelevance,+ ContextRelevance,+ Groundedness,+)from embedchain.factory import EmbedderFactory, LlmFactory, VectorDBFactoryfrom embedchain.helpers.json_serializable import register_deserializablefrom embedchain.llm.base import BaseLlm@@ -36,6 +39,7 @@ from embedchain.utils.evaluation import EvalData, EvalMetricfrom embedchain.utils.misc import validate_configfrom embedchain.vectordb.base import BaseVectorDBfrom embedchain.vectordb.chroma import ChromaDB+from mem0 import Memorylogger = logging.getLogger(__name__)diff --git a/embedchain/embedchain/bots/base.py b/embedchain/embedchain/bots/base.pyindex aa9cbdf9f..4a817cc4c 100644--- a/embedchain/embedchain/bots/base.py+++ b/embedchain/embedchain/bots/base.py@@ -3,8 +3,10 @@ from typing import Anyfrom embedchain import Appfrom embedchain.config import AddConfig, AppConfig, BaseLlmConfigfrom embedchain.embedder.openai import OpenAIEmbedder-from embedchain.helpers.json_serializable import (JSONSerializable,- register_deserializable)+from embedchain.helpers.json_serializable import (+ JSONSerializable,+ register_deserializable,+)from embedchain.llm.openai import OpenAILlmfrom embedchain.vectordb.chroma import ChromaDBdiff --git a/embedchain/embedchain/cache.py b/embedchain/embedchain/cache.pyindex e3334fd85..765141c3c 100644--- a/embedchain/embedchain/cache.py+++ b/embedchain/embedchain/cache.py@@ -9,10 +9,12 @@ from gptcache.manager import get_data_managerfrom gptcache.manager.scalar_data.base import Answerfrom gptcache.manager.scalar_data.base import DataType as CacheDataTypefrom gptcache.session import Session-from gptcache.similarity_evaluation.distance import \- SearchDistanceEvaluation # noqa: F401-from gptcache.similarity_evaluation.exact_match import \- ExactMatchEvaluation # noqa: F401+from gptcache.similarity_evaluation.distance import ( # noqa: F401+ SearchDistanceEvaluation,+)+from gptcache.similarity_evaluation.exact_match import ( # noqa: F401+ ExactMatchEvaluation,+)logger = logging.getLogger(__name__)diff --git a/embedchain/embedchain/cli.py b/embedchain/embedchain/cli.pyindex 3ced1afde..e4f0401d5 100644--- a/embedchain/embedchain/cli.py+++ b/embedchain/embedchain/cli.py@@ -14,13 +14,21 @@ import requestsfrom rich.console import Consolefrom embedchain.telemetry.posthog import AnonymousTelemetry-from embedchain.utils.cli import (deploy_fly, deploy_gradio_app,- deploy_hf_spaces, deploy_modal,- deploy_render, deploy_streamlit,- get_pkg_path_from_name, setup_fly_io_app,- setup_gradio_app, setup_hf_app,- setup_modal_com_app, setup_render_com_app,- setup_streamlit_io_app)+from embedchain.utils.cli import (+ deploy_fly,+ deploy_gradio_app,+ deploy_hf_spaces,+ deploy_modal,+ deploy_render,+ deploy_streamlit,+ get_pkg_path_from_name,+ setup_fly_io_app,+ setup_gradio_app,+ setup_hf_app,+ setup_modal_com_app,+ setup_render_com_app,+ setup_streamlit_io_app,+)console = Console()api_process = Nonediff --git a/embedchain/embedchain/config/__init__.py b/embedchain/embedchain/config/__init__.pyindex f497b2e66..768408b78 100644--- a/embedchain/embedchain/config/__init__.py+++ b/embedchain/embedchain/config/__init__.py@@ -8,8 +8,8 @@ from .embedder.base import BaseEmbedderConfigfrom .embedder.base import BaseEmbedderConfig as EmbedderConfigfrom .embedder.ollama import OllamaEmbedderConfigfrom .llm.base import BaseLlmConfig+from .mem0_config import Mem0Configfrom .vector_db.chroma import ChromaDbConfigfrom .vector_db.elasticsearch import ElasticsearchDBConfigfrom .vector_db.opensearch import OpenSearchDBConfigfrom .vector_db.zilliz import ZillizDBConfig-from .mem0_config import Mem0Configdiff --git a/embedchain/embedchain/config/evaluation/__init__.py b/embedchain/embedchain/config/evaluation/__init__.pyindex ebbfcd0dc..67e78dade 100644--- a/embedchain/embedchain/config/evaluation/__init__.py+++ b/embedchain/embedchain/config/evaluation/__init__.py@@ -1,2 +1,5 @@-from .base import (AnswerRelevanceConfig, ContextRelevanceConfig, # noqa: F401- GroundednessConfig)+from .base import ( # noqa: F401+ AnswerRelevanceConfig,+ ContextRelevanceConfig,+ GroundednessConfig,+)diff --git a/embedchain/embedchain/config/llm/base.py b/embedchain/embedchain/config/llm/base.pyindex 77e892b73..693d09c5b 100644--- a/embedchain/embedchain/config/llm/base.py+++ b/embedchain/embedchain/config/llm/base.py@@ -1,9 +1,9 @@import jsonimport loggingimport re-from string import Template-from typing import Any, Mapping, Optional, Dict, Unionfrom pathlib import Path+from string import Template+from typing import Any, Dict, Mapping, Optional, Unionimport httpxdiff --git a/embedchain/embedchain/embedchain.py b/embedchain/embedchain/embedchain.pyindex 661b3c8ab..f7271d501 100644--- a/embedchain/embedchain/embedchain.py+++ b/embedchain/embedchain/embedchain.py@@ -6,7 +6,12 @@ from typing import Any, Optional, Unionfrom dotenv import load_dotenvfrom langchain.docstore.document import Document-from embedchain.cache import adapt, get_gptcache_session, gptcache_data_convert, gptcache_update_cache_callback+from embedchain.cache import (+ adapt,+ get_gptcache_session,+ gptcache_data_convert,+ gptcache_update_cache_callback,+)from embedchain.chunkers.base_chunker import BaseChunkerfrom embedchain.config import AddConfig, BaseLlmConfig, ChunkerConfigfrom embedchain.config.base_app_config import BaseAppConfig@@ -16,7 +21,12 @@ from embedchain.embedder.base import BaseEmbedderfrom embedchain.helpers.json_serializable import JSONSerializablefrom embedchain.llm.base import BaseLlmfrom embedchain.loaders.base_loader import BaseLoader-from embedchain.models.data_type import DataType, DirectDataType, IndirectDataType, SpecialDataType+from embedchain.models.data_type import (+ DataType,+ DirectDataType,+ IndirectDataType,+ SpecialDataType,+)from embedchain.utils.misc import detect_datatype, is_valid_json_stringfrom embedchain.vectordb.base import BaseVectorDBdiff --git a/embedchain/embedchain/embedder/clarifai.py b/embedchain/embedchain/embedder/clarifai.pyindex 6f0b7c22f..8f0bb2fe4 100644--- a/embedchain/embedchain/embedder/clarifai.py+++ b/embedchain/embedchain/embedder/clarifai.py@@ -1,18 +1,18 @@import osfrom typing import Optional, Union+from chromadb import EmbeddingFunction, Embeddings+from embedchain.config import BaseEmbedderConfigfrom embedchain.embedder.base import BaseEmbedder-from chromadb import EmbeddingFunction, Embeddings-class ClarifaiEmbeddingFunction(EmbeddingFunction):def __init__(self, config: BaseEmbedderConfig) -> None:super().__init__()try:- from clarifai.client.model import Modelfrom clarifai.client.input import Inputs+ from clarifai.client.model import Modelexcept ModuleNotFoundError:raise ModuleNotFoundError("The required dependencies for ClarifaiEmbeddingFunction are not installed."diff --git a/embedchain/embedchain/embedder/gpt4all.py b/embedchain/embedchain/embedder/gpt4all.pyindex 95d7fd62b..83123f499 100644--- a/embedchain/embedchain/embedder/gpt4all.py+++ b/embedchain/embedchain/embedder/gpt4all.py@@ -9,7 +9,9 @@ class GPT4AllEmbedder(BaseEmbedder):def __init__(self, config: Optional[BaseEmbedderConfig] = None):super().__init__(config=config)- from langchain_community.embeddings import GPT4AllEmbeddings as LangchainGPT4AllEmbeddings+ from langchain_community.embeddings import (+ GPT4AllEmbeddings as LangchainGPT4AllEmbeddings,+ )model_name = self.config.model or "all-MiniLM-L6-v2-f16.gguf"gpt4all_kwargs = {'allow_download': 'True'}diff --git a/embedchain/embedchain/embedder/openai.py b/embedchain/embedchain/embedder/openai.pyindex fc2c7d63d..d9f4c7420 100644--- a/embedchain/embedchain/embedder/openai.py+++ b/embedchain/embedchain/embedder/openai.py@@ -3,7 +3,6 @@ from typing import Optionalfrom chromadb.utils.embedding_functions import OpenAIEmbeddingFunction-from embedchain.config import BaseEmbedderConfigfrom embedchain.embedder.base import BaseEmbedderfrom embedchain.models import VectorDimensionsdiff --git a/embedchain/embedchain/llm/aws_bedrock.py b/embedchain/embedchain/llm/aws_bedrock.pyindex 89b620326..7f916268b 100644--- a/embedchain/embedchain/llm/aws_bedrock.py+++ b/embedchain/embedchain/llm/aws_bedrock.py@@ -45,8 +45,9 @@ class AWSBedrockLlm(BaseLlm):}if config.stream:- from langchain.callbacks.streaming_stdout import \- StreamingStdOutCallbackHandler+ from langchain.callbacks.streaming_stdout import (+ StreamingStdOutCallbackHandler,+ )kwargs["streaming"] = Truekwargs["callbacks"] = [StreamingStdOutCallbackHandler()]diff --git a/embedchain/embedchain/llm/base.py b/embedchain/embedchain/llm/base.pyindex bcbed4c8f..ace4bb79b 100644--- a/embedchain/embedchain/llm/base.py+++ b/embedchain/embedchain/llm/base.py@@ -5,7 +5,6 @@ from typing import Any, Optionalfrom langchain.schema import BaseMessage as LCBaseMessage-from embedchain.constants import SQLITE_PATHfrom embedchain.config import BaseLlmConfigfrom embedchain.config.llm.base import (DEFAULT_PROMPT,@@ -13,6 +12,7 @@ from embedchain.config.llm.base import (DEFAULT_PROMPT_WITH_MEM0_MEMORY_TEMPLATE,DOCS_SITE_PROMPT_TEMPLATE,)+from embedchain.constants import SQLITE_PATHfrom embedchain.core.db.database import init_db, setup_enginefrom embedchain.helpers.json_serializable import JSONSerializablefrom embedchain.memory.base import ChatHistorydiff --git a/embedchain/embedchain/llm/gpt4all.py b/embedchain/embedchain/llm/gpt4all.pyindex 833f3e268..76062b08b 100644--- a/embedchain/embedchain/llm/gpt4all.py+++ b/embedchain/embedchain/llm/gpt4all.py@@ -26,8 +26,7 @@ class GPT4ALLLlm(BaseLlm):@staticmethoddef _get_instance(model):try:- from langchain_community.llms.gpt4all import \- GPT4All as LangchainGPT4All+ from langchain_community.llms.gpt4all import GPT4All as LangchainGPT4Allexcept ModuleNotFoundError:raise ModuleNotFoundError("The GPT4All python package is not installed. Please install it with `pip install --upgrade embedchain[opensource]`" # noqa E501diff --git a/embedchain/embedchain/llm/jina.py b/embedchain/embedchain/llm/jina.pyindex 33796bc5c..ac3a0e76f 100644--- a/embedchain/embedchain/llm/jina.py+++ b/embedchain/embedchain/llm/jina.py@@ -35,8 +35,9 @@ class JinaLlm(BaseLlm):if config.top_p:kwargs["model_kwargs"]["top_p"] = config.top_pif config.stream:- from langchain.callbacks.streaming_stdout import \- StreamingStdOutCallbackHandler+ from langchain.callbacks.streaming_stdout import (+ StreamingStdOutCallbackHandler,+ )chat = JinaChat(**kwargs, streaming=config.stream, callbacks=[StreamingStdOutCallbackHandler()])else:diff --git a/embedchain/embedchain/loaders/pdf_file.py b/embedchain/embedchain/loaders/pdf_file.pyindex 78f93b5db..a7f6d5540 100644--- a/embedchain/embedchain/loaders/pdf_file.py+++ b/embedchain/embedchain/loaders/pdf_file.py@@ -1,6 +1,7 @@import hashlibfrom langchain_community.document_loaders import PyPDFLoader+from embedchain.helpers.json_serializable import register_deserializablefrom embedchain.loaders.base_loader import BaseLoaderfrom embedchain.utils.misc import clean_stringdiff --git a/embedchain/embedchain/loaders/rss_feed.py b/embedchain/embedchain/loaders/rss_feed.pyindex a4b3376f2..bc17c68bc 100644--- a/embedchain/embedchain/loaders/rss_feed.py+++ b/embedchain/embedchain/loaders/rss_feed.py@@ -28,7 +28,9 @@ class RSSFeedLoader(BaseLoader):@staticmethoddef get_rss_content(url: str):try:- from langchain_community.document_loaders import RSSFeedLoader as LangchainRSSFeedLoader+ from langchain_community.document_loaders import (+ RSSFeedLoader as LangchainRSSFeedLoader,+ )except ImportError:raise ImportError("""RSSFeedLoader file requires extra dependencies.diff --git a/embedchain/embedchain/loaders/unstructured_file.py b/embedchain/embedchain/loaders/unstructured_file.pyindex 62c20ae43..856ac888b 100644--- a/embedchain/embedchain/loaders/unstructured_file.py+++ b/embedchain/embedchain/loaders/unstructured_file.py@@ -11,8 +11,7 @@ class UnstructuredLoader(BaseLoader):"""Load data from an Unstructured file."""try:import unstructured # noqa: F401- from langchain_community.document_loaders import \- UnstructuredFileLoader+ from langchain_community.document_loaders import UnstructuredFileLoaderexcept ImportError:raise ImportError('Unstructured file requires extra dependencies. Install with `pip install "unstructured[local-inference, all-docs]"`' # noqa: E501diff --git a/embedchain/embedchain/vectordb/zilliz.py b/embedchain/embedchain/vectordb/zilliz.pyindex 0a30de9d6..ca5544733 100644--- a/embedchain/embedchain/vectordb/zilliz.py+++ b/embedchain/embedchain/vectordb/zilliz.py@@ -6,8 +6,15 @@ from embedchain.helpers.json_serializable import register_deserializablefrom embedchain.vectordb.base import BaseVectorDBtry:- from pymilvus import (Collection, CollectionSchema, DataType, FieldSchema,- MilvusClient, connections, utility)+ from pymilvus import (+ Collection,+ CollectionSchema,+ DataType,+ FieldSchema,+ MilvusClient,+ connections,+ utility,+ )except ImportError:raise ImportError("Zilliz requires extra dependencies. Install with `pip install --upgrade embedchain[milvus]`"diff --git a/embedchain/examples/chat-pdf/app.py b/embedchain/examples/chat-pdf/app.pyindex 0b2fefaee..fb29b73e9 100644--- a/embedchain/examples/chat-pdf/app.py+++ b/embedchain/examples/chat-pdf/app.py@@ -8,8 +8,7 @@ import streamlit as stfrom embedchain import Appfrom embedchain.config import BaseLlmConfig-from embedchain.helpers.callbacks import (StreamingStdOutCallbackHandlerYield,- generate)+from embedchain.helpers.callbacks import StreamingStdOutCallbackHandlerYield, generatedef embedchain_bot(db_path, api_key):diff --git a/embedchain/examples/sadhguru-ai/app.py b/embedchain/examples/sadhguru-ai/app.pyindex 67d4c62de..5c123d600 100644--- a/embedchain/examples/sadhguru-ai/app.py+++ b/embedchain/examples/sadhguru-ai/app.py@@ -8,8 +8,7 @@ import streamlit as stfrom embedchain import Appfrom embedchain.config import BaseLlmConfig-from embedchain.helpers.callbacks import (StreamingStdOutCallbackHandlerYield,- generate)+from embedchain.helpers.callbacks import StreamingStdOutCallbackHandlerYield, generate@st.cache_resourcediff --git a/embedchain/examples/unacademy-ai/app.py b/embedchain/examples/unacademy-ai/app.pyindex 5e552f1dd..e31dba918 100644--- a/embedchain/examples/unacademy-ai/app.py+++ b/embedchain/examples/unacademy-ai/app.py@@ -4,8 +4,7 @@ import streamlit as stfrom embedchain import Appfrom embedchain.config import BaseLlmConfig-from embedchain.helpers.callbacks import (StreamingStdOutCallbackHandlerYield,- generate)+from embedchain.helpers.callbacks import StreamingStdOutCallbackHandlerYield, generate@st.cache_resourcediff --git a/embedchain/tests/embedder/test_azure_openai_embedder.py b/embedchain/tests/embedder/test_azure_openai_embedder.pyindex 77357198a..2667d01f3 100644--- a/embedchain/tests/embedder/test_azure_openai_embedder.py+++ b/embedchain/tests/embedder/test_azure_openai_embedder.py@@ -1,4 +1,4 @@-from unittest.mock import patch, Mock+from unittest.mock import Mock, patchimport httpxdiff --git a/embedchain/tests/embedder/test_huggingface_embedder.py b/embedchain/tests/embedder/test_huggingface_embedder.pyindex 4760b9260..ed97ccc91 100644--- a/embedchain/tests/embedder/test_huggingface_embedder.py+++ b/embedchain/tests/embedder/test_huggingface_embedder.py@@ -1,5 +1,6 @@from unittest.mock import patch+from embedchain.config import BaseEmbedderConfigfrom embedchain.embedder.huggingface import HuggingFaceEmbedderdiff --git a/embedchain/tests/helper_classes/test_json_serializable.py b/embedchain/tests/helper_classes/test_json_serializable.pyindex adcfe5f7b..e68e05075 100644--- a/embedchain/tests/helper_classes/test_json_serializable.py+++ b/embedchain/tests/helper_classes/test_json_serializable.py@@ -4,8 +4,10 @@ from string import Templatefrom embedchain import Appfrom embedchain.config import AppConfig, BaseLlmConfig-from embedchain.helpers.json_serializable import (JSONSerializable,- register_deserializable)+from embedchain.helpers.json_serializable import (+ JSONSerializable,+ register_deserializable,+)class TestJsonSerializable(unittest.TestCase):diff --git a/embedchain/tests/llm/conftest.py b/embedchain/tests/llm/conftest.pyindex edfafb95e..6e3da3d5d 100644--- a/embedchain/tests/llm/conftest.py+++ b/embedchain/tests/llm/conftest.py@@ -1,7 +1,9 @@from unittest import mock+import pytest+@pytest.fixture(autouse=True)def mock_alembic_command_upgrade():with mock.patch("alembic.command.upgrade"):diff --git a/embedchain/tests/llm/test_azure_openai.py b/embedchain/tests/llm/test_azure_openai.pyindex 6aa69e6ef..f5ac3874d 100644--- a/embedchain/tests/llm/test_azure_openai.py+++ b/embedchain/tests/llm/test_azure_openai.py@@ -1,4 +1,4 @@-from unittest.mock import Mock, MagicMock, patch+from unittest.mock import MagicMock, Mock, patchimport httpximport pytestdiff --git a/embedchain/tests/llm/test_ollama.py b/embedchain/tests/llm/test_ollama.pyindex e45cb6bb9..b0d932635 100644--- a/embedchain/tests/llm/test_ollama.py+++ b/embedchain/tests/llm/test_ollama.py@@ -1,8 +1,8 @@import pytest+from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandlerfrom embedchain.config import BaseLlmConfigfrom embedchain.llm.ollama import OllamaLlm-from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler@pytest.fixturediff --git a/embedchain/tests/models/test_data_type.py b/embedchain/tests/models/test_data_type.pyindex bf3d6e1e6..60d66282c 100644--- a/embedchain/tests/models/test_data_type.py+++ b/embedchain/tests/models/test_data_type.py@@ -1,5 +1,9 @@-from embedchain.models.data_type import (DataType, DirectDataType,- IndirectDataType, SpecialDataType)+from embedchain.models.data_type import (+ DataType,+ DirectDataType,+ IndirectDataType,+ SpecialDataType,+)def test_subclass_types_in_data_type():diff --git a/mem0/__init__.py b/mem0/__init__.pyindex 0433062ed..66632ea04 100644--- a/mem0/__init__.py+++ b/mem0/__init__.py@@ -2,5 +2,5 @@ import importlib.metadata__version__ = importlib.metadata.version("mem0ai")-from mem0.memory.main import Memory # noqafrom mem0.client.main import MemoryClient # noqa+from mem0.memory.main import Memory # noqadiff --git a/mem0/configs/base.py b/mem0/configs/base.pyindex ee2a333da..42a0a2b24 100644--- a/mem0/configs/base.py+++ b/mem0/configs/base.py@@ -1,12 +1,13 @@import osfrom typing import Any, Dict, Optional+from pydantic import BaseModel, Field-from mem0.memory.setup import mem0_dir-from mem0.vector_stores.configs import VectorStoreConfig-from mem0.llms.configs import LlmConfigfrom mem0.embeddings.configs import EmbedderConfigfrom mem0.graphs.configs import GraphStoreConfig+from mem0.llms.configs import LlmConfig+from mem0.memory.setup import mem0_dir+from mem0.vector_stores.configs import VectorStoreConfigclass MemoryItem(BaseModel):diff --git a/mem0/configs/embeddings/base.py b/mem0/configs/embeddings/base.pyindex 7014ea251..f4659dce3 100644--- a/mem0/configs/embeddings/base.py+++ b/mem0/configs/embeddings/base.py@@ -1,9 +1,10 @@from abc import ABC-from mem0.configs.base import AzureConfig-from typing import Optional, Union, Dict+from typing import Dict, Optional, Unionimport httpx+from mem0.configs.base import AzureConfig+class BaseEmbedderConfig(ABC):"""diff --git a/mem0/configs/llms/base.py b/mem0/configs/llms/base.pyindex 0cf7cbb11..94c8e278f 100644--- a/mem0/configs/llms/base.py+++ b/mem0/configs/llms/base.py@@ -1,9 +1,10 @@from abc import ABC-from mem0.configs.base import AzureConfig-from typing import Optional, Union, Dict+from typing import Dict, Optional, Unionimport httpx+from mem0.configs.base import AzureConfig+class BaseLlmConfig(ABC):"""diff --git a/mem0/configs/vector_stores/chroma.py b/mem0/configs/vector_stores/chroma.pyindex 23e182f1d..ba58b3ac4 100644--- a/mem0/configs/vector_stores/chroma.py+++ b/mem0/configs/vector_stores/chroma.py@@ -1,6 +1,6 @@import subprocessimport sys-from typing import Optional, ClassVar, Dict, Any+from typing import Any, ClassVar, Dict, Optionalfrom pydantic import BaseModel, Field, model_validatordiff --git a/mem0/configs/vector_stores/pgvector.py b/mem0/configs/vector_stores/pgvector.pyindex 1ed59c75b..df8dabf4c 100644--- a/mem0/configs/vector_stores/pgvector.py+++ b/mem0/configs/vector_stores/pgvector.py@@ -1,4 +1,4 @@-from typing import Optional, Dict, Any+from typing import Any, Dict, Optionalfrom pydantic import BaseModel, Field, model_validatordiff --git a/mem0/configs/vector_stores/qdrant.py b/mem0/configs/vector_stores/qdrant.pyindex bb76cac3d..10951db8b 100644--- a/mem0/configs/vector_stores/qdrant.py+++ b/mem0/configs/vector_stores/qdrant.py@@ -1,5 +1,6 @@+from typing import Any, ClassVar, Dict, Optional+from pydantic import BaseModel, Field, model_validator-from typing import Optional, ClassVar, Dict, Anyclass QdrantConfig(BaseModel):diff --git a/mem0/embeddings/base.py b/mem0/embeddings/base.pyindex ef6800f34..c5d12b6e2 100644--- a/mem0/embeddings/base.py+++ b/mem0/embeddings/base.py@@ -1,5 +1,5 @@-from typing import Optionalfrom abc import ABC, abstractmethod+from typing import Optionalfrom mem0.configs.embeddings.base import BaseEmbedderConfigdiff --git a/mem0/graphs/configs.py b/mem0/graphs/configs.pyindex a93d27d96..033637c32 100644--- a/mem0/graphs/configs.py+++ b/mem0/graphs/configs.py@@ -1,7 +1,10 @@from typing import Optional+from pydantic import BaseModel, Field, field_validator, model_validator+from mem0.llms.configs import LlmConfig+class Neo4jConfig(BaseModel):url: Optional[str] = Field(None, description="Host address for the graph database")username: Optional[str] = Field(None, description="Username for the graph database")diff --git a/mem0/llms/anthropic.py b/mem0/llms/anthropic.pyindex 5e32d81c9..fb390348c 100644--- a/mem0/llms/anthropic.py+++ b/mem0/llms/anthropic.py@@ -1,7 +1,4 @@-import subprocess-import sysimport os-import jsonfrom typing import Dict, List, Optionaltry:@@ -9,8 +6,8 @@ try:except ImportError:raise ImportError("The 'anthropic' library is required. Please install it using 'pip install anthropic'.")-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass AnthropicLLM(LLMBase):diff --git a/mem0/llms/aws_bedrock.py b/mem0/llms/aws_bedrock.pyindex b5699a9ef..5e7969c13 100644--- a/mem0/llms/aws_bedrock.py+++ b/mem0/llms/aws_bedrock.py@@ -1,16 +1,14 @@-import subprocess-import sys-import osimport json-from typing import Dict, List, Optional, Any+import os+from typing import Any, Dict, List, Optionaltry:import boto3except ImportError:raise ImportError("The 'boto3' library is required. Please install it using 'pip install boto3'.")-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass AWSBedrockLLM(LLMBase):diff --git a/mem0/llms/azure_openai.py b/mem0/llms/azure_openai.pyindex d18569a8e..f093284b4 100644--- a/mem0/llms/azure_openai.py+++ b/mem0/llms/azure_openai.py@@ -1,11 +1,11 @@-import osimport json+import osfrom typing import Dict, List, Optionalfrom openai import AzureOpenAI-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass AzureOpenAILLM(LLMBase):diff --git a/mem0/llms/base.py b/mem0/llms/base.pyindex 69e880b4d..a1ed3c794 100644--- a/mem0/llms/base.py+++ b/mem0/llms/base.py@@ -1,5 +1,5 @@-from typing import Optionalfrom abc import ABC, abstractmethod+from typing import Optionalfrom mem0.configs.llms.base import BaseLlmConfigdiff --git a/mem0/llms/groq.py b/mem0/llms/groq.pyindex c67436c08..e970a1ee0 100644--- a/mem0/llms/groq.py+++ b/mem0/llms/groq.py@@ -1,7 +1,5 @@-import subprocess-import sys-import osimport json+import osfrom typing import Dict, List, Optionaltry:@@ -9,8 +7,8 @@ try:except ImportError:raise ImportError("The 'groq' library is required. Please install it using 'pip install groq'.")-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass GroqLLM(LLMBase):diff --git a/mem0/llms/litellm.py b/mem0/llms/litellm.pyindex 1a6fb7c0c..cfdcba347 100644--- a/mem0/llms/litellm.py+++ b/mem0/llms/litellm.py@@ -1,5 +1,3 @@-import subprocess-import sysimport jsonfrom typing import Dict, List, Optional@@ -8,8 +6,8 @@ try:except ImportError:raise ImportError("The 'litellm' library is required. Please install it using 'pip install litellm'.")-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass LiteLLM(LLMBase):diff --git a/mem0/llms/ollama.py b/mem0/llms/ollama.pyindex e7acbdd7b..6750f0dd4 100644--- a/mem0/llms/ollama.py+++ b/mem0/llms/ollama.py@@ -1,5 +1,3 @@-import subprocess-import sysfrom typing import Dict, List, Optionaltry:@@ -7,8 +5,8 @@ try:except ImportError:raise ImportError("The 'ollama' library is required. Please install it using 'pip install ollama'.")-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass OllamaLLM(LLMBase):diff --git a/mem0/llms/openai.py b/mem0/llms/openai.pyindex 68a363453..b988c33bb 100644--- a/mem0/llms/openai.py+++ b/mem0/llms/openai.py@@ -1,11 +1,11 @@-import osimport json+import osfrom typing import Dict, List, Optionalfrom openai import OpenAI-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass OpenAILLM(LLMBase):diff --git a/mem0/llms/openai_structured.py b/mem0/llms/openai_structured.pyindex d2ea9c4e9..ab56b85ff 100644--- a/mem0/llms/openai_structured.py+++ b/mem0/llms/openai_structured.py@@ -1,10 +1,11 @@-import os, json+import json+import osfrom typing import Dict, List, Optionalfrom openai import OpenAI-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass OpenAIStructuredLLM(LLMBase):diff --git a/mem0/llms/together.py b/mem0/llms/together.pyindex 816ed7a99..51ebac660 100644--- a/mem0/llms/together.py+++ b/mem0/llms/together.py@@ -1,7 +1,5 @@-import subprocess-import sys-import osimport json+import osfrom typing import Dict, List, Optionaltry:@@ -9,8 +7,8 @@ try:except ImportError:raise ImportError("The 'together' library is required. Please install it using 'pip install together'.")-from mem0.llms.base import LLMBasefrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.base import LLMBaseclass TogetherLLM(LLMBase):diff --git a/mem0/memory/graph_memory.py b/mem0/memory/graph_memory.pyindex 71352c94c..9ec52e6bd 100644--- a/mem0/memory/graph_memory.py+++ b/mem0/memory/graph_memory.py@@ -1,10 +1,17 @@-import jsonimport logging+from langchain_community.graphs import Neo4jGraphfrom rank_bm25 import BM25Okapi-from mem0.utils.factory import LlmFactory, EmbedderFactory-from mem0.graphs.utils import get_update_memory_messages, EXTRACT_ENTITIES_PROMPT-from mem0.graphs.tools import UPDATE_MEMORY_TOOL_GRAPH, ADD_MEMORY_TOOL_GRAPH, NOOP_TOOL, ADD_MESSAGE_TOOL, SEARCH_TOOL++from mem0.graphs.tools import (+ ADD_MEMORY_TOOL_GRAPH,+ ADD_MESSAGE_TOOL,+ NOOP_TOOL,+ SEARCH_TOOL,+ UPDATE_MEMORY_TOOL_GRAPH,+)+from mem0.graphs.utils import EXTRACT_ENTITIES_PROMPT, get_update_memory_messages+from mem0.utils.factory import EmbedderFactory, LlmFactorylogger = logging.getLogger(__name__)diff --git a/mem0/memory/main.py b/mem0/memory/main.pyindex d5744b685..f158ec825 100644--- a/mem0/memory/main.py+++ b/mem0/memory/main.py@@ -1,22 +1,24 @@-import logging+import concurrentimport hashlib-import uuid-import pytzimport json+import logging+import threading+import uuid+import warningsfrom datetime import datetimefrom typing import Any, Dict-import warnings++import pytzfrom pydantic import ValidationError++from mem0.configs.base import MemoryConfig, MemoryItem+from mem0.configs.prompts import get_update_memory_messagesfrom mem0.memory.base import MemoryBasefrom mem0.memory.setup import setup_configfrom mem0.memory.storage import SQLiteManagerfrom mem0.memory.telemetry import capture_eventfrom mem0.memory.utils import get_fact_retrieval_messages, parse_messages-from mem0.configs.prompts import get_update_memory_messages-from mem0.utils.factory import LlmFactory, EmbedderFactory, VectorStoreFactory-from mem0.configs.base import MemoryItem, MemoryConfig-import threading-import concurrent+from mem0.utils.factory import EmbedderFactory, LlmFactory, VectorStoreFactory# Setup user configsetup_config()@@ -154,7 +156,7 @@ class Memory(MemoryBase):logging.info(resp)try:if resp["event"] == "ADD":- memory_id = self._create_memory(data=resp["text"], metadata=metadata)+ self._create_memory(data=resp["text"], metadata=metadata)elif resp["event"] == "UPDATE":self._update_memory(memory_id=resp["id"], data=resp["text"], metadata=metadata)elif resp["event"] == "DELETE":@@ -175,7 +177,7 @@ class Memory(MemoryBase):else:self.graph.user_id = "USER"data = "\n".join([msg["content"] for msg in messages if "content" in msg and msg["role"] != "system"])- added_entities = self.graph.add(data, filters)+ self.graph.add(data, filters)def get(self, memory_id):"""diff --git a/mem0/memory/telemetry.py b/mem0/memory/telemetry.pyindex 70336f780..ec819e93e 100644--- a/mem0/memory/telemetry.py+++ b/mem0/memory/telemetry.py@@ -1,3 +1,4 @@+import loggingimport platformimport sys@@ -5,6 +6,8 @@ from posthog import Posthogfrom mem0.memory.setup import get_user_id, setup_config+logging.getLogger('posthog').setLevel(logging.CRITICAL + 1)+logging.getLogger('urllib3').setLevel(logging.CRITICAL + 1)class AnonymousTelemetry:def __init__(self, project_api_key, host):diff --git a/mem0/proxy/main.py b/mem0/proxy/main.pyindex daf24ae14..bb614f4f3 100644--- a/mem0/proxy/main.py+++ b/mem0/proxy/main.py@@ -1,9 +1,10 @@import loggingimport subprocessimport sys-import httpx-from typing import Optional, List, Unionimport threading+from typing import List, Optional, Union++import httpxtry:import litellm@@ -20,9 +21,9 @@ except ImportError:raise ImportError("The required 'litellm' library is not installed.")sys.exit(1)-from mem0.memory.telemetry import capture_client_eventfrom mem0 import Memory, MemoryClientfrom mem0.configs.prompts import MEMORY_ANSWER_PROMPT+from mem0.memory.telemetry import capture_client_eventlogger = logging.getLogger(__name__)diff --git a/mem0/utils/factory.py b/mem0/utils/factory.pyindex c672cf1d6..aca433b0f 100644--- a/mem0/utils/factory.py+++ b/mem0/utils/factory.py@@ -1,7 +1,7 @@import importlib-from mem0.configs.llms.base import BaseLlmConfigfrom mem0.configs.embeddings.base import BaseEmbedderConfig+from mem0.configs.llms.base import BaseLlmConfigdef load_class(class_type):diff --git a/mem0/vector_stores/chroma.py b/mem0/vector_stores/chroma.pyindex 21fc85c68..0dc97a3fc 100644--- a/mem0/vector_stores/chroma.py+++ b/mem0/vector_stores/chroma.py@@ -1,7 +1,5 @@-import subprocess-import sysimport logging-from typing import Optional, List, Dict+from typing import Dict, List, Optionalfrom pydantic import BaseModeldiff --git a/mem0/vector_stores/configs.py b/mem0/vector_stores/configs.pyindex 3b2eb2937..2f052da5b 100644--- a/mem0/vector_stores/configs.py+++ b/mem0/vector_stores/configs.py@@ -1,4 +1,5 @@-from typing import Optional, Dict+from typing import Dict, Optional+from pydantic import BaseModel, Field, model_validatordiff --git a/mem0/vector_stores/pgvector.py b/mem0/vector_stores/pgvector.pyindex dae1e2d18..f9ec3f977 100644--- a/mem0/vector_stores/pgvector.py+++ b/mem0/vector_stores/pgvector.py@@ -1,8 +1,7 @@-import subprocess-import sysimport jsonimport logging-from typing import Optional, List+from typing import List, Optional+from pydantic import BaseModeltry:diff --git a/mem0/vector_stores/qdrant.py b/mem0/vector_stores/qdrant.pyindex 0c7000b82..3ecb93f9f 100644--- a/mem0/vector_stores/qdrant.py+++ b/mem0/vector_stores/qdrant.py@@ -1,6 +1,6 @@+import loggingimport osimport shutil-import loggingfrom qdrant_client import QdrantClientfrom qdrant_client.models import (diff --git a/tests/llms/test_azure_openai.py b/tests/llms/test_azure_openai.pyindex effa19a18..63eb91b01 100644--- a/tests/llms/test_azure_openai.py+++ b/tests/llms/test_azure_openai.py@@ -1,10 +1,11 @@+from unittest.mock import Mock, patch+import httpximport pytest-from unittest.mock import Mock, patch-from mem0.llms.azure_openai import AzureOpenAILLMfrom mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.azure_openai import AzureOpenAILLMMODEL = "gpt-4o" # or your custom deployment nameTEMPERATURE = 0.7diff --git a/tests/llms/test_groq.py b/tests/llms/test_groq.pyindex 52c3b2227..e7d1f51c1 100644--- a/tests/llms/test_groq.py+++ b/tests/llms/test_groq.py@@ -1,7 +1,10 @@-import pytestfrom unittest.mock import Mock, patch-from mem0.llms.groq import GroqLLM++import pytest+from mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.groq import GroqLLM+@pytest.fixturedef mock_groq_client():diff --git a/tests/llms/test_litellm.py b/tests/llms/test_litellm.pyindex b611d5c2a..f4b265aac 100644--- a/tests/llms/test_litellm.py+++ b/tests/llms/test_litellm.py@@ -1,8 +1,10 @@-import pytestfrom unittest.mock import Mock, patch-from mem0.llms import litellm+import pytest+from mem0.configs.llms.base import BaseLlmConfig+from mem0.llms import litellm+@pytest.fixturedef mock_litellm():diff --git a/tests/llms/test_ollama.py b/tests/llms/test_ollama.pyindex a781971c1..d99fd2bcc 100644--- a/tests/llms/test_ollama.py+++ b/tests/llms/test_ollama.py@@ -1,9 +1,12 @@-import pytestfrom unittest.mock import Mock, patch-from mem0.llms.ollama import OllamaLLM++import pytest+from mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.ollama import OllamaLLMfrom mem0.llms.utils.tools import ADD_MEMORY_TOOL+@pytest.fixturedef mock_ollama_client():with patch('mem0.llms.ollama.Client') as mock_ollama:diff --git a/tests/llms/test_openai.py b/tests/llms/test_openai.pyindex 81005079b..204487c43 100644--- a/tests/llms/test_openai.py+++ b/tests/llms/test_openai.py@@ -1,7 +1,10 @@-import pytestfrom unittest.mock import Mock, patch-from mem0.llms.openai import OpenAILLM++import pytest+from mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.openai import OpenAILLM+@pytest.fixturedef mock_openai_client():diff --git a/tests/llms/test_together.py b/tests/llms/test_together.pyindex 1353416f4..f317d106c 100644--- a/tests/llms/test_together.py+++ b/tests/llms/test_together.py@@ -1,7 +1,10 @@-import pytestfrom unittest.mock import Mock, patch-from mem0.llms.together import TogetherLLM++import pytest+from mem0.configs.llms.base import BaseLlmConfig+from mem0.llms.together import TogetherLLM+@pytest.fixturedef mock_together_client():diff --git a/tests/test_proxy.py b/tests/test_proxy.pyindex c8fe566fc..c7776b84a 100644--- a/tests/test_proxy.py+++ b/tests/test_proxy.py@@ -1,10 +1,11 @@-import pytestfrom unittest.mock import Mock, patch-from mem0.configs.prompts import MEMORY_ANSWER_PROMPT+import pytest+from mem0 import Memory, MemoryClient-from mem0.proxy.main import Mem0-from mem0.proxy.main import Chat, Completions+from mem0.configs.prompts import MEMORY_ANSWER_PROMPT+from mem0.proxy.main import Chat, Completions, Mem0+@pytest.fixturedef mock_memory_client():