Skip to content

Commit 4d90b55

Browse files
committed
feat: Update multi-category examples
1 parent a27aa43 commit 4d90b55

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

docs/strategies/multi-category-filters.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
# Multi-Category Filters
1+
# Multi-Category/Tag Filters
22

3-
Sometimes you may want to filter documents in Chroma based on multiple categories e.g. `games` and `movies`.
3+
Sometimes you may want to filter documents in Chroma based on multiple categories or tags e.g. `games` and `movies`.
44
Unfortunately, Chroma does not yet support complex data-types like lists or sets so that one can use a single metadata
55
field to store and filter by. It is also not possible to use fuzzy search `LIKE` queries on metadata fields.
66

77
To solve this problem without introducing a complex logic on the client side, we suggest the following approach.
88

99
When adding document to a collection add each category it belongs to as a boolean metadata field:
1010

11-
!!! note "No Empty Categories"
11+
!!! note "No Empty Categories/Tags"
1212

1313
Only add categories an item belongs to with flags set to `True`.
1414
Do not add categories an item does not belong to and set the flag to `False`.
1515

1616
```python
17-
import uuid
1817

19-
collection.add(ids=[f"{uuid.uuid4()}"], documents=["This is a document"], metadatas=[{"games": True, "movies": True}])
18+
collection.add(
19+
ids=[f"{uuid.uuid4()}"],
20+
documents=["This is a document"],
21+
metadatas=[{"games": True, "movies": True}],
22+
)
2023
```
2124

2225
When querying documents, you can filter by multiple categories by using the `where` parameter:
2326

2427
```python
25-
results = collection.query(query_texts=["This is a query document"], where={"games": True, "movies": True})
28+
results = collection.query(
29+
query_texts=["This is a query document"],
30+
where={"games": True},
31+
)
32+
# or a more complex query
33+
results = collection.query(
34+
query_texts=["This is a query document"],
35+
where={"$or": [{"games": True}, {"movies": True}]},
36+
)
2637
```
27-

0 commit comments

Comments
 (0)