Skip to content

Commit 86b145c

Browse files
use an enum for field type literals
1 parent 4e88981 commit 86b145c

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"
@@ -165,7 +173,7 @@ def as_redis_field(self) -> RedisField:
165173
class TextField(BaseField):
166174
"""Text field supporting a full text search index"""
167175

168-
type: Literal["text"] = "text"
176+
type: Literal[FieldTypes.TEXT] = FieldTypes.TEXT
169177
attrs: TextFieldAttributes = Field(default_factory=TextFieldAttributes)
170178

171179
def as_redis_field(self) -> RedisField:
@@ -183,7 +191,7 @@ def as_redis_field(self) -> RedisField:
183191
class TagField(BaseField):
184192
"""Tag field for simple boolean-style filtering"""
185193

186-
type: Literal["tag"] = "tag"
194+
type: Literal[FieldTypes.TAG] = FieldTypes.TAG
187195
attrs: TagFieldAttributes = Field(default_factory=TagFieldAttributes)
188196

189197
def as_redis_field(self) -> RedisField:
@@ -200,7 +208,7 @@ def as_redis_field(self) -> RedisField:
200208
class NumericField(BaseField):
201209
"""Numeric field for numeric range filtering"""
202210

203-
type: Literal["numeric"] = "numeric"
211+
type: Literal[FieldTypes.NUMERIC] = FieldTypes.NUMERIC
204212
attrs: NumericFieldAttributes = Field(default_factory=NumericFieldAttributes)
205213

206214
def as_redis_field(self) -> RedisField:
@@ -215,7 +223,7 @@ def as_redis_field(self) -> RedisField:
215223
class GeoField(BaseField):
216224
"""Geo field with a geo-spatial index for location based search"""
217225

218-
type: Literal["geo"] = "geo"
226+
type: Literal[FieldTypes.GEO] = FieldTypes.GEO
219227
attrs: GeoFieldAttributes = Field(default_factory=GeoFieldAttributes)
220228

221229
def as_redis_field(self) -> RedisField:
@@ -230,7 +238,7 @@ def as_redis_field(self) -> RedisField:
230238
class FlatVectorField(BaseField):
231239
"Vector field with a FLAT index (brute force nearest neighbors search)"
232240

233-
type: Literal["vector"] = "vector"
241+
type: Literal[FieldTypes.VECTOR] = FieldTypes.VECTOR
234242
attrs: FlatVectorFieldAttributes
235243

236244
def as_redis_field(self) -> RedisField:

0 commit comments

Comments
 (0)