11import bz2
22import csv
33import os
4- import time
4+ import asyncio
55from io import TextIOWrapper
66
77import numpy as np
88import pytest
99import pytest_asyncio
1010import redis .asyncio as redis
11- import redis .commands .search
1211import redis .commands .search .aggregation as aggregations
1312import redis .commands .search .reducers as reducers
1413from redis .commands .search import AsyncSearch
@@ -49,8 +48,8 @@ async def decoded_r(create_redis, stack_url):
4948async def waitForIndex (env , idx , timeout = None ):
5049 delay = 0.1
5150 while True :
52- res = await env .execute_command ("FT.INFO" , idx )
5351 try :
52+ res = await env .execute_command ("FT.INFO" , idx )
5453 if int (res [res .index ("indexing" ) + 1 ]) == 0 :
5554 break
5655 except ValueError :
@@ -62,7 +61,7 @@ async def waitForIndex(env, idx, timeout=None):
6261 except ValueError :
6362 break
6463
65- time .sleep (delay )
64+ await asyncio .sleep (delay )
6665 if timeout is not None :
6766 timeout -= delay
6867 if timeout <= 0 :
@@ -1765,7 +1764,7 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17651764 mixed_data = {"first_name" : "🐍python" , "vector_emb" : fake_vec .tobytes ()}
17661765 await decoded_r .hset (f"{ index_name } :1" , mapping = mixed_data )
17671766
1768- schema = (
1767+ schema = [
17691768 TagField ("first_name" ),
17701769 VectorField (
17711770 "embeddings_bio" ,
@@ -1776,14 +1775,15 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17761775 "DISTANCE_METRIC" : "COSINE" ,
17771776 },
17781777 ),
1779- )
1778+ ]
17801779
17811780 await decoded_r .ft (index_name ).create_index (
17821781 fields = schema ,
17831782 definition = IndexDefinition (
17841783 prefix = [f"{ index_name } :" ], index_type = IndexType .HASH
17851784 ),
17861785 )
1786+ await waitForIndex (decoded_r , index_name )
17871787
17881788 query = (
17891789 Query ("*" )
@@ -1793,6 +1793,12 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
17931793 result = await decoded_r .ft (index_name ).search (query = query , query_params = {})
17941794 docs = result .docs
17951795
1796+ if len (docs ) == 0 :
1797+ hash_content = await decoded_r .hget (f"{ index_name } :1" , "first_name" )
1798+ assert len (docs ) > 0 , (
1799+ f"Returned search results are empty. Result: { result } ; Hash: { hash_content } "
1800+ )
1801+
17961802 decoded_vec_from_search_results = np .frombuffer (
17971803 docs [0 ]["vector_emb" ], dtype = np .float32
17981804 )
0 commit comments