Skip to content

Commit 3ab7e19

Browse files
use an enum for field type literals
1 parent 0cf4411 commit 3ab7e19

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

redisvl/schema/fields.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
from redis.commands.search.field import VectorField as RedisVectorField
1818

1919

20+
class FieldTypes(str, Enum):
21+
TAG = "tag"
22+
TEXT = "text"
23+
NUMERIC = "numeric"
24+
GEO = "geo"
25+
VECTOR = "vector"
26+
27+
2028
class VectorDistanceMetric(str, Enum):
2129
COSINE = "COSINE"
2230
L2 = "L2"
@@ -167,7 +175,7 @@ def as_redis_field(self) -> RedisField:
167175
class TextField(BaseField):
168176
"""Text field supporting a full text search index"""
169177

170-
type: Literal["text"] = "text"
178+
type: Literal[FieldTypes.TEXT] = FieldTypes.TEXT
171179
attrs: TextFieldAttributes = Field(default_factory=TextFieldAttributes)
172180

173181
def as_redis_field(self) -> RedisField:
@@ -185,7 +193,7 @@ def as_redis_field(self) -> RedisField:
185193
class TagField(BaseField):
186194
"""Tag field for simple boolean-style filtering"""
187195

188-
type: Literal["tag"] = "tag"
196+
type: Literal[FieldTypes.TAG] = FieldTypes.TAG
189197
attrs: TagFieldAttributes = Field(default_factory=TagFieldAttributes)
190198

191199
def as_redis_field(self) -> RedisField:
@@ -202,7 +210,7 @@ def as_redis_field(self) -> RedisField:
202210
class NumericField(BaseField):
203211
"""Numeric field for numeric range filtering"""
204212

205-
type: Literal["numeric"] = "numeric"
213+
type: Literal[FieldTypes.NUMERIC] = FieldTypes.NUMERIC
206214
attrs: NumericFieldAttributes = Field(default_factory=NumericFieldAttributes)
207215

208216
def as_redis_field(self) -> RedisField:
@@ -217,7 +225,7 @@ def as_redis_field(self) -> RedisField:
217225
class GeoField(BaseField):
218226
"""Geo field with a geo-spatial index for location based search"""
219227

220-
type: Literal["geo"] = "geo"
228+
type: Literal[FieldTypes.GEO] = FieldTypes.GEO
221229
attrs: GeoFieldAttributes = Field(default_factory=GeoFieldAttributes)
222230

223231
def as_redis_field(self) -> RedisField:
@@ -232,7 +240,7 @@ def as_redis_field(self) -> RedisField:
232240
class FlatVectorField(BaseField):
233241
"Vector field with a FLAT index (brute force nearest neighbors search)"
234242

235-
type: Literal["vector"] = "vector"
243+
type: Literal[FieldTypes.VECTOR] = FieldTypes.VECTOR
236244
attrs: FlatVectorFieldAttributes
237245

238246
def as_redis_field(self) -> RedisField:

0 commit comments

Comments
 (0)