Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions redisvl/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def from_yaml(cls, schema_path: str):
SearchIndex: A SearchIndex object.
"""
schema = read_schema(schema_path)
return cls(fields=schema.index_fields, **schema.index.model_dump())
return cls(fields=schema.index_fields, **schema.index.dict())

@classmethod
def from_dict(cls, schema_dict: Dict[str, Any]):
Expand All @@ -108,7 +108,7 @@ def from_dict(cls, schema_dict: Dict[str, Any]):
SearchIndex: A SearchIndex object.
"""
schema = SchemaModel(**schema_dict)
return cls(fields=schema.index_fields, **schema.index.model_dump())
return cls(fields=schema.index_fields, **schema.index.dict())

@classmethod
def from_existing(
Expand Down
12 changes: 5 additions & 7 deletions redisvl/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uuid import uuid4

import yaml
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, Field, validator
from redis.commands.search.field import (
GeoField,
NumericField,
Expand Down Expand Up @@ -66,8 +66,7 @@ class BaseVectorField(BaseModel):
distance_metric: str = Field(default="COSINE")
initial_cap: int = Field(default=20000)

@field_validator("algorithm", "datatype", "distance_metric", mode="before")
@classmethod
@validator("algorithm", "datatype", "distance_metric", pre=True, each_item=True)
def uppercase_strings(cls, v):
return v.upper()

Expand Down Expand Up @@ -132,8 +131,7 @@ class SchemaModel(BaseModel):
index: IndexModel = Field(...)
fields: FieldsModel = Field(...)

@field_validator("index")
@classmethod
@validator("index")
def validate_index(cls, v):
if v.storage_type not in ["hash", "json"]:
raise ValueError(f"Storage type {v.storage_type} not supported")
Expand All @@ -142,7 +140,7 @@ def validate_index(cls, v):
@property
def index_fields(self):
redis_fields = []
for field_name in self.fields.model_fields.keys():
for field_name in self.fields.__fields__.keys():
field_group = getattr(self.fields, field_name)
if field_group is not None:
for field in field_group:
Expand All @@ -158,4 +156,4 @@ def read_schema(file_path: str):
with open(fp, "r") as f:
schema = yaml.safe_load(f)

return SchemaModel(**schema)
return SchemaModel(**schema)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ numpy
redis>=4.3.4
pyyaml
coloredlogs
pydantic>=2.0.0
pydantic<2.0.0
tenacity==8.2.2
tabulate==0.9.0
2 changes: 1 addition & 1 deletion tests/integration/test_simple_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ async def test_simple(async_client):
print("Score:", doc.vector_distance)
pprint(doc)

await index.delete()
await index.delete()