Skip to main content

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

  1. Source document + its permissions → Chunk + metadata (groups, region, effective date, version)
  2. User signs in → Verified groups
  3. Verified groups → Search with filters
  4. Chunk + metadata (groups, region, effective date, version) → Search with filters
  5. 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

Practise it on these questions

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.