Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 5 · 4. Embeddings & Vector Stores
Lesson 35 of 68

Metadata Filtering

Narrowing the search space. Mixing structured and unstructured data.

Derpx0610 Jan · 1 min read
LangChain Mastery
Embeddings: What Matters in PracticeEmbedding Models in LangChainVector Stores: FAISS, ChromaPersisting & Reloading IndexesMetadata FilteringDense vs Sparse (BM25 Overview)Hybrid Search Concepts
Contents
1. The False Positive Problem2. Pre-Filtering vs Post-FilteringPre-Filtering (Better)Post-Filtering (Common but risky)3. Implementation4. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
Embeddings: What Matters in PracticeEmbedding Models in LangChainVector Stores: FAISS, ChromaPersisting & Reloading IndexesMetadata FilteringDense vs Sparse (BM25 Overview)Hybrid Search Concepts
Contents
1. The False Positive Problem2. Pre-Filtering vs Post-FilteringPre-Filtering (Better)Post-Filtering (Common but risky)3. Implementation4. Summary

1. The False Positive Problem

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.

2. Pre-Filtering vs Post-Filtering

Pre-Filtering (Better)

Logic: "Find all docs where year=2023, THEN find the most similar ones."

  • Pros: Efficient. Guarantees the constraint is met.
  • Cons: Harder for database to optimize (HNSW index).

Post-Filtering (Common but risky)

Logic: "Find top 100 similar docs. THEN remove ones where year!=2023."

  • Risk: What if all top 100 are from 2022? You filter them all out and return 0 results.

3. Implementation

Most vector stores now support Pre-filtering native.

filter_search.py
results = vectorstore.similarity_search(
  "profit growth",
  k=5,
  filter={"year": 2023, "department": "finance"}
)

4. Summary

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."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonPersisting & Reloading IndexesNext lesson →Dense vs Sparse (BM25 Overview)