Skip to content

Commit 226c4c3

Browse files
committed
Add documentation for Vectorize range queries
1 parent 2ef9f57 commit 226c4c3

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/content/changelogs/vectorize.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ productLink: "/vectorize/"
55
productArea: Developer platform
66
productAreaLink: /workers/platform/changelog/platform/
77
entries:
8+
- publish_date: "2024-12-19"
9+
title: Added support for range queries in metadata filters
10+
description: |-
11+
Vectorize now supports `$lt`, `$lte`, `$gt`, and `$gte` clauses in [metadata filters](/vectorize/reference/metadata-filtering/).
12+
813
- publish_date: "2024-11-13"
914
title: Added support for `$in` and `$nin` metadata filters
1015
description: |-

src/content/docs/vectorize/reference/metadata-filtering.mdx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,26 @@ Vectors upserted before a metadata index was created won't have their metadata c
3131

3232
## Supported operations
3333

34-
Optional `filter` property on `query()` method specifies metadata filter:
35-
36-
| Operator | Description |
37-
| -------- | ----------- |
38-
| `$eq` | Equals |
39-
| `$ne` | Not equals |
40-
| `$in` | In |
41-
| `$nin` | Not in |
34+
An optional `filter` property on `query()` method specifies metadata filters:
35+
36+
| Operator | Description |
37+
| -------- | ------------------------ |
38+
| `$eq` | Equals |
39+
| `$ne` | Not equals |
40+
| `$in` | In |
41+
| `$nin` | Not in |
42+
| `$lt` | Less than |
43+
| `$lte` | Less than or equal to |
44+
| `$gt` | Greater than |
45+
| `$gte` | Greater than or equal to |
4246

4347
- `filter` must be non-empty object whose compact JSON representation must be less than 2048 bytes.
4448
- `filter` object keys cannot be empty, contain `" | .` (dot is reserved for nesting), start with `$`, or be longer than 512 characters.
4549
- For `$eq` and `$ne`, `filter` object non-nested values can be `string`, `number`, `boolean`, or `null` values.
4650
- For `$in` and `$nin`, `filter` object values can be arrays of `string`, `number`, `boolean`, or `null` values.
51+
- Upper-bound range queries (i.e. `$lt` and `$lte`) can be combined with lower-bound range queries (i.e. `$gt` and `$gte`) within the same filter. Other combinations are not allowed.
52+
- For range queries (i.e. `$lt`, `$lte`, `$gt`, `$gte`), `filter` object non-nested values can be `string` or `number` values. Strings are ordered lexicographically.
53+
- Range queries involving a large number of vectors (~10M and above) may experience reduced accuracy.
4754

4855
### Namespace versus metadata filtering
4956

@@ -78,6 +85,20 @@ Both [namespaces](/vectorize/best-practices/insert-vectors/#namespaces) and meta
7885
{ "someKey": { "$nin": ["hbo", "netflix"] } }
7986
```
8087

88+
#### Range query involving numbers
89+
90+
```json
91+
{ "timestamp": { "$gte": 1734242400, "$lt": 1734328800 } }
92+
```
93+
94+
#### Range query involving strings
95+
Range queries can be used to implement prefix searching on string metadata fields.
96+
For example, the following filter matches all values starting with "net":
97+
98+
```json
99+
{ "someKey": { "$gte": "net", "$lt": "neu" } }
100+
```
101+
81102
#### Implicit logical `AND` with multiple keys
82103

83104
```json

0 commit comments

Comments
 (0)