Dynamically combine multiple filters

I would like to dynamically combine multiple filters in the same query.

For example, I have a list of md5s that I would like to include in a filter,

md5_list = ['md5_value_1', 'md5_value_2', 'md5_value_3', ...]

I would like to prepare an OR filter using all these md5 values and then run my query. Essesstially something like this.

## The code below is just to show what I am trying to achieve.

# List of md5 values
md5_list = ['md5_value_1', 'md5_value_2', 'md5_value_3', ...]

# Create a list of filters for each md5 value
filters = [wvc.query.Filter.by_property("md5").equal(md5) for md5 in md5_list]

# Combine the filters using the bitwise OR operator
combined_filter = "Or".join(filters)

# Use the combined filter in the query
vecDB_response = documentCollection.query.near_vector(
    near_vector=questionsVectorQuery,
    filters=combined_filter,
    limit=10,
    return_metadata=MetadataQuery(distance=True)
)

Any ideas how to achieve this? Any help would be appreicated.

Thanks
A

        md5_list = ['md5_value_1', 'md5_value_2', 'md5_value_3']

        vecDB_response = documentCollection.query.near_vector(
            near_vector=questionsVectorQuery,
            filters=wvc.query.Filter.by_property("md5").contains_any(md5_list),
            limit=10,
            return_metadata=MetadataQuery(distance=True)
        )

Yet again. Asked a bit too soon.

1 Like

hi @Amit !!

Thanks for sharing :slight_smile: