← Back to learning path
Chapter · Published

RAG permission filtering and knowledge freshness

Make tenant permissions, document status, and freshness first-class fields in retrieval so unauthorized or stale evidence never reaches the model.

Source: knowledge/p24-b/collection_6e8fbe1e8b1ea569a539e8a5/tutorials/rag-permission-filtering-and-freshness.mdRAG knowledge engineering
Chapter progress 0%Learning path progress 0% · 0/10 chapters completedContinue learning path →

A wrong answer can come from an expired or unauthorized document rather than from the model. Enforce permission and freshness at retrieval time, and keep the source timestamp in the answer context.

Core concepts

Each chunk should carry tenant_id, allowed_roles, document_status, and valid_until. The server builds the authorization filter before keyword or vector retrieval; the model never receives an unauthorized candidate.

def allowed_filter(tenant_id: str, roles: set[str]) -> dict:
    return {
        'tenant_id': tenant_id,
        'document_status': 'published',
        'allowed_roles': {'$overlap': sorted(roles)},
    }

query = allowed_filter('tenant-a', {'support'})
assert query['document_status'] == 'published'

Steps and use cases

  1. Define published, withdrawn, deleted, and expired states.
  2. Obtain tenant and role claims from the session service and construct the filter server-side.
  3. Put source time and version into the context so the model can prefer the newest valid evidence.
  4. Scan for expired documents and create a work queue; never expose unreviewed material automatically.

This is useful for multi-tenant help centers, internal policy libraries, and permission-sensitive technical content.

Official references

OpenAI Retrieval and the OWASP Top 10 for LLM applications.

Last checked: 2026-11-16. Frontend filters are search hints only; authorization belongs to the server.

Related practical cases

KnowledgeCase study: replaying RAG retrieval regression with a fixed question set

Further reading

KnowledgeAI Agents: From Core Concepts to ProductionKnowledgeProduction Prompt Engineering: From Instructions to Measurable ContractsKnowledgeStructured Outputs and Tool Contracts for Safe Agents
Product Hub Demo · V0.3