Pattern · Retrieval and RAG
Metadata and permission filters
Store who may see each chunk and what it is about, and filter inside the search before ranking.
Say it in the interview
Access control has to live in retrieval, not the prompt: every chunk carries its allowed groups and effective dates, and the search filters on the verified user before ranking. Missing permissions mean visible to nobody.
When to use it
- Enterprise data with access rights
- Documents that differ by region, product, date or version
- Old versions must not be cited
How it works
- Source document + its permissions → Chunk + metadata (groups, region, effective date, version)
- User signs in → Verified groups
- Verified groups → Search with filters
- Chunk + metadata (groups, region, effective date, version) → Search with filters
- Search with filters → Only permitted, current chunks
Trade-offs
- Prevents leaks and stale answers at the source
- Permissions must be re-synced as they change
- Filters can hide the right answer if metadata is wrong
Pitfalls interviewers probe
- Filtering after ranking, so the top k is mostly empty
- Enforcing access rules in the prompt instead of code
- Missing permissions defaulting to visible