Mullion RAG Demo
Role-based access control with fork/merge patterns for sensitive data
The Scenario
A Retrieval-Augmented Generation (RAG) system provides answers based on a document corpus with varying access levels. Documents are classified as Public, Internal, or Confidential. The challenge: ensure users only receive answers based on documents they have clearance to access.
The Problem
Traditional RAG systems risk exposing sensitive information through:
- Accidental retrieval of confidential documents
- Cross-contamination between security contexts
- Lack of provenance tracking for sources
Mullion's Solution
Mullion enforces access control at the type level using:
- Scope-based filtering: Documents tagged with access level scopes
- Fork/merge patterns: Parallel processing with cache optimization
- Provenance tracking: Know exactly which documents influenced the answer
How It Works
Query Classification
Analyze user query to understand intent and scope
Access-Controlled Retrieval
Filter documents based on user's role (Public/Internal/Confidential)
Parallel Processing (Fork)
Process retrieved documents in parallel with cache optimization
Response Generation (Merge)
Combine insights while maintaining scope boundaries and provenance
✅ RAG with Mullion
// ✅ SAFE: Mullion enforces access control
const userRole = 'internal'; // Public, Internal, or Confidential
const ragCtx = scope(`rag-${userRole}`);
// Query classification
const query = await ragCtx.infer(QuerySchema, userInput);
// Retrieve only accessible documents
const docs = await retrieveDocuments(userRole, query.value);
// Fork/merge for parallel processing
const result = await fork({
branches: docs.map(doc => ({
fn: () => ragCtx.infer(AnswerSchema, `...${doc}...`)
})),
strategy: 'cache-optimized',
merge: weightedVote()
});
// Response includes provenance
console.log(result.value); // Answer
console.log(result.provenance); // Source documentsKey Features
Access Control
Role-based document filtering enforced at compile-time
Fork/Merge
Parallel processing with automatic cache optimization
Smart Caching
Provider-aware caching reduces costs and latency
Provenance
Track which documents influenced each answer
Try It Yourself
Query a document corpus with different access levels and see how Mullion enforces role-based boundaries.