Spaces:
Sleeping
Sleeping
File size: 564 Bytes
2b371d5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from llama_index.core.vector_stores import (
MetadataFilters,
MetadataFilter,
FilterOperator,
FilterCondition,
)
def build_filters_from_query(query: str):
terms = [t.lower() for t in query.split() if len(t) > 2]
if not terms:
return None
return MetadataFilters(
filters=[
MetadataFilter(
key="excerpt_keywords",
operator=FilterOperator.TEXT_MATCH,
value=term,
)
for term in terms
],
condition=FilterCondition.OR
) |