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={})]