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

- **Description:** The current version of the `delete` method assumes
that the id field will always be called `id`.
- **Issue:** n/a
- **Dependencies:** n/a
- **Twitter handle:** ugh, Twitter :D 

---

Thank you for contributing to LangChain!

- [x] **PR title**: "package: description"
- Where "package" is whichever of langchain, community, core, etc. is
being modified. Use "docs: ..." for purely docs changes, "infra: ..."
for CI changes.
  - Example: "community: add foobar LLM"


- [x] **PR message**: ***Delete this entire checklist*** and replace
with
    - **Description:** a description of the change
    - **Issue:** the issue # it fixes, if applicable
    - **Dependencies:** any dependencies required for this change
- **Twitter handle:** if your PR gets announced, and you'd like a
mention, we'll gladly shout you out!


- [x] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [x] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Brian Sharon 2024-12-11 16:49:35 -07:00 committed by GitHub
parent 8780f7a2ad
commit b20230c800
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -676,7 +676,7 @@ class LanceDB(VectorStore):
if filter: if filter:
tbl.delete(filter) tbl.delete(filter)
elif ids: elif ids:
tbl.delete("id in ('{}')".format(",".join(ids))) tbl.delete(f"{self._id_key} in ('{{}}')".format(",".join(ids)))
elif drop_columns: elif drop_columns:
if self.api_key is not None: if self.api_key is not None:
raise NotImplementedError( raise NotImplementedError(

View File

@ -84,6 +84,16 @@ def test_lancedb_delete() -> None:
assert store.get_table().count_rows() == 2 assert store.get_table().count_rows() == 2
@pytest.mark.requires("lancedb")
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") @pytest.mark.requires("lancedb")
def test_lancedb_all_searches() -> None: def test_lancedb_all_searches() -> None:
embeddings = FakeEmbeddings() embeddings = FakeEmbeddings()