For example
documents = [
Document(text=..., metadata={"user_id": "123"})
Document(text=..., metadata={"user_id": "321"})
]
index = VectorStoreIndex.from_documents(documents, ...)
from llama_index.core.vector_stores import (
MetadataFilter,
MetadataFilters,
FilterOperator,
)
filters = MetadataFilters(
filters=[
MetadataFilter(key="user_id", operator=FilterOperator.EQ, value="123"),
]
)
# filtered query engine
query_engine = index.as_query_engine(..., filters=filters)
# filtered retriever
retriever = index.as_retriever(..., filters=filters)
etc.