Skip to content

Commit 0c619f4

Browse files
author
Sam Partee
authored
Downgrade pydantic to 1.x (#50)
As the title states. This is for compatibility with Langchain.
1 parent e188b79 commit 0c619f4

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

redisvl/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def from_yaml(cls, schema_path: str):
9595
SearchIndex: A SearchIndex object.
9696
"""
9797
schema = read_schema(schema_path)
98-
return cls(fields=schema.index_fields, **schema.index.model_dump())
98+
return cls(fields=schema.index_fields, **schema.index.dict())
9999

100100
@classmethod
101101
def from_dict(cls, schema_dict: Dict[str, Any]):
@@ -108,7 +108,7 @@ def from_dict(cls, schema_dict: Dict[str, Any]):
108108
SearchIndex: A SearchIndex object.
109109
"""
110110
schema = SchemaModel(**schema_dict)
111-
return cls(fields=schema.index_fields, **schema.index.model_dump())
111+
return cls(fields=schema.index_fields, **schema.index.dict())
112112

113113
@classmethod
114114
def from_existing(

redisvl/schema.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from uuid import uuid4
44

55
import yaml
6-
from pydantic import BaseModel, Field, field_validator
6+
from pydantic import BaseModel, Field, validator
77
from redis.commands.search.field import (
88
GeoField,
99
NumericField,
@@ -66,8 +66,7 @@ class BaseVectorField(BaseModel):
6666
distance_metric: str = Field(default="COSINE")
6767
initial_cap: int = Field(default=20000)
6868

69-
@field_validator("algorithm", "datatype", "distance_metric", mode="before")
70-
@classmethod
69+
@validator("algorithm", "datatype", "distance_metric", pre=True, each_item=True)
7170
def uppercase_strings(cls, v):
7271
return v.upper()
7372

@@ -132,8 +131,7 @@ class SchemaModel(BaseModel):
132131
index: IndexModel = Field(...)
133132
fields: FieldsModel = Field(...)
134133

135-
@field_validator("index")
136-
@classmethod
134+
@validator("index")
137135
def validate_index(cls, v):
138136
if v.storage_type not in ["hash", "json"]:
139137
raise ValueError(f"Storage type {v.storage_type} not supported")
@@ -142,7 +140,7 @@ def validate_index(cls, v):
142140
@property
143141
def index_fields(self):
144142
redis_fields = []
145-
for field_name in self.fields.model_fields.keys():
143+
for field_name in self.fields.__fields__.keys():
146144
field_group = getattr(self.fields, field_name)
147145
if field_group is not None:
148146
for field in field_group:
@@ -158,4 +156,4 @@ def read_schema(file_path: str):
158156
with open(fp, "r") as f:
159157
schema = yaml.safe_load(f)
160158

161-
return SchemaModel(**schema)
159+
return SchemaModel(**schema)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ numpy
22
redis>=4.3.4
33
pyyaml
44
coloredlogs
5-
pydantic>=2.0.0
5+
pydantic<2.0.0
66
tenacity==8.2.2
77
tabulate==0.9.0

tests/integration/test_simple_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ async def test_simple(async_client):
102102
print("Score:", doc.vector_distance)
103103
pprint(doc)
104104

105-
await index.delete()
105+
await index.delete()

0 commit comments

Comments
 (0)