import { VectoriaDB, DocumentMetadata } from 'vectoriadb';// Define your metadata shapeinterface ToolDocument extends DocumentMetadata { toolName: string; owner: string; tags: string[]; risk: 'safe' | 'destructive';}// Create the databaseconst toolIndex = new VectoriaDB<ToolDocument>({ cacheDir: './.cache/transformers', defaultSimilarityThreshold: 0.4,});// Initialize (downloads model on first run)await toolIndex.initialize();// Add a documentawait toolIndex.add('users:list', 'List all users with pagination', { id: 'users:list', toolName: 'list', owner: 'users', tags: ['read'], risk: 'safe',});// Searchconst results = await toolIndex.search('find users');console.log(results[0].metadata.toolName); // 'list'
You now have a working semantic search index. initialize() must run before add, search, or update. Calling it twice is safe because VectoriaDB short-circuits if it is already ready.