Skip to content

Commit

Permalink
fix: Bool column in collection metadata
Browse files Browse the repository at this point in the history
- Fixes the problem for single-node Chroma

Refs: chroma-core#1849
  • Loading branch information
tazarov committed Mar 8, 2024
1 parent 64b39b1 commit e8c3112
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion chromadb/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def maybe_cast_one_to_many_metadata(target: OneOrMany[Metadata]) -> Metadatas:
return cast(Metadatas, target)


CollectionMetadata = Dict[str, Any]
CollectionMetadata = UpdateMetadata
UpdateCollectionMetadata = UpdateMetadata

# Documents
Expand Down
28 changes: 22 additions & 6 deletions chromadb/db/mixins/sysdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def get_collections(
metadata_t.str_value,
metadata_t.int_value,
metadata_t.float_value,
metadata_t.bool_value,
)
.left_join(metadata_t)
.on(collections_t.id == metadata_t.collection_id)
Expand Down Expand Up @@ -456,7 +457,7 @@ def get_collections(

# apply limit and offset
if limit is not None:
collections = collections[offset:offset+limit]
collections = collections[offset : offset + limit]
else:
collections = collections[offset:]

Expand Down Expand Up @@ -664,13 +665,15 @@ def _metadata_from_rows(
)
metadata: Dict[str, Union[str, int, float]] = {}
for row in rows:
key = str(row[-4])
if row[-3] is not None:
metadata[key] = str(row[-3])
key = str(row[-5])
if row[-4] is not None:
metadata[key] = str(row[-4])
elif row[-3] is not None:
metadata[key] = int(row[-3])
elif row[-2] is not None:
metadata[key] = int(row[-2])
metadata[key] = float(row[-2])
elif row[-1] is not None:
metadata[key] = float(row[-1])
metadata[key] = bool(row[-1])
return metadata or None

@trace_method("SqlSysDB._insert_metadata", OpenTelemetryGranularity.ALL)
Expand Down Expand Up @@ -711,6 +714,7 @@ def _insert_metadata(
table.str_value,
table.int_value,
table.float_value,
table.bool_value,
)
)
sql_id = self.uuid_to_db(id)
Expand All @@ -722,6 +726,16 @@ def _insert_metadata(
ParameterValue(v),
None,
None,
None,
)
elif isinstance(v, bool):
q = q.insert(
ParameterValue(sql_id),
ParameterValue(k),
None,
None,
None,
ParameterValue(v),
)
elif isinstance(v, int):
q = q.insert(
Expand All @@ -730,6 +744,7 @@ def _insert_metadata(
None,
ParameterValue(v),
None,
None,
)
elif isinstance(v, float):
q = q.insert(
Expand All @@ -738,6 +753,7 @@ def _insert_metadata(
None,
None,
ParameterValue(v),
None,
)
elif v is None:
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table COLLECTION_METADATA
add bool_value integer;

0 comments on commit e8c3112

Please sign in to comment.