Skip to content

The agent engineering platform.

community: use correct `id_key` when deleting by id in LanceDB wrapper (#28655)

Brian Sharonb20230c8009d
diff --git a/libs/community/langchain_community/vectorstores/lancedb.py b/libs/community/langchain_community/vectorstores/lancedb.py
index bcde354e88..7253d885b1 100644
--- a/libs/community/langchain_community/vectorstores/lancedb.py
+++ b/libs/community/langchain_community/vectorstores/lancedb.py
@@ -676,7 +676,7 @@ class LanceDB(VectorStore):
if filter:
tbl.delete(filter)
elif ids:
- tbl.delete("id in ('{}')".format(",".join(ids)))
+ tbl.delete(f"{self._id_key} in ('{{}}')".format(",".join(ids)))
elif drop_columns:
if self.api_key is not None:
raise NotImplementedError(
diff --git a/libs/community/tests/integration_tests/vectorstores/test_lancedb.py b/libs/community/tests/integration_tests/vectorstores/test_lancedb.py
index 7152c93bfa..7ba3a00466 100644
--- a/libs/community/tests/integration_tests/vectorstores/test_lancedb.py
+++ b/libs/community/tests/integration_tests/vectorstores/test_lancedb.py
@@ -84,6 +84,16 @@ def test_lancedb_delete() -> None:
assert store.get_table().count_rows() == 2
+def test_lancedb_delete_by_ids() -> None:
+ embeddings = FakeEmbeddings()
+
+ store = LanceDB(embedding=embeddings, id_key="pk")
+ ids = store.add_texts(["text 1", "text 2", "item 3"])
+ store.delete(ids=ids)
+ assert store.get_table().count_rows() == 0
+
+
@pytest.mark.requires("lancedb")
def test_lancedb_all_searches() -> None:
embeddings = FakeEmbeddings()