From 9cd20080fc259a84ed326fa492edffc2ca063d22 Mon Sep 17 00:00:00 2001 From: talos <40233642+Talostat@users.noreply.github.com> Date: Wed, 26 Feb 2025 23:10:13 +0800 Subject: [PATCH] community: Update SQLiteVec table trigger (#29914) **Issue**: This trigger can only be used by the first table created. Cannot create additional triggers for other tables. **fixed**: Update the trigger name so that it can be used for new tables. --------- Co-authored-by: Chester Curme --- .../vectorstores/sqlitevec.py | 2 +- .../vectorstores/test_sqlitevec.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libs/community/langchain_community/vectorstores/sqlitevec.py b/libs/community/langchain_community/vectorstores/sqlitevec.py index 52da1942f5a..e8ea7b60ec6 100644 --- a/libs/community/langchain_community/vectorstores/sqlitevec.py +++ b/libs/community/langchain_community/vectorstores/sqlitevec.py @@ -95,7 +95,7 @@ class SQLiteVec(VectorStore): ) self._connection.execute( f""" - CREATE TRIGGER IF NOT EXISTS embed_text + CREATE TRIGGER IF NOT EXISTS {self._table}_embed_text AFTER INSERT ON {self._table} BEGIN INSERT INTO {self._table}_vec(rowid, text_embedding) diff --git a/libs/community/tests/integration_tests/vectorstores/test_sqlitevec.py b/libs/community/tests/integration_tests/vectorstores/test_sqlitevec.py index f7c67ba5299..01073f4c11a 100644 --- a/libs/community/tests/integration_tests/vectorstores/test_sqlitevec.py +++ b/libs/community/tests/integration_tests/vectorstores/test_sqlitevec.py @@ -56,3 +56,27 @@ def test_sqlitevec_add_extra() -> None: docsearch.add_texts(texts, metadatas) output = docsearch.similarity_search("foo", k=10) assert len(output) == 6 + + +@pytest.mark.requires("sqlite-vec") +def test_sqlitevec_search_multiple_tables() -> None: + """Test end to end construction and search with multiple tables.""" + docsearch_1 = SQLiteVec.from_texts( + fake_texts, + FakeEmbeddings(), + table="table_1", + db_file=":memory:", ## change to local storage for testing + ) + + docsearch_2 = SQLiteVec.from_texts( + fake_texts, + FakeEmbeddings(), + table="table_2", + db_file=":memory:", + ) + + output_1 = docsearch_1.similarity_search("foo", k=1) + output_2 = docsearch_2.similarity_search("foo", k=1) + + assert output_1 == [Document(page_content="foo", metadata={})] + assert output_2 == [Document(page_content="foo", metadata={})]