Skip to content

Commit

Permalink
[BUG]: Fixed a typo in metadata sqlite filtering (#1264)
Browse files Browse the repository at this point in the history
Ref: #1252 

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Fixed a typo in the sqlite metadata filtering where the name of the
should be `string_value` (not `str_value`)

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python

## Documentation Changes
N/A
  • Loading branch information
tazarov authored Oct 23, 2023
1 parent 019b954 commit 5a5e158
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions chromadb/segment/impl/metadata/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def count(self) -> int:
self._db.querybuilder()
.from_(embeddings_t)
.where(
embeddings_t.segment_id == ParameterValue(self._db.uuid_to_db(self._id))
embeddings_t.segment_id == ParameterValue(
self._db.uuid_to_db(self._id))
)
.select(fn.Count(embeddings_t.id))
)
Expand Down Expand Up @@ -139,16 +140,19 @@ def get_metadata(
metadata_t.bool_value,
)
.where(
embeddings_t.segment_id == ParameterValue(self._db.uuid_to_db(self._id))
embeddings_t.segment_id == ParameterValue(
self._db.uuid_to_db(self._id))
)
.orderby(embeddings_t.id)
)

if where:
q = q.where(self._where_map_criterion(q, where, embeddings_t, metadata_t))
q = q.where(self._where_map_criterion(
q, where, embeddings_t, metadata_t))
if where_document:
q = q.where(
self._where_doc_criterion(q, where_document, embeddings_t, fulltext_t)
self._where_doc_criterion(
q, where_document, embeddings_t, fulltext_t)
)

if ids:
Expand Down Expand Up @@ -227,7 +231,8 @@ def _insert_record(
if upsert:
return self._update_record(cur, record)
else:
logger.warning(f"Insert of existing embedding ID: {record['id']}")
logger.warning(
f"Insert of existing embedding ID: {record['id']}")
# We are trying to add for a record that already exists. Fail the call.
# We don't throw an exception since this is in principal an async path
return
Expand Down Expand Up @@ -361,7 +366,8 @@ def _delete_record(self, cur: Cursor, record: EmbeddingRecord) -> None:
sql = sql + " RETURNING id"
result = cur.execute(sql, params).fetchone()
if result is None:
logger.warning(f"Delete of nonexisting embedding ID: {record['id']}")
logger.warning(
f"Delete of nonexisting embedding ID: {record['id']}")
else:
id = result[0]

Expand Down Expand Up @@ -392,7 +398,8 @@ def _update_record(self, cur: Cursor, record: EmbeddingRecord) -> None:
sql = sql + " RETURNING id"
result = cur.execute(sql, params).fetchone()
if result is None:
logger.warning(f"Update of nonexisting embedding ID: {record['id']}")
logger.warning(
f"Update of nonexisting embedding ID: {record['id']}")
else:
id = result[0]
if record["metadata"]:
Expand Down Expand Up @@ -447,7 +454,8 @@ def _where_map_criterion(
]
clause.append(reduce(lambda x, y: x | y, criteria))
else:
expr = cast(Union[LiteralValue, Dict[WhereOperator, LiteralValue]], v)
expr = cast(
Union[LiteralValue, Dict[WhereOperator, LiteralValue]], v)
sq = (
self._db.querybuilder()
.from_(metadata_t)
Expand Down Expand Up @@ -564,7 +572,7 @@ def _value_criterion(
col_exprs = [
table.string_value.isin(ParameterValue(_v))
if op == "$in"
else table.str_value.notin(ParameterValue(_v))
else table.string_value.notin(ParameterValue(_v))
]
elif isinstance(value[0], bool):
col_exprs = [
Expand Down

0 comments on commit 5a5e158

Please sign in to comment.