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.

fix: wrap vector and payload in lists for Langchain.update (#4446)

Kartik73038900f505
diff --git a/mem0/vector_stores/langchain.py b/mem0/vector_stores/langchain.py
index 4fe06c1b1..844c5d414 100644
--- a/mem0/vector_stores/langchain.py
+++ b/mem0/vector_stores/langchain.py
@@ -115,7 +115,7 @@ class Langchain(VectorStoreBase):
Update a vector and its payload.
"""
self.delete(vector_id)
- self.insert(vector, payload, [vector_id])
+ self.insert([vector], [payload], [vector_id])
def get(self, vector_id):
"""
diff --git a/tests/vector_stores/test_langchain_vector_store.py b/tests/vector_stores/test_langchain_vector_store.py
index 5f1a8c544..6dd85d042 100644
--- a/tests/vector_stores/test_langchain_vector_store.py
+++ b/tests/vector_stores/test_langchain_vector_store.py
@@ -224,3 +224,24 @@ def test_list_with_exception(langchain_instance):
# Verify that an empty list is returned when an exception occurs
assert results == []
+
+
+def test_update_wraps_vector_and_payload_in_lists(langchain_instance):
+ """Regression test for Langchain update() type mismatch.
+
+ update() must wrap vector and payload in lists before calling insert(),
+ which expects List[List[float]] and List[Dict] respectively.
+ """
+ langchain_instance.client.delete = Mock()
+ langchain_instance.client.add_embeddings = Mock()
+
+ vector = [0.1, 0.2, 0.3]
+ payload = {"data": "updated text", "name": "updated"}
+ vector_id = "id1"
+
+ langchain_instance.update(vector_id=vector_id, vector=vector, payload=payload)
+
+ langchain_instance.client.delete.assert_called_once_with(ids=[vector_id])
+ langchain_instance.client.add_embeddings.assert_called_once_with(
+ embeddings=[vector], metadatas=[payload], ids=[vector_id]
+ )