Learn how to build an always-on semantic tool discovery system using VectoriaDB.Documentation Index
Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
In this guide you’ll build a typed document shape for tools, an indexing routine that stays in sync, semantic queries with filters, persistent caches, and tunable HNSW search.
What You’ll Build
- A typed document shape for every tool, app, or resource you want to search
- An indexing routine that stays in sync with your tool registry
- Semantic queries with metadata filters, score thresholds, and pagination controls
- Persistent caches (file or Redis) so restarts do not require re-embedding everything
- Tunable HNSW search for large inventories
Prerequisites
- Node.js 22 or later
- Ability to install npm packages
- Optional: writable disk or Redis for persistence
Install & Initialize VectoriaDB
src/tool-index.ts
initialize() must run before add, search, or update. Calling it twice is safe because VectoriaDB short-circuits if it is already ready.Index Your Tools
Collect metadata from your tool registry and write it into the database. Each document needs a unique
id, the natural-language text you want to vectorize, and metadata that extends DocumentMetadata.src/collect-tools.ts
addMany validates every document, enforces maxBatchSize, and prevents duplicates.Run Semantic Search
Query the index anywhere you can run async code:
src/search-tools.ts
search returns the best matches sorted by cosine similarity. Use filter to enforce authorization, includeVector to inspect raw vectors, and threshold to drop low-confidence hits.Persist Embeddings
Avoid re-indexing on every boot by using storage adapters with a deterministic tools hash:
src/warmup.ts
toolsHash automatically invalidates the cache when your tool list or descriptions change. Call saveToStorage() after indexing; initialize() transparently loads the cache on the next boot.Need a shared cache across pods? Swap in
RedisStorageAdapter with your preferred Redis client and namespace.Scale & Tune
- Enable
useHNSWfor datasets above roughly ten thousand documents. HNSW provides sub-millisecond queries with more than 95% recall. - Adjust
thresholdandtopKper query to trade recall for precision. - Guard resource usage with
maxDocuments,maxDocumentSize, andmaxBatchSize. - Set a custom
cacheDirif your runtime has strict filesystem policies.
src/scaled-config.ts
Complete Example
src/complete-example.ts
Related
Welcome
Getting started
Indexing
Adding documents
Search
Query options
Storage
Storage adapters
HNSW
Scaling to large datasets