From eafa0e429cfc5a4d6e8573161b42bd0e023e2839 Mon Sep 17 00:00:00 2001 From: Yash Pratap Solanky <101447028+ysolanky@users.noreply.github.com> Date: Thu, 6 Feb 2025 10:50:13 -0500 Subject: [PATCH] lance-db-name_exists-ag-2655 (#2024) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - Added `name_exists` function for LanceDb. Fixes #2017 --- ## Type of change Please check the options that are relevant: - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Model update (Addition or modification of models) - [ ] Other (please describe): --- ## Checklist - [ ] Adherence to standards: Code complies with Agno’s style guidelines and best practices. - [ ] Formatting and validation: You have run `./scripts/format.sh` and `./scripts/validate.sh` to ensure code is formatted and linted. - [ ] Self-review completed: A thorough review has been performed by the contributor(s). - [ ] Documentation: Docstrings and comments have been added or updated for any complex logic. - [ ] Examples and guides: Relevant cookbook examples have been included or updated (if applicable). - [ ] Tested in a clean environment: Changes have been tested in a clean environment to confirm expected behavior. - [ ] Tests (optional): Tests have been added or updated to cover any new or changed functionality. --- ## Additional Notes LanceDb natively does not allow `name_exists`. This is a very inefficient workaround. To be updated when native search for a doc name is added by LanceDb. `name_exists` is used by the `WebsiteKnowledgeBase` --------- Co-authored-by: Dirk Brand <51947788+dirkbrnd@users.noreply.github.com> --- libs/agno/agno/vectordb/lancedb/lance_db.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/agno/agno/vectordb/lancedb/lance_db.py b/libs/agno/agno/vectordb/lancedb/lance_db.py index 843bc8e2d3..13d99f2580 100644 --- a/libs/agno/agno/vectordb/lancedb/lance_db.py +++ b/libs/agno/agno/vectordb/lancedb/lance_db.py @@ -326,4 +326,7 @@ def delete(self) -> bool: return False def name_exists(self, name: str) -> bool: - raise NotImplementedError + if self.table is None: + return False + result = self.table.search().select(["payload"]).to_pandas() + return any(row["payload"].get("name") == name for _, row in result.iterrows())