SHEN YIFull-Stack & AI

Paris • Singapore • Shanghai

RAG Formation · Lesson · Retrieval engineering

Metadata, filters, and access boundaries

Separate useful document labels from the real authorization boundary an enterprise chatbot needs.

$ lesson --status
▸ course RAG Formation
▸ lesson 07 / 16
▸ phase Retrieval engineering
▸ status Complete
● build → measure → learn

Standalone lesson

Learn the full lesson and test your understanding here.

The 16-lesson RAG Formation curriculum is complete. This page contains the complete lesson content, local reference material, and instant browser exercises.

Today’s tangible win

By the end you’ll have a current-vs-proposed access matrix on paper — one that doesn’t pretend the demo already knows how to authorize roles, because it doesn’t.

Watch the walkthrough

1 · What exists today

Right now, ingestion tags every document with a reference, company, department, and document type. Handy for filtering — but none of that is a user permission.

Primary reading: Qdrant — Filtering

cd demo
python3 metadata_lab.py --output-dir reports/lesson-07-inventory

When it’s done, open lesson-07-metadata-inventory.md. The whole thing runs offline — it just reads the synthetic corpus definition, never calls an API, and never touches an index.

2 · Build the access matrix

RoleAllowed department / typeStatusEvidence or gap
EmployeeOwn department proceduresProposedDepartment metadata is already there, but nothing filters by the user’s own department yet.
SupplierApproved supplier-facing documentsProposedThe demo inventory has no supplier role, and no field marking a document as supplier-facing.
QAQuality procedures and recordsMetadata availableDepartment and type can describe the scope, but real authorization still has to be enforced server-side.
AuditorRead-only approved scopeProposedCurrent metadata doesn’t represent a read-only role or an audit scope at all.

3 · Negative-access practice

Case A: The prompt says “only answer HR questions.” Retrieval doesn’t care — it still pulls from every document. What’s missing?

Case B: A document carries department metadata, but the user has no department attribute at all. What status is honest here?

Case C: A supplier has no business seeing a QA procedure. What does the negative test actually need to prove?

Mission connection

An answer can be word-for-word correct and still be a problem — if it came from a document the user had no business seeing. For a company chatbot, “reliable” isn’t just about getting the facts right; it includes never crossing that line.

4 · Deliverable

  1. Save the metadata inventory report.
  2. Fill in the four-role matrix, one status per row.
  3. Write one negative-retrieval test you’d add before shipping this.

Next: Lesson 8 — Query handling and reranking.

Ask me anything about a metadata field, role, filter, or negative test — I’m your teacher for this course.