Convert the RedisConfig to an IndexSchema.
This method creates an IndexSchema object based on the current configuration.
It's useful for generating a schema that can be used to create or update
a Redis index.
to_index_schema(
self,
) -> IndexSchemaExample:
from langchain_redis import RedisConfig
config = RedisConfig(
index_name="my_index",
embedding_dimensions=1536,
distance_metric="COSINE",
metadata_schema=[
{"name": "author", "type": "text"},
{"name": "year", "type": "numeric"}
]
)
schema = config.to_index_schema()
print(schema.index.name)
# Output: my_index
print(len(schema.fields))
# Output: 4 (id, content, embedding, author, year)
Note:
index_schema is already set, it will be returned directly.schema_path is set, the schema will be loaded from the YAML file.IndexSchema is created based on the current
configuration.metadata_schema.IndexSchema.