Skip to content

Commit

Permalink
redis[patch]: fix config init (#15)
Browse files Browse the repository at this point in the history
* redis[patch]: fix config init

* fmt

* fmt
  • Loading branch information
baskaryan authored Sep 14, 2024
1 parent ca6d071 commit d41290f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions libs/redis/langchain_redis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ class RedisConfig(BaseModel):
arbitrary_types_allowed=True,
)

def __init__(self, **data: Any):
super().__init__(**data)
if "schema" in data:
schema = data["schema"]
self.index_name = schema.index.name
self.key_prefix = schema.index.prefix
self.storage_type = schema.index.storage_type.value
self.index_schema = schema

@model_validator(mode="before")
@classmethod
def check_schema_options(cls, values: Dict) -> Dict:
Expand All @@ -115,13 +106,19 @@ def check_schema_options(cls, values: Dict) -> Dict:
"Only one of 'index_schema', 'schema_path', "
"or 'metadata_schema' can be specified."
)
if "schema" in values:
schema = values.pop("schema")
values["index_name"] = schema.index.name
values["key_prefix"] = schema.index.prefix
values["storage_type"] = schema.index.storage_type.value
values["index_schema"] = schema

return values

@model_validator(mode="after")
def set_key_prefix(self) -> Self:
if self.key_prefix is None:
self.key_prefix = self.index_schema
self.key_prefix = self.index_name
return self

@classmethod
Expand Down

0 comments on commit d41290f

Please sign in to comment.