fix: wrap vector and payload in lists for Langchain.update (#4446)
This commit is contained in:
@@ -115,7 +115,7 @@ class Langchain(VectorStoreBase):
|
|||||||
Update a vector and its payload.
|
Update a vector and its payload.
|
||||||
"""
|
"""
|
||||||
self.delete(vector_id)
|
self.delete(vector_id)
|
||||||
self.insert(vector, payload, [vector_id])
|
self.insert([vector], [payload], [vector_id])
|
||||||
|
|
||||||
def get(self, vector_id):
|
def get(self, vector_id):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -224,3 +224,24 @@ def test_list_with_exception(langchain_instance):
|
|||||||
|
|
||||||
# Verify that an empty list is returned when an exception occurs
|
# Verify that an empty list is returned when an exception occurs
|
||||||
assert results == []
|
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]
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user