Home/
Part XIII — Expert Mode: Systems, Agents, and Automation/41. Advanced RAG (Beyond the Basics)/41.2 Metadata filtering and access control
41.2 Metadata filtering and access control
Overview and links for this section of the guide.
On this page
Metadata Filtering
// Filter before or during vector search
const results = await vectorSearch({
query: embeddedQuery,
filter: {
department: { $eq: 'engineering' },
year: { $gte: 2023 },
status: { $in: ['published', 'approved'] }
},
limit: 10
});
Access Control
// Access control at query time
async function searchWithACL(query: string, user: User) {
const allowedDocs = user.permissions.flatMap(p => p.documentIds);
return vectorSearch({
query: embed(query),
filter: {
$or: [
{ visibility: 'public' },
{ id: { $in: allowedDocs } },
{ department: { $in: user.departments } }
]
}
});
}