Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: FTS delete #1664

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions chromadb/segment/impl/metadata/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ def _where_doc_criterion(
def delete(self) -> None:
t = Table("embeddings")
t1 = Table("embedding_metadata")
t2 = Table("embedding_fulltext_search")
q0 = (
self._db.querybuilder()
.from_(t1)
Expand Down Expand Up @@ -603,7 +604,23 @@ def delete(self) -> None:
)
)
)
q_fts = (
self._db.querybuilder()
.from_(t2)
.delete()
.where(
t2.rowid.isin(
self._db.querybuilder()
.from_(t)
.select(t.id)
.where(
t.segment_id == ParameterValue(self._db.uuid_to_db(self._id))
)
)
)
)
with self._db.tx() as cur:
cur.execute(*get_sql(q_fts))
cur.execute(*get_sql(q0))
cur.execute(*get_sql(q))

Expand Down
20 changes: 20 additions & 0 deletions chromadb/test/segment/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,23 @@ def test_delete_segment(
res = cur.execute(sql, params)
# assert that the segment is gone
assert len(res.fetchall()) == 0

fts_t = Table("embedding_fulltext_search")
q_fts = (
_db.querybuilder()
.from_(fts_t)
.select()
.where(
fts_t.rowid.isin(
_db.querybuilder()
.from_(t)
.select(t.id)
.where(t.segment_id == ParameterValue(_db.uuid_to_db(_id)))
)
)
)
sql, params = get_sql(q_fts)
with _db.tx() as cur:
res = cur.execute(sql, params)
# assert that all FTS rows are gone
assert len(res.fetchall()) == 0
Loading