Replies: 1 comment 2 replies
-
I found two similar closed issues that might help:
Possible Reasons and Solutions:
Example Code to Ensure Correct Schema and Prefixfrom 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",
},
},
],
}
)
vector_store = RedisVectorStore(
schema=custom_schema,
redis_client=redis_client,
overwrite=True,
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context
) Example Code to Query with Metadata Filtersfrom llama_index.core.vector_stores import (
MetadataFilters,
MetadataFilter,
ExactMatchFilter,
)
retriever = index.as_retriever(
similarity_top_k=3,
filters=MetadataFilters(
filters=[
ExactMatchFilter(key="file_name", value="paul_graham_essay.txt"),
MetadataFilter(
key="updated_at",
value=date_to_timestamp("2023-01-01"),
operator=">=",
),
MetadataFilter(
key="text",
value="learn",
operator="text_match",
),
],
condition="and",
),
)
result_nodes = retriever.retrieve("What did the author learn?")
for node in result_nodes:
print(node) Handling Redis Query Errorsredis_query = get_redis_query(
return_fields=return_fields,
top_k=query.similarity_top_k,
vector_field=self._vector_field,
filters=filters,
)
if not query.query_embedding:
raise ValueError("Query embedding is required for querying.")
query_params = {
"vector": array_to_buffer(query.query_embedding),
}
_logger.info(f"Querying index {self._index_name}")
try:
results = self._redis_client.ft(self._index_name).search(
redis_query, query_params=query_params # type: ignore
)
except RedisTimeoutError as e:
_logger.error(f"Query timed out on {self._index_name}: {e}")
raise
except RedisError as e:
_logger.error(f"Error querying {self._index_name}: {e}")
raise
if len(results.docs) == 0:
raise ValueError(
f"No docs found on index '{self._index_name}' with "
f"prefix '{self._prefix}' and filters '{filters}'. "
"* Did you originally create the index with a different prefix? "
"* Did you index your metadata fields when you created the index?"
) Ensure the schema is correctly defined, the prefix is consistent, metadata is indexed correctly, and the query embedding is provided to avoid retrieval issues. Handle potential Redis errors appropriately [3][4]. |
Beta Was this translation helpful? Give feedback.
-
Why redis vector store can't retrieve content even though it is exactly matched by the query? Secondly why it retrieves the same content even though it is retrieving from a different custom index? Isn't redis database separated by the index name?
Beta Was this translation helpful? Give feedback.
All reactions