redis / redis-vl-python

Redis Vector Library (RedisVL) interfaces with Redis' vector database for realtime semantic search, RAG, and recommendation systems.
https://www.redisvl.com/
MIT License
176 stars 25 forks source link

Adding a filter_expression to an existing VectorQuery is not always working #165

Closed pierrelambert closed 17 hours ago

pierrelambert commented 1 week ago

Executing:

from redisvl.query.filter import Text, Tag, Num, FilterExpression from redisvl.query import VectorQuery

unionTag = Tag("id_texte") == {"VA2", "VA4", "VA1"}

query1 = VectorQuery( vector = vector1f, vector_field_name = "texte_vec", return_fields = ["titre", "questions", "keyword", "texte", "id_texte"], num_results = 5 ) queryf = VectorQuery( vector = vector1f, vector_field_name = "texte_vec", return_fields = ["titre", "questions", "keyword", "texte", "id_texte"], num_results = 5, filter_expression=unionTag )

print(query1) print(unionTag) print(queryf) filter_query_2 = query1.set_filter(unionTag) print(filter_query_2) =====================Results======= *=>[KNN 5 @texte_vec $vector AS vector_distance] RETURN 6 titre questions keyword texte id_texte vector_distance SORTBY vector_distance ASC DIALECT 2 LIMIT 0 5 @id_texte:{A2|A4|A1} @id_texte:{A2|A4|A1}=>[KNN 5 @texte_vec $vector AS vector_distance] RETURN 6 titre questions keyword texte id_texte vector_distance SORTBY vector_distance ASC DIALECT 2 LIMIT 0 5 None

I would expect to be able to update a VectorQuery with a filter_expression

tylerhutcherson commented 1 week ago

Will look into this and get it addressed asap.

tylerhutcherson commented 1 week ago

@pierrelambert issue here is that set_filter() operates in place and returns None. It doesn't produce a copy of the query object itself. So if you remove the = in your set_filter operation query1 should now have the right filter.