Skip to content

AsyncSearchIndex vector query failure #359

Closed
@sraza1983

Description

@sraza1983

The example mentioned in the documentation here fails with errors. See below.


TypeError Traceback (most recent call last)
File ~/Library/Python/3.9/lib/python/site-packages/redisvl/index/index.py:1730, in AsyncSearchIndex.search(self, *args, **kwargs)
1729 try:
-> 1730 client = await self._get_client()
1731 if isinstance(client, AsyncRedisCluster):
1732 # Use special cluster search for AsyncRedisCluster

File ~/Library/Python/3.9/lib/python/site-packages/redisvl/index/index.py:1265, in AsyncSearchIndex._get_client(self)
1264 if not self._validated_client:
-> 1265 await RedisConnectionFactory.validate_async_redis(
1266 self._redis_client,
1267 self._lib_name,
1268 )
1269 self._validated_client = True

File ~/Library/Python/3.9/lib/python/site-packages/redisvl/redis/connection.py:421, in RedisConnectionFactory.validate_async_redis(redis_client, lib_name, required_modules)
420 if not issubclass(type(redis_client), (AsyncRedis, AsyncRedisCluster)):
--> 421 raise TypeError(
422 "Invalid async Redis client instance. Must be async Redis or async RedisCluster."
423 )
424 # Set client library name

TypeError: Invalid async Redis client instance. Must be async Redis or async RedisCluster.
...
1745 raise RedisSearchError(f"Error while searching: {str(e)}") from e
1746 except Exception as e:
-> 1747 raise RedisSearchError(f"Unexpected error while searching: {str(e)}") from e

RedisSearchError: Unexpected error while searching: Invalid async Redis client instance. Must be async Redis or async RedisCluster.
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

Name: redisvl
Version: 0.8.0
Summary: Python client library and CLI for using Redis as a vector database
Home-page:
Author:
Author-email: "Redis Inc." [email protected]
License:
Location: /Users/salmanraza/Library/Python/3.9/lib/python/site-packages
Requires: redis, pyyaml, jsonpath-ng, python-ulid, numpy, pydantic, ml-dtypes, tenacity
Required-by:
Note: you may need to restart the kernel to use updated packages.
Name: sentence-transformers
Version: 4.1.0
Summary: Embeddings, Retrieval, and Reranking
Home-page:
Author:
Author-email: Nils Reimers [email protected], Tom Aarsen [email protected]
License: Apache 2.0
Location: /Users/salmanraza/Library/Python/3.9/lib/python/site-packages
Requires: typing_extensions, torch, tqdm, transformers, scikit-learn, scipy, huggingface-hub, Pillow
Required-by:
Note: you may need to restart the kernel to use updated packages.
Name: pandas
Version: 2.2.2
Summary: Powerful data structures for data analysis, time series, and statistics

`from redisvl.index import AsyncSearchIndex

from redis.asyncio import Redis

from redisvl.query import VectorQuery

Create Redis client

redis_client = Redis(

host=REDIS_HOST,

port=REDIS_PORT,

password=REDIS_PASSWORD,

decode_responses=True,

ssl_cert_reqs="none",

ssl=True)

index = AsyncSearchIndex.from_dict(schema, redis_client=client)

query = VectorQuery(
vector=[0.1, 0.1, 0.5],
vector_field_name="vector", # use the correct field name from your schema
return_fields=["caption", "subtitle", "views", "vector_distance"], # use fields that exist in your schema/data
num_results=3
)

execute the vector query async

results = await index.query(query)

print(results)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions