Performance: Metadata filtering in vector stores
This affects query response time and resource usage during vector search by limiting the search space using metadata filters.
results = vector_store.similarity_search(query_vector, filter={"category": "books"})
results = vector_store.similarity_search(query_vector) filtered_results = [r for r in results if r.metadata['category'] == 'books']
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Post-filtering after full search | N/A | N/A | N/A | [X] Bad |
| Pre-filtering with metadata in query | N/A | N/A | N/A | [OK] Good |
results = vector_store.search('climate change', filter={'source': 'news', 'year': 2023})
print(len(results))
If the vector store has 10 documents with source 'news' and year 2023, and 5 with source 'news' but year 2022, what will be printed?results = vector_store.search('AI', filter=['category', 'tech'])
What is the main problem causing the error?Pass the test and this pattern moves unknown