mirror of
https://github.com/hwchase17/langchain.git
synced 2025-04-30 21:05:36 +00:00
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:
parent
7562677f3f
commit
9cd20080fc
libs/community
@ -95,7 +95,7 @@ class SQLiteVec(VectorStore):
|
|||||||
)
|
)
|
||||||
self._connection.execute(
|
self._connection.execute(
|
||||||
f"""
|
f"""
|
||||||
CREATE TRIGGER IF NOT EXISTS embed_text
|
CREATE TRIGGER IF NOT EXISTS {self._table}_embed_text
|
||||||
AFTER INSERT ON {self._table}
|
AFTER INSERT ON {self._table}
|
||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO {self._table}_vec(rowid, text_embedding)
|
INSERT INTO {self._table}_vec(rowid, text_embedding)
|
||||||
|
@ -56,3 +56,27 @@ def test_sqlitevec_add_extra() -> None:
|
|||||||
docsearch.add_texts(texts, metadatas)
|
docsearch.add_texts(texts, metadatas)
|
||||||
output = docsearch.similarity_search("foo", k=10)
|
output = docsearch.similarity_search("foo", k=10)
|
||||||
assert len(output) == 6
|
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={})]
|
||||||
|
Loading…
Reference in New Issue
Block a user