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 <chester.curme@gmail.com>
This commit is contained in:
talos 2025-02-26 23:10:13 +08:00 committed by GitHub
parent 7562677f3f
commit 9cd20080fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -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)

View File

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