Narrowing the search space. Mixing structured and unstructured data.
You ask: "What did the 2023 financial report say about profit?" The vector store finds a chunk: "Profit increased by 10% (2020 report)." Semantically, it is very close. Factually, it is wrong.
Vectors define "Aboutness." Metadata defines "Exactness." You cannot rely on vectors to filter by year, user ID, or category.
Logic: "Find all docs where year=2023, THEN find the most similar ones."
Logic: "Find top 100 similar docs. THEN remove ones where year!=2023."
Most vector stores now support Pre-filtering native.
results = vectorstore.similarity_search(
"profit growth",
k=5,
filter={"year": 2023, "department": "finance"}
)
Always attach metadata during ingestion. Effective RAG is 50% Vector Search + 50% SQL-style filtering.
Key Intuition: "Filters are hard constraints. Vectors are soft suggestions."