Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

added dotenv in .toml, added an example to use qdrant, fixed the code in main.py (#1653)

rajibe35786e567ea
diff --git a/cookbooks/add_memory_using_qdrant_cloud.py b/cookbooks/add_memory_using_qdrant_cloud.py
new file mode 100644
index 000000000..c2500ff88
--- /dev/null
+++ b/cookbooks/add_memory_using_qdrant_cloud.py
@@ -0,0 +1,40 @@
+# This example shows how to use vector config to use QDRANT CLOUD
+import os
+from dotenv import load_dotenv
+from mem0 import Memory
+
+# Loading OpenAI API Key
+load_dotenv()
+OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
+USER_ID = "test"
+quadrant_host="xx.gcp.cloud.qdrant.io"
+
+# creating the config attributes
+collection_name="memory" # this is the collection I created in QDRANT cloud
+api_key=os.environ.get("QDRANT_API_KEY") # Getting the QDRANT api KEY
+host=quadrant_host
+port=6333 #Default port for QDRANT cloud
+
+# Creating the config dict
+config = {
+ "vector_store": {
+ "provider": "qdrant",
+ "config": {
+ "collection_name": collection_name,
+ "host": host,
+ "port": port,
+ "path": None,
+ "api_key":api_key
+ }
+ }
+}
+
+# this is the change, create the memory class using from config
+memory = Memory().from_config(config)
+
+USER_DATA = """
+I am a strong believer in memory architecture.
+"""
+
+response = memory.add(USER_DATA, user_id=USER_ID)
+print(response)
diff --git a/mem0/memory/main.py b/mem0/memory/main.py
index 142f6b7a2..18af38946 100644
--- a/mem0/memory/main.py
+++ b/mem0/memory/main.py
@@ -32,7 +32,7 @@ class Memory(MemoryBase):
self.vector_store = VectorStoreFactory.create(self.config.vector_store.provider, self.config.vector_store.config)
self.llm = LlmFactory.create(self.config.llm.provider, self.config.llm.config)
self.db = SQLiteManager(self.config.history_db_path)
- self.collection_name = self.config.vector_store.config.collection_name if "collection_name" in self.config.vector_store.config else "mem0"
+ self.collection_name = self.config.vector_store.config.collection_name
capture_event("mem0.init", self)