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
feat: Automate installation of required libraries. (#1795)
Jaimin Godhanid03ba0fc8a46
diff --git a/mem0/embeddings/ollama.py b/mem0/embeddings/ollama.pyindex 1298760b3..2e7f37587 100644--- a/mem0/embeddings/ollama.py+++ b/mem0/embeddings/ollama.py@@ -1,3 +1,5 @@+import subprocess+import sysfrom typing import Optionalfrom mem0.configs.embeddings.base import BaseEmbedderConfig@@ -6,9 +8,17 @@ from mem0.embeddings.base import EmbeddingBasetry:from ollama import Clientexcept ImportError:- raise ImportError(- "Ollama requires extra dependencies. Install with `pip install ollama`"- ) from None+ user_input = input("The 'ollama' library is required. Install it now? [y/N]: ")+ if user_input.lower() == 'y':+ try:+ subprocess.check_call([sys.executable, "-m", "pip", "install", "ollama"])+ from ollama import Client+ except subprocess.CalledProcessError:+ print("Failed to install 'ollama'. Please install it manually using 'pip install ollama'.")+ sys.exit(1)+ else:+ print("The required 'ollama' library is not installed.")+ sys.exit(1)class OllamaEmbedding(EmbeddingBase):diff --git a/mem0/proxy/main.py b/mem0/proxy/main.pyindex 76942b1ff..58a6a7302 100644--- a/mem0/proxy/main.py+++ b/mem0/proxy/main.py@@ -1,3 +1,5 @@+import subprocess+import sysimport httpxfrom typing import Optional, List, Unionimport threading@@ -5,9 +7,17 @@ import threadingtry:import litellmexcept ImportError:- raise ImportError(- "litellm requires extra dependencies. Install with `pip install litellm`"- ) from None+ user_input = input("The 'litellm' library is required. Install it now? [y/N]: ")+ if user_input.lower() == 'y':+ try:+ subprocess.check_call([sys.executable, "-m", "pip", "install", "litellm"])+ import litellm+ except subprocess.CalledProcessError:+ print("Failed to install 'litellm'. Please install it manually using 'pip install litellm'.")+ sys.exit(1)+ else:+ raise ImportError("The required 'litellm' library is not installed.")+ sys.exit(1)from mem0.memory.telemetry import capture_client_eventfrom mem0 import Memory, MemoryClientdiff --git a/mem0/vector_stores/chroma.py b/mem0/vector_stores/chroma.pyindex b75b0c914..791ff8c96 100644--- a/mem0/vector_stores/chroma.py+++ b/mem0/vector_stores/chroma.py@@ -1,3 +1,5 @@+import subprocess+import sysimport loggingfrom typing import Optional, List, Dict@@ -7,9 +9,18 @@ try:import chromadbfrom chromadb.config import Settingsexcept ImportError:- raise ImportError(- "Chromadb requires extra dependencies. Install with `pip install chromadb`"- ) from None+ user_input = input("The 'chromadb' library is required. Install it now? [y/N]: ")+ if user_input.lower() == 'y':+ try:+ subprocess.check_call([sys.executable, "-m", "pip", "install", "chromadb"])+ import chromadb+ from chromadb.config import Settings+ except subprocess.CalledProcessError:+ print("Failed to install 'chromadb'. Please install it manually using 'pip install chromadb'.")+ sys.exit(1)+ else:+ print("The required 'chromadb' library is not installed.")+ sys.exit(1)from mem0.vector_stores.base import VectorStoreBasediff --git a/mem0/vector_stores/pgvector.py b/mem0/vector_stores/pgvector.pyindex 180792fdb..9da5f4a14 100644--- a/mem0/vector_stores/pgvector.py+++ b/mem0/vector_stores/pgvector.py@@ -1,3 +1,5 @@+import subprocess+import sysimport jsonfrom typing import Optional, Listfrom pydantic import BaseModel@@ -6,9 +8,18 @@ try:import psycopg2from psycopg2.extras import execute_valuesexcept ImportError:- raise ImportError(- "PGVector requires extra dependencies. Install with `pip install psycopg2`"- ) from None+ user_input = input("The 'psycopg2' library is required. Install it now? [y/N]: ")+ if user_input.lower() == 'y':+ try:+ subprocess.check_call([sys.executable, "-m", "pip", "install", "psycopg2"])+ import psycopg2+ from psycopg2.extras import execute_values+ except subprocess.CalledProcessError:+ print("Failed to install 'psycopg2'. Please install it manually using 'pip install psycopg2'.")+ sys.exit(1)+ else:+ print("The required 'psycopg2' library is not installed.")+ sys.exit(1)from mem0.vector_stores.base import VectorStoreBase