You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** Not all indexes can be deleted. Vector and FTS indexes currently cannot be disabled
255
+
**Note:** Not all indexes can be deleted. Vector indexes currently cannot be disabled.
256
+
</Callout>
257
+
258
+
<Callout>
259
+
**Array metadata and indexes:** Array metadata (e.g. `[1, 2, 3]` or `["action", "comedy"]`) shares the same inverted index as its scalar counterpart. Disabling `IntInvertedIndexConfig` will also prevent `$contains` and `$not_contains` queries on integer arrays, and similarly for other types.
String operations like `contains()` and `regex()` are case-sensitive by default. The `is_in()` operator is efficient even with large lists.
184
+
String operations like `contains()` and `regex()`on `K.DOCUMENT`are case-sensitive by default. When used on metadata fields, `contains()` checks array membership rather than substring matching. The `is_in()` operator is efficient even with large lists.
169
185
</Callout>
170
186
187
+
## Array Metadata
188
+
189
+
Chroma supports storing arrays of values in metadata fields. You can use `contains()` / `not_contains()` (or `$contains` / `$not_contains` in dictionary syntax) to filter records based on whether an array includes a specific scalar value.
190
+
191
+
### Storing Array Metadata
192
+
193
+
Arrays can contain strings, numbers, or booleans. All elements in an array must be the same type. Empty arrays are not allowed.
The `$contains` value must be a scalar that matches the array's element type. All elements in an array must be the same type, and nested arrays are not supported.
316
+
</Warning>
317
+
171
318
## Logical Operators
172
319
173
320
**Supported operators:**
@@ -243,8 +390,8 @@ You can also use dictionary syntax instead of K expressions. This is useful when
243
390
-`$lte` - Less than or equal (numeric only)
244
391
-`$in` - Value in list
245
392
-`$nin` - Value not in list
246
-
-`$contains` - String contains
247
-
-`$not_contains` - String doesn't contain
393
+
-`$contains` - On `#document`: substring search. On metadata fields: array contains value.
394
+
-`$not_contains` - On `#document`: excludes by substring. On metadata fields: array does not contain value.
248
395
-`$regex` - Regex match
249
396
-`$not_regex` - Regex doesn't match
250
397
-`$and` - Logical AND
@@ -268,12 +415,16 @@ You can also use dictionary syntax instead of K expressions. This is useful when
268
415
{"category": {"$in": ["tech", "ai"]}} # Same as K("category").is_in(["tech", "ai"])
269
416
{"status": {"$nin": ["draft", "deleted"]}} # Same as K("status").not_in(["draft", "deleted"])
270
417
271
-
# String operators (currently K.DOCUMENT only)
418
+
# String operators (K.DOCUMENT only)
272
419
{"#document": {"$contains": "API"}} # Same as K.DOCUMENT.contains("API")
**Currently, `contains()`, `not_contains()`, `regex()`, and `not_regex()` operators only work on `K.DOCUMENT`**. These operators do not yet support metadata fields.
646
+
**`regex()` and `not_regex()` only work on `K.DOCUMENT`**. These operators do not yet support metadata fields.
492
647
493
-
Additionally, the pattern must contain at least 3 literal characters to ensure accurate results.
648
+
`contains()` and `not_contains()` have different behavior depending on the field:
649
+
- On `K.DOCUMENT`: substring search (the pattern must have at least 3 literal characters)
650
+
- On metadata fields: array membership check (see [Array Metadata](#array-metadata) above)
651
+
652
+
Substring matching on metadata scalar fields (e.g. checking if a string field contains a substring) is not yet supported.
494
653
495
654
<CodeGroup>
496
655
```python Python
497
-
#Currently supported - K.DOCUMENT only
656
+
#Substring search on K.DOCUMENT - works
498
657
K.DOCUMENT.contains("API") # Works
499
658
K.DOCUMENT.regex(r"v\d\.\d\.\d") # Works
500
-
K.DOCUMENT.contains("machine learning") # Works
501
659
502
-
# NOT YET SUPPORTED - metadata fields
503
-
K("title").contains("Python") # Not supported yet
504
-
K("description").regex(r"API.*") # Not supported yet
660
+
# Array membership on metadata fields - works
661
+
K("tags").contains("action") # Works - checks if array contains value
662
+
663
+
# Substring/regex on metadata scalar fields - NOT YET SUPPORTED
664
+
# K("title").regex(r".*Python.*") # Not supported yet
K.DOCUMENT.contains("API"); // 3 characters - good
524
685
K.DOCUMENT.contains("AI"); // Only 2 characters - may give incorrect results
525
686
K.DOCUMENT.regex("\\d+"); // No literal characters - may give incorrect results
526
687
```
527
688
</CodeGroup>
528
689
529
690
<Warning>
530
-
String pattern matching currently only works on `K.DOCUMENT`. Support for metadata fields is not yet available. Also, patterns with fewer than 3 literal characters may return incorrect results.
691
+
`regex()` and `not_regex()` currently only work on `K.DOCUMENT`. Substring matching on metadata scalar fields is not yet available. Also, patterns with fewer than 3 literal characters may return incorrect results.
531
692
</Warning>
532
693
533
694
<Callout>
534
-
String pattern matching on metadata fields is not currently supported. Full support is coming in a future release, which will allow users to opt-in to additional indexes for string pattern matching on specific metadata fields.
695
+
Substring and regex matching on metadata scalar fields is not currently supported. Full support is coming in a future release, which will allow users to opt-in to additional indexes for string pattern matching on specific metadata fields.
All elements in an array must be the same type, and empty arrays are not allowed. You can filter on array metadata using the `$contains` and `$not_contains` operators — see [Metadata Filtering](/docs/querying-collections/metadata-filtering#using-array-metadata) for details.
179
+
136
180
## Behaviors
137
181
138
182
- If you add a record with an ID that already exists in the collection, it will be ignored without throwing an error. In order to overwrite data in your collection, you must [update](./update-data) the data.
0 commit comments