mem0ai-azure-mysql 0.1.115__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 (116) hide show
  1. mem0/__init__.py +6 -0
  2. mem0/client/__init__.py +0 -0
  3. mem0/client/main.py +1535 -0
  4. mem0/client/project.py +860 -0
  5. mem0/client/utils.py +29 -0
  6. mem0/configs/__init__.py +0 -0
  7. mem0/configs/base.py +90 -0
  8. mem0/configs/dbs/__init__.py +4 -0
  9. mem0/configs/dbs/base.py +41 -0
  10. mem0/configs/dbs/mysql.py +25 -0
  11. mem0/configs/embeddings/__init__.py +0 -0
  12. mem0/configs/embeddings/base.py +108 -0
  13. mem0/configs/enums.py +7 -0
  14. mem0/configs/llms/__init__.py +0 -0
  15. mem0/configs/llms/base.py +152 -0
  16. mem0/configs/prompts.py +333 -0
  17. mem0/configs/vector_stores/__init__.py +0 -0
  18. mem0/configs/vector_stores/azure_ai_search.py +59 -0
  19. mem0/configs/vector_stores/baidu.py +29 -0
  20. mem0/configs/vector_stores/chroma.py +40 -0
  21. mem0/configs/vector_stores/elasticsearch.py +47 -0
  22. mem0/configs/vector_stores/faiss.py +39 -0
  23. mem0/configs/vector_stores/langchain.py +32 -0
  24. mem0/configs/vector_stores/milvus.py +43 -0
  25. mem0/configs/vector_stores/mongodb.py +25 -0
  26. mem0/configs/vector_stores/opensearch.py +41 -0
  27. mem0/configs/vector_stores/pgvector.py +37 -0
  28. mem0/configs/vector_stores/pinecone.py +56 -0
  29. mem0/configs/vector_stores/qdrant.py +49 -0
  30. mem0/configs/vector_stores/redis.py +26 -0
  31. mem0/configs/vector_stores/supabase.py +44 -0
  32. mem0/configs/vector_stores/upstash_vector.py +36 -0
  33. mem0/configs/vector_stores/vertex_ai_vector_search.py +27 -0
  34. mem0/configs/vector_stores/weaviate.py +43 -0
  35. mem0/dbs/__init__.py +4 -0
  36. mem0/dbs/base.py +68 -0
  37. mem0/dbs/configs.py +21 -0
  38. mem0/dbs/mysql.py +321 -0
  39. mem0/embeddings/__init__.py +0 -0
  40. mem0/embeddings/aws_bedrock.py +100 -0
  41. mem0/embeddings/azure_openai.py +43 -0
  42. mem0/embeddings/base.py +31 -0
  43. mem0/embeddings/configs.py +30 -0
  44. mem0/embeddings/gemini.py +39 -0
  45. mem0/embeddings/huggingface.py +41 -0
  46. mem0/embeddings/langchain.py +35 -0
  47. mem0/embeddings/lmstudio.py +29 -0
  48. mem0/embeddings/mock.py +11 -0
  49. mem0/embeddings/ollama.py +53 -0
  50. mem0/embeddings/openai.py +49 -0
  51. mem0/embeddings/together.py +31 -0
  52. mem0/embeddings/vertexai.py +54 -0
  53. mem0/graphs/__init__.py +0 -0
  54. mem0/graphs/configs.py +96 -0
  55. mem0/graphs/neptune/__init__.py +0 -0
  56. mem0/graphs/neptune/base.py +410 -0
  57. mem0/graphs/neptune/main.py +372 -0
  58. mem0/graphs/tools.py +371 -0
  59. mem0/graphs/utils.py +97 -0
  60. mem0/llms/__init__.py +0 -0
  61. mem0/llms/anthropic.py +64 -0
  62. mem0/llms/aws_bedrock.py +270 -0
  63. mem0/llms/azure_openai.py +114 -0
  64. mem0/llms/azure_openai_structured.py +76 -0
  65. mem0/llms/base.py +32 -0
  66. mem0/llms/configs.py +34 -0
  67. mem0/llms/deepseek.py +85 -0
  68. mem0/llms/gemini.py +201 -0
  69. mem0/llms/groq.py +88 -0
  70. mem0/llms/langchain.py +65 -0
  71. mem0/llms/litellm.py +87 -0
  72. mem0/llms/lmstudio.py +53 -0
  73. mem0/llms/ollama.py +94 -0
  74. mem0/llms/openai.py +124 -0
  75. mem0/llms/openai_structured.py +52 -0
  76. mem0/llms/sarvam.py +89 -0
  77. mem0/llms/together.py +88 -0
  78. mem0/llms/vllm.py +89 -0
  79. mem0/llms/xai.py +52 -0
  80. mem0/memory/__init__.py +0 -0
  81. mem0/memory/base.py +63 -0
  82. mem0/memory/graph_memory.py +632 -0
  83. mem0/memory/main.py +1843 -0
  84. mem0/memory/memgraph_memory.py +630 -0
  85. mem0/memory/setup.py +56 -0
  86. mem0/memory/storage.py +218 -0
  87. mem0/memory/telemetry.py +90 -0
  88. mem0/memory/utils.py +133 -0
  89. mem0/proxy/__init__.py +0 -0
  90. mem0/proxy/main.py +194 -0
  91. mem0/utils/factory.py +132 -0
  92. mem0/vector_stores/__init__.py +0 -0
  93. mem0/vector_stores/azure_ai_search.py +383 -0
  94. mem0/vector_stores/baidu.py +368 -0
  95. mem0/vector_stores/base.py +58 -0
  96. mem0/vector_stores/chroma.py +229 -0
  97. mem0/vector_stores/configs.py +60 -0
  98. mem0/vector_stores/elasticsearch.py +235 -0
  99. mem0/vector_stores/faiss.py +473 -0
  100. mem0/vector_stores/langchain.py +179 -0
  101. mem0/vector_stores/milvus.py +245 -0
  102. mem0/vector_stores/mongodb.py +293 -0
  103. mem0/vector_stores/opensearch.py +281 -0
  104. mem0/vector_stores/pgvector.py +294 -0
  105. mem0/vector_stores/pinecone.py +373 -0
  106. mem0/vector_stores/qdrant.py +240 -0
  107. mem0/vector_stores/redis.py +295 -0
  108. mem0/vector_stores/supabase.py +237 -0
  109. mem0/vector_stores/upstash_vector.py +293 -0
  110. mem0/vector_stores/vertex_ai_vector_search.py +629 -0
  111. mem0/vector_stores/weaviate.py +316 -0
  112. mem0ai_azure_mysql-0.1.115.data/data/README.md +169 -0
  113. mem0ai_azure_mysql-0.1.115.dist-info/METADATA +224 -0
  114. mem0ai_azure_mysql-0.1.115.dist-info/RECORD +116 -0
  115. mem0ai_azure_mysql-0.1.115.dist-info/WHEEL +4 -0
  116. mem0ai_azure_mysql-0.1.115.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,372 @@
1
+ import logging
2
+ from .base import NeptuneBase
3
+
4
+ try:
5
+ from langchain_aws import NeptuneAnalyticsGraph
6
+ except ImportError:
7
+ raise ImportError("langchain_aws is not installed. Please install it using 'make install_all'.")
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ class MemoryGraph(NeptuneBase):
13
+ def __init__(self, config):
14
+ self.config = config
15
+
16
+ self.graph = None
17
+ endpoint = self.config.graph_store.config.endpoint
18
+ if endpoint and endpoint.startswith("neptune-graph://"):
19
+ graph_identifier = endpoint.replace("neptune-graph://", "")
20
+ self.graph = NeptuneAnalyticsGraph(graph_identifier)
21
+
22
+ if not self.graph:
23
+ raise ValueError("Unable to create a Neptune client: missing 'endpoint' in config")
24
+
25
+ self.node_label = ":`__Entity__`" if self.config.graph_store.config.base_label else ""
26
+
27
+ self.embedding_model = NeptuneBase._create_embedding_model(self.config)
28
+
29
+ self.llm_provider = "openai_structured"
30
+ if self.config.llm.provider:
31
+ self.llm_provider = self.config.llm.provider
32
+ if self.config.graph_store.llm:
33
+ self.llm_provider = self.config.graph_store.llm.provider
34
+
35
+ self.llm = NeptuneBase._create_llm(self.config, self.llm_provider)
36
+ self.user_id = None
37
+ self.threshold = 0.7
38
+
39
+ def _delete_entities_cypher(self, source, destination, relationship, user_id):
40
+ """
41
+ Returns the OpenCypher query and parameters for deleting entities in the graph DB
42
+
43
+ :param source: source node
44
+ :param destination: destination node
45
+ :param relationship: relationship label
46
+ :param user_id: user_id to use
47
+ :return: str, dict
48
+ """
49
+
50
+ cypher = f"""
51
+ MATCH (n {self.node_label} {{name: $source_name, user_id: $user_id}})
52
+ -[r:{relationship}]->
53
+ (m {self.node_label} {{name: $dest_name, user_id: $user_id}})
54
+ DELETE r
55
+ RETURN
56
+ n.name AS source,
57
+ m.name AS target,
58
+ type(r) AS relationship
59
+ """
60
+ params = {
61
+ "source_name": source,
62
+ "dest_name": destination,
63
+ "user_id": user_id,
64
+ }
65
+ logger.debug(f"_delete_entities\n query={cypher}")
66
+ return cypher, params
67
+
68
+ def _add_entities_cypher(
69
+ self,
70
+ source_node_list,
71
+ source,
72
+ source_embedding,
73
+ source_type,
74
+ destination_node_list,
75
+ destination,
76
+ dest_embedding,
77
+ destination_type,
78
+ relationship,
79
+ user_id,
80
+ ):
81
+ """
82
+ Returns the OpenCypher query and parameters for adding entities in the graph DB
83
+
84
+ :param source_node_list: list of source nodes
85
+ :param source: source node name
86
+ :param source_embedding: source node embedding
87
+ :param source_type: source node label
88
+ :param destination_node_list: list of dest nodes
89
+ :param destination: destination name
90
+ :param dest_embedding: destination embedding
91
+ :param destination_type: destination node label
92
+ :param relationship: relationship label
93
+ :param user_id: user id to use
94
+ :return: str, dict
95
+ """
96
+
97
+ source_label = self.node_label if self.node_label else f":`{source_type}`"
98
+ source_extra_set = f", source:`{source_type}`" if self.node_label else ""
99
+ destination_label = self.node_label if self.node_label else f":`{destination_type}`"
100
+ destination_extra_set = f", destination:`{destination_type}`" if self.node_label else ""
101
+
102
+ # Refactor this code with the graph_memory.py implementation
103
+ if not destination_node_list and source_node_list:
104
+ cypher = f"""
105
+ MATCH (source)
106
+ WHERE id(source) = $source_id
107
+ SET source.mentions = coalesce(source.mentions, 0) + 1
108
+ WITH source
109
+ MERGE (destination {destination_label} {{name: $destination_name, user_id: $user_id}})
110
+ ON CREATE SET
111
+ destination.created = timestamp(),
112
+ destination.mentions = 1
113
+ {destination_extra_set}
114
+ ON MATCH SET
115
+ destination.mentions = coalesce(destination.mentions, 0) + 1
116
+ WITH source, destination, $dest_embedding as dest_embedding
117
+ CALL neptune.algo.vectors.upsert(destination, dest_embedding)
118
+ WITH source, destination
119
+ MERGE (source)-[r:{relationship}]->(destination)
120
+ ON CREATE SET
121
+ r.created = timestamp(),
122
+ r.mentions = 1
123
+ ON MATCH SET
124
+ r.mentions = coalesce(r.mentions, 0) + 1
125
+ RETURN source.name AS source, type(r) AS relationship, destination.name AS target
126
+ """
127
+
128
+ params = {
129
+ "source_id": source_node_list[0]["id(source_candidate)"],
130
+ "destination_name": destination,
131
+ "dest_embedding": dest_embedding,
132
+ "user_id": user_id,
133
+ }
134
+ elif destination_node_list and not source_node_list:
135
+ cypher = f"""
136
+ MATCH (destination)
137
+ WHERE id(destination) = $destination_id
138
+ SET destination.mentions = coalesce(destination.mentions, 0) + 1
139
+ WITH destination
140
+ MERGE (source {source_label} {{name: $source_name, user_id: $user_id}})
141
+ ON CREATE SET
142
+ source.created = timestamp(),
143
+ source.mentions = 1
144
+ {source_extra_set}
145
+ ON MATCH SET
146
+ source.mentions = coalesce(source.mentions, 0) + 1
147
+ WITH source, destination, $source_embedding as source_embedding
148
+ CALL neptune.algo.vectors.upsert(source, source_embedding)
149
+ WITH source, destination
150
+ MERGE (source)-[r:{relationship}]->(destination)
151
+ ON CREATE SET
152
+ r.created = timestamp(),
153
+ r.mentions = 1
154
+ ON MATCH SET
155
+ r.mentions = coalesce(r.mentions, 0) + 1
156
+ RETURN source.name AS source, type(r) AS relationship, destination.name AS target
157
+ """
158
+
159
+ params = {
160
+ "destination_id": destination_node_list[0]["id(destination_candidate)"],
161
+ "source_name": source,
162
+ "source_embedding": source_embedding,
163
+ "user_id": user_id,
164
+ }
165
+ elif source_node_list and destination_node_list:
166
+ cypher = f"""
167
+ MATCH (source)
168
+ WHERE id(source) = $source_id
169
+ SET source.mentions = coalesce(source.mentions, 0) + 1
170
+ WITH source
171
+ MATCH (destination)
172
+ WHERE id(destination) = $destination_id
173
+ SET destination.mentions = coalesce(destination.mentions) + 1
174
+ MERGE (source)-[r:{relationship}]->(destination)
175
+ ON CREATE SET
176
+ r.created_at = timestamp(),
177
+ r.updated_at = timestamp(),
178
+ r.mentions = 1
179
+ ON MATCH SET r.mentions = coalesce(r.mentions, 0) + 1
180
+ RETURN source.name AS source, type(r) AS relationship, destination.name AS target
181
+ """
182
+ params = {
183
+ "source_id": source_node_list[0]["id(source_candidate)"],
184
+ "destination_id": destination_node_list[0]["id(destination_candidate)"],
185
+ "user_id": user_id,
186
+ }
187
+ else:
188
+ cypher = f"""
189
+ MERGE (n {source_label} {{name: $source_name, user_id: $user_id}})
190
+ ON CREATE SET n.created = timestamp(),
191
+ n.mentions = 1
192
+ {source_extra_set}
193
+ ON MATCH SET n.mentions = coalesce(n.mentions, 0) + 1
194
+ WITH n, $source_embedding as source_embedding
195
+ CALL neptune.algo.vectors.upsert(n, source_embedding)
196
+ WITH n
197
+ MERGE (m {destination_label} {{name: $dest_name, user_id: $user_id}})
198
+ ON CREATE SET m.created = timestamp(),
199
+ m.mentions = 1
200
+ {destination_extra_set}
201
+ ON MATCH SET m.mentions = coalesce(m.mentions, 0) + 1
202
+ WITH n, m, $dest_embedding as dest_embedding
203
+ CALL neptune.algo.vectors.upsert(m, dest_embedding)
204
+ WITH n, m
205
+ MERGE (n)-[rel:{relationship}]->(m)
206
+ ON CREATE SET rel.created = timestamp(), rel.mentions = 1
207
+ ON MATCH SET rel.mentions = coalesce(rel.mentions, 0) + 1
208
+ RETURN n.name AS source, type(rel) AS relationship, m.name AS target
209
+ """
210
+ params = {
211
+ "source_name": source,
212
+ "dest_name": destination,
213
+ "source_embedding": source_embedding,
214
+ "dest_embedding": dest_embedding,
215
+ "user_id": user_id,
216
+ }
217
+ logger.debug(
218
+ f"_add_entities:\n destination_node_search_result={destination_node_list}\n source_node_search_result={source_node_list}\n query={cypher}"
219
+ )
220
+ return cypher, params
221
+
222
+ def _search_source_node_cypher(self, source_embedding, user_id, threshold):
223
+ """
224
+ Returns the OpenCypher query and parameters to search for source nodes
225
+
226
+ :param source_embedding: source vector
227
+ :param user_id: user_id to use
228
+ :param threshold: the threshold for similarity
229
+ :return: str, dict
230
+ """
231
+ cypher = f"""
232
+ MATCH (source_candidate {self.node_label})
233
+ WHERE source_candidate.user_id = $user_id
234
+
235
+ WITH source_candidate, $source_embedding as v_embedding
236
+ CALL neptune.algo.vectors.distanceByEmbedding(
237
+ v_embedding,
238
+ source_candidate,
239
+ {{metric:"CosineSimilarity"}}
240
+ ) YIELD distance
241
+ WITH source_candidate, distance AS cosine_similarity
242
+ WHERE cosine_similarity >= $threshold
243
+
244
+ WITH source_candidate, cosine_similarity
245
+ ORDER BY cosine_similarity DESC
246
+ LIMIT 1
247
+
248
+ RETURN id(source_candidate), cosine_similarity
249
+ """
250
+
251
+ params = {
252
+ "source_embedding": source_embedding,
253
+ "user_id": user_id,
254
+ "threshold": threshold,
255
+ }
256
+ logger.debug(f"_search_source_node\n query={cypher}")
257
+ return cypher, params
258
+
259
+ def _search_destination_node_cypher(self, destination_embedding, user_id, threshold):
260
+ """
261
+ Returns the OpenCypher query and parameters to search for destination nodes
262
+
263
+ :param source_embedding: source vector
264
+ :param user_id: user_id to use
265
+ :param threshold: the threshold for similarity
266
+ :return: str, dict
267
+ """
268
+ cypher = f"""
269
+ MATCH (destination_candidate {self.node_label})
270
+ WHERE destination_candidate.user_id = $user_id
271
+
272
+ WITH destination_candidate, $destination_embedding as v_embedding
273
+ CALL neptune.algo.vectors.distanceByEmbedding(
274
+ v_embedding,
275
+ destination_candidate,
276
+ {{metric:"CosineSimilarity"}}
277
+ ) YIELD distance
278
+ WITH destination_candidate, distance AS cosine_similarity
279
+ WHERE cosine_similarity >= $threshold
280
+
281
+ WITH destination_candidate, cosine_similarity
282
+ ORDER BY cosine_similarity DESC
283
+ LIMIT 1
284
+
285
+ RETURN id(destination_candidate), cosine_similarity
286
+ """
287
+ params = {
288
+ "destination_embedding": destination_embedding,
289
+ "user_id": user_id,
290
+ "threshold": threshold,
291
+ }
292
+
293
+ logger.debug(f"_search_destination_node\n query={cypher}")
294
+ return cypher, params
295
+
296
+ def _delete_all_cypher(self, filters):
297
+ """
298
+ Returns the OpenCypher query and parameters to delete all edges/nodes in the memory store
299
+
300
+ :param filters: search filters
301
+ :return: str, dict
302
+ """
303
+ cypher = f"""
304
+ MATCH (n {self.node_label} {{user_id: $user_id}})
305
+ DETACH DELETE n
306
+ """
307
+ params = {"user_id": filters["user_id"]}
308
+
309
+ logger.debug(f"delete_all query={cypher}")
310
+ return cypher, params
311
+
312
+ def _get_all_cypher(self, filters, limit):
313
+ """
314
+ Returns the OpenCypher query and parameters to get all edges/nodes in the memory store
315
+
316
+ :param filters: search filters
317
+ :param limit: return limit
318
+ :return: str, dict
319
+ """
320
+
321
+ cypher = f"""
322
+ MATCH (n {self.node_label} {{user_id: $user_id}})-[r]->(m {self.node_label} {{user_id: $user_id}})
323
+ RETURN n.name AS source, type(r) AS relationship, m.name AS target
324
+ LIMIT $limit
325
+ """
326
+ params = {"user_id": filters["user_id"], "limit": limit}
327
+ return cypher, params
328
+
329
+ def _search_graph_db_cypher(self, n_embedding, filters, limit):
330
+ """
331
+ Returns the OpenCypher query and parameters to search for similar nodes in the memory store
332
+
333
+ :param n_embedding: node vector
334
+ :param filters: search filters
335
+ :param limit: return limit
336
+ :return: str, dict
337
+ """
338
+
339
+ cypher_query = f"""
340
+ MATCH (n {self.node_label})
341
+ WHERE n.user_id = $user_id
342
+ WITH n, $n_embedding as n_embedding
343
+ CALL neptune.algo.vectors.distanceByEmbedding(
344
+ n_embedding,
345
+ n,
346
+ {{metric:"CosineSimilarity"}}
347
+ ) YIELD distance
348
+ WITH n, distance as similarity
349
+ WHERE similarity >= $threshold
350
+ CALL {{
351
+ WITH n
352
+ MATCH (n)-[r]->(m)
353
+ RETURN n.name AS source, id(n) AS source_id, type(r) AS relationship, id(r) AS relation_id, m.name AS destination, id(m) AS destination_id
354
+ UNION ALL
355
+ WITH n
356
+ MATCH (m)-[r]->(n)
357
+ RETURN m.name AS source, id(m) AS source_id, type(r) AS relationship, id(r) AS relation_id, n.name AS destination, id(n) AS destination_id
358
+ }}
359
+ WITH distinct source, source_id, relationship, relation_id, destination, destination_id, similarity
360
+ RETURN source, source_id, relationship, relation_id, destination, destination_id, similarity
361
+ ORDER BY similarity DESC
362
+ LIMIT $limit
363
+ """
364
+ params = {
365
+ "n_embedding": n_embedding,
366
+ "threshold": self.threshold,
367
+ "user_id": filters["user_id"],
368
+ "limit": limit,
369
+ }
370
+ logger.debug(f"_search_graph_db\n query={cypher_query}")
371
+
372
+ return cypher_query, params