Commit 8a55e35
authored
Finalize spec for index schema and fields (#103)
Advanced search operations require the ability to define rules and
configurations about what data should be indexed, how it should be
indexed, and how the database should handle this data on read/write.
Redis handles this in a declarative manner, allowing for the dev to
explicitly control these components of the search patterns.
An `IndexSchema` is what RedisVL uses to simplify this approach for
users. The goal is not to replace the core search API.. but rather to
create an easier onramp for less redis-savy developers, i.e. AI-native
developers.
This PR applies a significant overhaul to the v0 implementation of
schema in redisvl; with an additional goal of incorporating feedback
from across the company/product/users for a better longterm approach in
the ecosystem.
Below is a quick example from the class docstring:
```python
from redisvl.schema import IndexSchema
# From YAML
schema = IndexSchema.from_yaml("schema.yaml")
# From Dict
schema = IndexSchema.from_dict({
"index": {
"name": "user-index",
"prefix": "user",
"storage_type": "json",
},
"fields": [
{"name": "user", "type": "tag"},
{"name": "credit_score", "type": "tag"},
{
"name": "embedding",
"type": "vector",
"attrs": {
"algorithm": "flat",
"dims": 3,
"distance_metrics": "cosine",
"datatype": "float32"
}
}
]
})
```
```
Note:
The `fields` attribute in the schema must contain unique field names to ensure
correct and unambiguous field references.
```
## `IndexSchema` Components
### Index Info
Each index has a set of attributes like the index `name`, the chosen key
`prefix`, and the underlying `storage_type`. In RedisVL, we also
introduce the setting for `key_separator` which allows you to customize
what char is used to separate the prefix from the identifier in the
Redis key.
```python
class IndexInfo(BaseModel):
"""
Represents the basic configuration information for an index in Redis.
This class includes the essential details required to define an index, such as
its name, prefix, key separator, and storage type.
"""
name: str
"""The unique name of the index."""
prefix: str = "rvl"
"""The prefix used for Redis keys associated with this index."""
key_separator: str = ":"
"""The separator character used in Redis keys."""
storage_type: StorageType = StorageType.HASH
"""The storage type used in Redis (e.g., 'hash' or 'json')."""
```
Index info can be parsed from a YAML or dict-like representation:
```yaml
index:
name: user-index-v1
prefix: user
key_separator: ':'
storage_type: json
```
### Fields
Fields are a list of.... field definitions that are to be included in
the redis index (info as described above). A field has a `name`, `type`,
`path` (optional, only for JSON index), and `attrs` (optional settings
per field):
```python
class BaseField(BaseModel):
"""Base field"""
name: str
"""Field name"""
type: str
"""Field type"""
path: Optional[str] = None
"""Field path (within JSON object)"""
attrs: Optional[Union[BaseFieldAttributes, BaseVectorFieldAttributes]] = None
"""Specified field attributes"""
```
Fields can be listed in either a dictionary or YAML representation like
the following:
```yaml
fields:
- name: user
type: tag
path: '.user'
- name: credit_score
type: tag
path: '$.credit_score'
- name: embedding
type: vector
path: '$.embedding'
attrs:
algorithm: flat
dims: 3
distance_metric: cosine
datatype: float32
```
### Version
The schema will be locked in a `0.1.0`. The pydantic model for
`IndexSchema` prevents the user from fatfingering or using the incorrect
version of the schema for this version of the library. It is a fixed
variable.
```yaml
version: '0.1.0'
```1 parent c3e036b commit 8a55e35
File tree
33 files changed
+1311
-905
lines changed- docs
- _static/js
- api
- examples
- user_guide
- redisvl
- cli
- llmcache
- schema
- utils
- schemas
- tests
- integration
- unit
33 files changed
+1311
-905
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 15 | + | |
20 | 16 | | |
| 17 | + | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | | - | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
| |||
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 84 | | |
94 | 85 | | |
95 | 86 | | |
| |||
653 | 644 | | |
654 | 645 | | |
655 | 646 | | |
656 | | - | |
| 647 | + | |
657 | 648 | | |
658 | 649 | | |
659 | 650 | | |
| |||
667 | 658 | | |
668 | 659 | | |
669 | 660 | | |
| 661 | + | |
| 662 | + | |
670 | 663 | | |
671 | | - | |
672 | | - | |
| 664 | + | |
| 665 | + | |
673 | 666 | | |
674 | 667 | | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
682 | 677 | | |
683 | 678 | | |
684 | 679 | | |
| |||
690 | 685 | | |
691 | 686 | | |
692 | 687 | | |
| 688 | + | |
| 689 | + | |
693 | 690 | | |
694 | 691 | | |
| 692 | + | |
| 693 | + | |
695 | 694 | | |
696 | | - | |
| 695 | + | |
697 | 696 | | |
698 | 697 | | |
699 | 698 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | | - | |
49 | | - | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| |||
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | | - | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
| |||
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
90 | | - | |
91 | | - | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
115 | | - | |
| 118 | + | |
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
| |||
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
129 | | - | |
| 132 | + | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| |||
138 | 141 | | |
139 | 142 | | |
140 | 143 | | |
141 | | - | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
147 | | - | |
| 150 | + | |
148 | 151 | | |
149 | 152 | | |
150 | 153 | | |
| |||
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
159 | | - | |
| 162 | + | |
160 | 163 | | |
161 | 164 | | |
162 | 165 | | |
| |||
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
186 | | - | |
| 189 | + | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
| |||
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
204 | | - | |
205 | | - | |
| 207 | + | |
| 208 | + | |
206 | 209 | | |
207 | 210 | | |
208 | 211 | | |
| |||
250 | 253 | | |
251 | 254 | | |
252 | 255 | | |
253 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
254 | 274 | | |
255 | 275 | | |
256 | 276 | | |
| |||
0 commit comments