-
How to correctly retrieve data when there are multiple prefix in a redis index? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
To correctly retrieve data when there are multiple prefixes in a Redis index, ensure that the chosen FT.INFO <name of your index> Look under Here is an example of how to define and use a custom index schema with a specific prefix: from redisvl.schema import IndexSchema
custom_schema = IndexSchema.from_dict(
{
"index": {
"name": "paul_graham",
"prefix": "essay",
"key_separator": ":",
},
"fields": [
{"type": "tag", "name": "id"},
{"type": "tag", "name": "doc_id"},
{"type": "text", "name": "text"},
{"type": "numeric", "name": "updated_at"},
{"type": "tag", "name": "file_name"},
{
"type": "vector",
"name": "vector",
"attrs": {
"dims": 1024,
"algorithm": "hnsw",
"distance_metric": "cosine",
},
},
],
}
)
# Create the RedisVectorStore with the custom schema
vector_store = RedisVectorStore(
schema=custom_schema,
redis_client=redis_client,
overwrite=True,
)
# Load storage context
storage_context = StorageContext.from_defaults(vector_store=vector_store)
# Build and load index from documents and storage context
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context
) Additionally, if you are using a Redis replication setup with multiple Redis servers and Redis sentinels, you can set the redis_client = get_client(
redis_url="redis+sentinel://username:password@sentinelhost:26379/mymaster/0"
) By ensuring the prefix is consistent and correctly set in your schema, and by properly configuring your Redis client for replication setups, you can retrieve data accurately from the Redis index [1][2]. |
Beta Was this translation helpful? Give feedback.
To correctly retrieve data when there are multiple prefixes in a Redis index built from a vector store, ensure that the chosen
prefix
in the index schema is consistent across your code. You can verify the prefix used by running the following command in the Redis CLI:Look under
index_definition
=>prefixes
to see the prefix your index was created with. Make sure that all records have the correct key prefix that matches the index schema.Here is an example of defining a custom index schema with a specific prefix: