const results = await toolIndex.search('sensitive operation', { filter: (metadata) => { // Must be owned by specific teams const allowedOwners = ['billing', 'users', 'orders']; if (!allowedOwners.includes(metadata.owner)) return false; // Must not be deprecated if (metadata.deprecated) return false; // Must not be destructive OR user has elevated permissions if (metadata.risk === 'destructive' && !userHasPermission) return false; return true; },});
For filtering without semantic search, use filter():
src/non-semantic-filter.ts
// Get all tools by owner (no semantic ranking)const billingTools = toolIndex.filter( (metadata) => metadata.owner === 'billing');// Get all deprecated toolsconst deprecated = toolIndex.filter( (metadata) => metadata.deprecated === true);// Get all high-risk toolsconst destructive = toolIndex.filter( (metadata) => metadata.risk === 'destructive');
filter() returns documents without semantic ranking - they’re returned in insertion order. Use search() with a filter when you need semantic relevance.