agentrun-mem0ai 0.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. agentrun_mem0/__init__.py +6 -0
  2. agentrun_mem0/client/__init__.py +0 -0
  3. agentrun_mem0/client/main.py +1747 -0
  4. agentrun_mem0/client/project.py +931 -0
  5. agentrun_mem0/client/utils.py +115 -0
  6. agentrun_mem0/configs/__init__.py +0 -0
  7. agentrun_mem0/configs/base.py +90 -0
  8. agentrun_mem0/configs/embeddings/__init__.py +0 -0
  9. agentrun_mem0/configs/embeddings/base.py +110 -0
  10. agentrun_mem0/configs/enums.py +7 -0
  11. agentrun_mem0/configs/llms/__init__.py +0 -0
  12. agentrun_mem0/configs/llms/anthropic.py +56 -0
  13. agentrun_mem0/configs/llms/aws_bedrock.py +192 -0
  14. agentrun_mem0/configs/llms/azure.py +57 -0
  15. agentrun_mem0/configs/llms/base.py +62 -0
  16. agentrun_mem0/configs/llms/deepseek.py +56 -0
  17. agentrun_mem0/configs/llms/lmstudio.py +59 -0
  18. agentrun_mem0/configs/llms/ollama.py +56 -0
  19. agentrun_mem0/configs/llms/openai.py +79 -0
  20. agentrun_mem0/configs/llms/vllm.py +56 -0
  21. agentrun_mem0/configs/prompts.py +459 -0
  22. agentrun_mem0/configs/rerankers/__init__.py +0 -0
  23. agentrun_mem0/configs/rerankers/base.py +17 -0
  24. agentrun_mem0/configs/rerankers/cohere.py +15 -0
  25. agentrun_mem0/configs/rerankers/config.py +12 -0
  26. agentrun_mem0/configs/rerankers/huggingface.py +17 -0
  27. agentrun_mem0/configs/rerankers/llm.py +48 -0
  28. agentrun_mem0/configs/rerankers/sentence_transformer.py +16 -0
  29. agentrun_mem0/configs/rerankers/zero_entropy.py +28 -0
  30. agentrun_mem0/configs/vector_stores/__init__.py +0 -0
  31. agentrun_mem0/configs/vector_stores/alibabacloud_mysql.py +64 -0
  32. agentrun_mem0/configs/vector_stores/aliyun_tablestore.py +32 -0
  33. agentrun_mem0/configs/vector_stores/azure_ai_search.py +57 -0
  34. agentrun_mem0/configs/vector_stores/azure_mysql.py +84 -0
  35. agentrun_mem0/configs/vector_stores/baidu.py +27 -0
  36. agentrun_mem0/configs/vector_stores/chroma.py +58 -0
  37. agentrun_mem0/configs/vector_stores/databricks.py +61 -0
  38. agentrun_mem0/configs/vector_stores/elasticsearch.py +65 -0
  39. agentrun_mem0/configs/vector_stores/faiss.py +37 -0
  40. agentrun_mem0/configs/vector_stores/langchain.py +30 -0
  41. agentrun_mem0/configs/vector_stores/milvus.py +42 -0
  42. agentrun_mem0/configs/vector_stores/mongodb.py +25 -0
  43. agentrun_mem0/configs/vector_stores/neptune.py +27 -0
  44. agentrun_mem0/configs/vector_stores/opensearch.py +41 -0
  45. agentrun_mem0/configs/vector_stores/pgvector.py +52 -0
  46. agentrun_mem0/configs/vector_stores/pinecone.py +55 -0
  47. agentrun_mem0/configs/vector_stores/qdrant.py +47 -0
  48. agentrun_mem0/configs/vector_stores/redis.py +24 -0
  49. agentrun_mem0/configs/vector_stores/s3_vectors.py +28 -0
  50. agentrun_mem0/configs/vector_stores/supabase.py +44 -0
  51. agentrun_mem0/configs/vector_stores/upstash_vector.py +34 -0
  52. agentrun_mem0/configs/vector_stores/valkey.py +15 -0
  53. agentrun_mem0/configs/vector_stores/vertex_ai_vector_search.py +28 -0
  54. agentrun_mem0/configs/vector_stores/weaviate.py +41 -0
  55. agentrun_mem0/embeddings/__init__.py +0 -0
  56. agentrun_mem0/embeddings/aws_bedrock.py +100 -0
  57. agentrun_mem0/embeddings/azure_openai.py +55 -0
  58. agentrun_mem0/embeddings/base.py +31 -0
  59. agentrun_mem0/embeddings/configs.py +30 -0
  60. agentrun_mem0/embeddings/gemini.py +39 -0
  61. agentrun_mem0/embeddings/huggingface.py +44 -0
  62. agentrun_mem0/embeddings/langchain.py +35 -0
  63. agentrun_mem0/embeddings/lmstudio.py +29 -0
  64. agentrun_mem0/embeddings/mock.py +11 -0
  65. agentrun_mem0/embeddings/ollama.py +53 -0
  66. agentrun_mem0/embeddings/openai.py +49 -0
  67. agentrun_mem0/embeddings/together.py +31 -0
  68. agentrun_mem0/embeddings/vertexai.py +64 -0
  69. agentrun_mem0/exceptions.py +503 -0
  70. agentrun_mem0/graphs/__init__.py +0 -0
  71. agentrun_mem0/graphs/configs.py +105 -0
  72. agentrun_mem0/graphs/neptune/__init__.py +0 -0
  73. agentrun_mem0/graphs/neptune/base.py +497 -0
  74. agentrun_mem0/graphs/neptune/neptunedb.py +511 -0
  75. agentrun_mem0/graphs/neptune/neptunegraph.py +474 -0
  76. agentrun_mem0/graphs/tools.py +371 -0
  77. agentrun_mem0/graphs/utils.py +97 -0
  78. agentrun_mem0/llms/__init__.py +0 -0
  79. agentrun_mem0/llms/anthropic.py +87 -0
  80. agentrun_mem0/llms/aws_bedrock.py +665 -0
  81. agentrun_mem0/llms/azure_openai.py +141 -0
  82. agentrun_mem0/llms/azure_openai_structured.py +91 -0
  83. agentrun_mem0/llms/base.py +131 -0
  84. agentrun_mem0/llms/configs.py +34 -0
  85. agentrun_mem0/llms/deepseek.py +107 -0
  86. agentrun_mem0/llms/gemini.py +201 -0
  87. agentrun_mem0/llms/groq.py +88 -0
  88. agentrun_mem0/llms/langchain.py +94 -0
  89. agentrun_mem0/llms/litellm.py +87 -0
  90. agentrun_mem0/llms/lmstudio.py +114 -0
  91. agentrun_mem0/llms/ollama.py +117 -0
  92. agentrun_mem0/llms/openai.py +147 -0
  93. agentrun_mem0/llms/openai_structured.py +52 -0
  94. agentrun_mem0/llms/sarvam.py +89 -0
  95. agentrun_mem0/llms/together.py +88 -0
  96. agentrun_mem0/llms/vllm.py +107 -0
  97. agentrun_mem0/llms/xai.py +52 -0
  98. agentrun_mem0/memory/__init__.py +0 -0
  99. agentrun_mem0/memory/base.py +63 -0
  100. agentrun_mem0/memory/graph_memory.py +698 -0
  101. agentrun_mem0/memory/kuzu_memory.py +713 -0
  102. agentrun_mem0/memory/main.py +2229 -0
  103. agentrun_mem0/memory/memgraph_memory.py +689 -0
  104. agentrun_mem0/memory/setup.py +56 -0
  105. agentrun_mem0/memory/storage.py +218 -0
  106. agentrun_mem0/memory/telemetry.py +90 -0
  107. agentrun_mem0/memory/utils.py +208 -0
  108. agentrun_mem0/proxy/__init__.py +0 -0
  109. agentrun_mem0/proxy/main.py +189 -0
  110. agentrun_mem0/reranker/__init__.py +9 -0
  111. agentrun_mem0/reranker/base.py +20 -0
  112. agentrun_mem0/reranker/cohere_reranker.py +85 -0
  113. agentrun_mem0/reranker/huggingface_reranker.py +147 -0
  114. agentrun_mem0/reranker/llm_reranker.py +142 -0
  115. agentrun_mem0/reranker/sentence_transformer_reranker.py +107 -0
  116. agentrun_mem0/reranker/zero_entropy_reranker.py +96 -0
  117. agentrun_mem0/utils/factory.py +283 -0
  118. agentrun_mem0/utils/gcp_auth.py +167 -0
  119. agentrun_mem0/vector_stores/__init__.py +0 -0
  120. agentrun_mem0/vector_stores/alibabacloud_mysql.py +547 -0
  121. agentrun_mem0/vector_stores/aliyun_tablestore.py +252 -0
  122. agentrun_mem0/vector_stores/azure_ai_search.py +396 -0
  123. agentrun_mem0/vector_stores/azure_mysql.py +463 -0
  124. agentrun_mem0/vector_stores/baidu.py +368 -0
  125. agentrun_mem0/vector_stores/base.py +58 -0
  126. agentrun_mem0/vector_stores/chroma.py +332 -0
  127. agentrun_mem0/vector_stores/configs.py +67 -0
  128. agentrun_mem0/vector_stores/databricks.py +761 -0
  129. agentrun_mem0/vector_stores/elasticsearch.py +237 -0
  130. agentrun_mem0/vector_stores/faiss.py +479 -0
  131. agentrun_mem0/vector_stores/langchain.py +180 -0
  132. agentrun_mem0/vector_stores/milvus.py +250 -0
  133. agentrun_mem0/vector_stores/mongodb.py +310 -0
  134. agentrun_mem0/vector_stores/neptune_analytics.py +467 -0
  135. agentrun_mem0/vector_stores/opensearch.py +292 -0
  136. agentrun_mem0/vector_stores/pgvector.py +404 -0
  137. agentrun_mem0/vector_stores/pinecone.py +382 -0
  138. agentrun_mem0/vector_stores/qdrant.py +270 -0
  139. agentrun_mem0/vector_stores/redis.py +295 -0
  140. agentrun_mem0/vector_stores/s3_vectors.py +176 -0
  141. agentrun_mem0/vector_stores/supabase.py +237 -0
  142. agentrun_mem0/vector_stores/upstash_vector.py +293 -0
  143. agentrun_mem0/vector_stores/valkey.py +824 -0
  144. agentrun_mem0/vector_stores/vertex_ai_vector_search.py +635 -0
  145. agentrun_mem0/vector_stores/weaviate.py +343 -0
  146. agentrun_mem0ai-0.0.11.data/data/README.md +205 -0
  147. agentrun_mem0ai-0.0.11.dist-info/METADATA +277 -0
  148. agentrun_mem0ai-0.0.11.dist-info/RECORD +150 -0
  149. agentrun_mem0ai-0.0.11.dist-info/WHEEL +4 -0
  150. agentrun_mem0ai-0.0.11.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,332 @@
1
+ import logging
2
+ from typing import Dict, List, Optional
3
+
4
+ from pydantic import BaseModel
5
+
6
+ try:
7
+ import chromadb
8
+ from chromadb.config import Settings
9
+ except ImportError:
10
+ raise ImportError("The 'chromadb' library is required. Please install it using 'pip install chromadb'.")
11
+
12
+ from agentrun_mem0.vector_stores.base import VectorStoreBase
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ class OutputData(BaseModel):
18
+ id: Optional[str] # memory id
19
+ score: Optional[float] # distance
20
+ payload: Optional[Dict] # metadata
21
+
22
+
23
+ class ChromaDB(VectorStoreBase):
24
+ def __init__(
25
+ self,
26
+ collection_name: str,
27
+ client: Optional[chromadb.Client] = None,
28
+ host: Optional[str] = None,
29
+ port: Optional[int] = None,
30
+ path: Optional[str] = None,
31
+ api_key: Optional[str] = None,
32
+ tenant: Optional[str] = None,
33
+ ):
34
+ """
35
+ Initialize the Chromadb vector store.
36
+
37
+ Args:
38
+ collection_name (str): Name of the collection.
39
+ client (chromadb.Client, optional): Existing chromadb client instance. Defaults to None.
40
+ host (str, optional): Host address for chromadb server. Defaults to None.
41
+ port (int, optional): Port for chromadb server. Defaults to None.
42
+ path (str, optional): Path for local chromadb database. Defaults to None.
43
+ api_key (str, optional): ChromaDB Cloud API key. Defaults to None.
44
+ tenant (str, optional): ChromaDB Cloud tenant ID. Defaults to None.
45
+ """
46
+ if client:
47
+ self.client = client
48
+ elif api_key and tenant:
49
+ # Initialize ChromaDB Cloud client
50
+ logger.info("Initializing ChromaDB Cloud client")
51
+ self.client = chromadb.CloudClient(
52
+ api_key=api_key,
53
+ tenant=tenant,
54
+ database="mem0" # Use fixed database name for cloud
55
+ )
56
+ else:
57
+ # Initialize local or server client
58
+ self.settings = Settings(anonymized_telemetry=False)
59
+
60
+ if host and port:
61
+ self.settings.chroma_server_host = host
62
+ self.settings.chroma_server_http_port = port
63
+ self.settings.chroma_api_impl = "chromadb.api.fastapi.FastAPI"
64
+ else:
65
+ if path is None:
66
+ path = "db"
67
+
68
+ self.settings.persist_directory = path
69
+ self.settings.is_persistent = True
70
+
71
+ self.client = chromadb.Client(self.settings)
72
+
73
+ self.collection_name = collection_name
74
+ self.collection = self.create_col(collection_name)
75
+
76
+ def _parse_output(self, data: Dict) -> List[OutputData]:
77
+ """
78
+ Parse the output data.
79
+
80
+ Args:
81
+ data (Dict): Output data.
82
+
83
+ Returns:
84
+ List[OutputData]: Parsed output data.
85
+ """
86
+ keys = ["ids", "distances", "metadatas"]
87
+ values = []
88
+
89
+ for key in keys:
90
+ value = data.get(key, [])
91
+ if isinstance(value, list) and value and isinstance(value[0], list):
92
+ value = value[0]
93
+ values.append(value)
94
+
95
+ ids, distances, metadatas = values
96
+ max_length = max(len(v) for v in values if isinstance(v, list) and v is not None)
97
+
98
+ result = []
99
+ for i in range(max_length):
100
+ entry = OutputData(
101
+ id=ids[i] if isinstance(ids, list) and ids and i < len(ids) else None,
102
+ score=(distances[i] if isinstance(distances, list) and distances and i < len(distances) else None),
103
+ payload=(metadatas[i] if isinstance(metadatas, list) and metadatas and i < len(metadatas) else None),
104
+ )
105
+ result.append(entry)
106
+
107
+ return result
108
+
109
+ def create_col(self, name: str, embedding_fn: Optional[callable] = None):
110
+ """
111
+ Create a new collection.
112
+
113
+ Args:
114
+ name (str): Name of the collection.
115
+ embedding_fn (Optional[callable]): Embedding function to use. Defaults to None.
116
+
117
+ Returns:
118
+ chromadb.Collection: The created or retrieved collection.
119
+ """
120
+ collection = self.client.get_or_create_collection(
121
+ name=name,
122
+ embedding_function=embedding_fn,
123
+ )
124
+ return collection
125
+
126
+ def insert(
127
+ self,
128
+ vectors: List[list],
129
+ payloads: Optional[List[Dict]] = None,
130
+ ids: Optional[List[str]] = None,
131
+ ):
132
+ """
133
+ Insert vectors into a collection.
134
+
135
+ Args:
136
+ vectors (List[list]): List of vectors to insert.
137
+ payloads (Optional[List[Dict]], optional): List of payloads corresponding to vectors. Defaults to None.
138
+ ids (Optional[List[str]], optional): List of IDs corresponding to vectors. Defaults to None.
139
+ """
140
+ logger.info(f"Inserting {len(vectors)} vectors into collection {self.collection_name}")
141
+ self.collection.add(ids=ids, embeddings=vectors, metadatas=payloads)
142
+
143
+ def search(
144
+ self, query: str, vectors: List[list], limit: int = 5, filters: Optional[Dict] = None
145
+ ) -> List[OutputData]:
146
+ """
147
+ Search for similar vectors.
148
+
149
+ Args:
150
+ query (str): Query.
151
+ vectors (List[list]): List of vectors to search.
152
+ limit (int, optional): Number of results to return. Defaults to 5.
153
+ filters (Optional[Dict], optional): Filters to apply to the search. Defaults to None.
154
+
155
+ Returns:
156
+ List[OutputData]: Search results.
157
+ """
158
+ where_clause = self._generate_where_clause(filters) if filters else None
159
+ results = self.collection.query(query_embeddings=vectors, where=where_clause, n_results=limit)
160
+ final_results = self._parse_output(results)
161
+ return final_results
162
+
163
+ def delete(self, vector_id: str):
164
+ """
165
+ Delete a vector by ID.
166
+
167
+ Args:
168
+ vector_id (str): ID of the vector to delete.
169
+ """
170
+ self.collection.delete(ids=vector_id)
171
+
172
+ def update(
173
+ self,
174
+ vector_id: str,
175
+ vector: Optional[List[float]] = None,
176
+ payload: Optional[Dict] = None,
177
+ ):
178
+ """
179
+ Update a vector and its payload.
180
+
181
+ Args:
182
+ vector_id (str): ID of the vector to update.
183
+ vector (Optional[List[float]], optional): Updated vector. Defaults to None.
184
+ payload (Optional[Dict], optional): Updated payload. Defaults to None.
185
+ """
186
+ self.collection.update(ids=vector_id, embeddings=vector, metadatas=payload)
187
+
188
+ def get(self, vector_id: str) -> OutputData:
189
+ """
190
+ Retrieve a vector by ID.
191
+
192
+ Args:
193
+ vector_id (str): ID of the vector to retrieve.
194
+
195
+ Returns:
196
+ OutputData: Retrieved vector.
197
+ """
198
+ result = self.collection.get(ids=[vector_id])
199
+ return self._parse_output(result)[0]
200
+
201
+ def list_cols(self) -> List[chromadb.Collection]:
202
+ """
203
+ List all collections.
204
+
205
+ Returns:
206
+ List[chromadb.Collection]: List of collections.
207
+ """
208
+ return self.client.list_collections()
209
+
210
+ def delete_col(self):
211
+ """
212
+ Delete a collection.
213
+ """
214
+ self.client.delete_collection(name=self.collection_name)
215
+
216
+ def col_info(self) -> Dict:
217
+ """
218
+ Get information about a collection.
219
+
220
+ Returns:
221
+ Dict: Collection information.
222
+ """
223
+ return self.client.get_collection(name=self.collection_name)
224
+
225
+ def list(self, filters: Optional[Dict] = None, limit: int = 100) -> List[OutputData]:
226
+ """
227
+ List all vectors in a collection.
228
+
229
+ Args:
230
+ filters (Optional[Dict], optional): Filters to apply to the list. Defaults to None.
231
+ limit (int, optional): Number of vectors to return. Defaults to 100.
232
+
233
+ Returns:
234
+ List[OutputData]: List of vectors.
235
+ """
236
+ where_clause = self._generate_where_clause(filters) if filters else None
237
+ results = self.collection.get(where=where_clause, limit=limit)
238
+ return [self._parse_output(results)]
239
+
240
+ def reset(self):
241
+ """Reset the index by deleting and recreating it."""
242
+ logger.warning(f"Resetting index {self.collection_name}...")
243
+ self.delete_col()
244
+ self.collection = self.create_col(self.collection_name)
245
+
246
+ @staticmethod
247
+ def _generate_where_clause(where: dict[str, any]) -> dict[str, any]:
248
+ """
249
+ Generate a properly formatted where clause for ChromaDB.
250
+
251
+ Args:
252
+ where (dict[str, any]): The filter conditions.
253
+
254
+ Returns:
255
+ dict[str, any]: Properly formatted where clause for ChromaDB.
256
+ """
257
+ if where is None:
258
+ return {}
259
+
260
+ def convert_condition(key: str, value: any) -> dict:
261
+ """Convert universal filter format to ChromaDB format."""
262
+ if value == "*":
263
+ # Wildcard - match any value (ChromaDB doesn't have direct wildcard, so we skip this filter)
264
+ return None
265
+ elif isinstance(value, dict):
266
+ # Handle comparison operators
267
+ chroma_condition = {}
268
+ for op, val in value.items():
269
+ if op == "eq":
270
+ chroma_condition[key] = {"$eq": val}
271
+ elif op == "ne":
272
+ chroma_condition[key] = {"$ne": val}
273
+ elif op == "gt":
274
+ chroma_condition[key] = {"$gt": val}
275
+ elif op == "gte":
276
+ chroma_condition[key] = {"$gte": val}
277
+ elif op == "lt":
278
+ chroma_condition[key] = {"$lt": val}
279
+ elif op == "lte":
280
+ chroma_condition[key] = {"$lte": val}
281
+ elif op == "in":
282
+ chroma_condition[key] = {"$in": val}
283
+ elif op == "nin":
284
+ chroma_condition[key] = {"$nin": val}
285
+ elif op in ["contains", "icontains"]:
286
+ # ChromaDB doesn't support contains, fallback to equality
287
+ chroma_condition[key] = {"$eq": val}
288
+ else:
289
+ # Unknown operator, treat as equality
290
+ chroma_condition[key] = {"$eq": val}
291
+ return chroma_condition
292
+ else:
293
+ # Simple equality
294
+ return {key: {"$eq": value}}
295
+
296
+ processed_filters = []
297
+
298
+ for key, value in where.items():
299
+ if key == "$or":
300
+ # Handle OR conditions
301
+ or_conditions = []
302
+ for condition in value:
303
+ or_condition = {}
304
+ for sub_key, sub_value in condition.items():
305
+ converted = convert_condition(sub_key, sub_value)
306
+ if converted:
307
+ or_condition.update(converted)
308
+ if or_condition:
309
+ or_conditions.append(or_condition)
310
+
311
+ if len(or_conditions) > 1:
312
+ processed_filters.append({"$or": or_conditions})
313
+ elif len(or_conditions) == 1:
314
+ processed_filters.append(or_conditions[0])
315
+
316
+ elif key == "$not":
317
+ # Handle NOT conditions - ChromaDB doesn't have direct NOT, so we'll skip for now
318
+ continue
319
+
320
+ else:
321
+ # Regular condition
322
+ converted = convert_condition(key, value)
323
+ if converted:
324
+ processed_filters.append(converted)
325
+
326
+ # Return appropriate format based on number of conditions
327
+ if len(processed_filters) == 0:
328
+ return {}
329
+ elif len(processed_filters) == 1:
330
+ return processed_filters[0]
331
+ else:
332
+ return {"$and": processed_filters}
@@ -0,0 +1,67 @@
1
+ from typing import Dict, Optional
2
+
3
+ from pydantic import BaseModel, Field, model_validator
4
+
5
+
6
+ class VectorStoreConfig(BaseModel):
7
+ provider: str = Field(
8
+ description="Provider of the vector store (e.g., 'qdrant', 'chroma', 'upstash_vector')",
9
+ default="qdrant",
10
+ )
11
+ config: Optional[Dict] = Field(description="Configuration for the specific vector store", default=None)
12
+
13
+ _provider_configs: Dict[str, str] = {
14
+ "qdrant": "QdrantConfig",
15
+ "chroma": "ChromaDbConfig",
16
+ "pgvector": "PGVectorConfig",
17
+ "pinecone": "PineconeConfig",
18
+ "mongodb": "MongoDBConfig",
19
+ "milvus": "MilvusDBConfig",
20
+ "baidu": "BaiduDBConfig",
21
+ "neptune": "NeptuneAnalyticsConfig",
22
+ "upstash_vector": "UpstashVectorConfig",
23
+ "azure_ai_search": "AzureAISearchConfig",
24
+ "azure_mysql": "AzureMySQLConfig",
25
+ "redis": "RedisDBConfig",
26
+ "valkey": "ValkeyConfig",
27
+ "databricks": "DatabricksConfig",
28
+ "elasticsearch": "ElasticsearchConfig",
29
+ "vertex_ai_vector_search": "GoogleMatchingEngineConfig",
30
+ "opensearch": "OpenSearchConfig",
31
+ "supabase": "SupabaseConfig",
32
+ "weaviate": "WeaviateConfig",
33
+ "faiss": "FAISSConfig",
34
+ "langchain": "LangchainConfig",
35
+ "aliyun_tablestore": "AliyunTableStoreConfig",
36
+ "s3_vectors": "S3VectorsConfig",
37
+ "alibabacloud_mysql": "MySQLVectorConfig",
38
+ }
39
+
40
+ @model_validator(mode="after")
41
+ def validate_and_create_config(self) -> "VectorStoreConfig":
42
+ provider = self.provider
43
+ config = self.config
44
+
45
+ if provider not in self._provider_configs:
46
+ raise ValueError(f"Unsupported vector store provider: {provider}")
47
+
48
+ module = __import__(
49
+ f"agentrun_mem0.configs.vector_stores.{provider}",
50
+ fromlist=[self._provider_configs[provider]],
51
+ )
52
+ config_class = getattr(module, self._provider_configs[provider])
53
+
54
+ if config is None:
55
+ config = {}
56
+
57
+ if not isinstance(config, dict):
58
+ if not isinstance(config, config_class):
59
+ raise ValueError(f"Invalid config type for provider {provider}")
60
+ return self
61
+
62
+ # also check if path in allowed kays for pydantic model, and whether config extra fields are allowed
63
+ if "path" not in config and "path" in config_class.__annotations__:
64
+ config["path"] = f"/tmp/{provider}"
65
+
66
+ self.config = config_class(**config)
67
+ return self