Learn how to persist embeddings between restarts using storage adapters.
By default, VectoriaDB stores embeddings in memory. Use a storage adapter to persist them between server restarts.
Storage Adapters
Adapter Use Case Persistence MemoryStorageAdapterDevelopment, testing None (default) FileStorageAdapterSingle-server deployment Local disk RedisStorageAdapterMulti-pod deployment Shared cache
Quick Start
src/storage-quickstart.ts
import { VectoriaDB , FileStorageAdapter , SerializationUtils } from ' vectoriadb ' ;
const documents = collectToolDocuments ();
const toolIndex = new VectoriaDB < ToolDocument >({
storageAdapter : new FileStorageAdapter ({
cacheDir : ' ./.cache/vectoriadb ' ,
namespace : ' tool-index ' ,
}),
toolsHash : SerializationUtils . createToolsHash ( documents ),
version : process . env . npm_package_version ,
});
await toolIndex . initialize ();
if ( toolIndex . size () === 0 ) {
await toolIndex . addMany ( documents );
await toolIndex . saveToStorage (); // Persist to disk
}
How Persistence Works
Initialize : VectoriaDB checks for cached data
Validate : Cache is validated against toolsHash, version, and modelName
Load or Index : Valid cache is loaded; otherwise re-indexing occurs
Save : Call saveToStorage() to persist changes
Cache Invalidation
VectoriaDB automatically invalidates the cache when documents change:
src/cache-invalidation.ts
const toolIndex = new VectoriaDB < ToolDocument >({
storageAdapter : new FileStorageAdapter ({ cacheDir : ' ./.cache ' }),
// Hash of document contents - invalidates when documents change
toolsHash : SerializationUtils . createToolsHash ( documents ),
// Application version - invalidates on deployments
version : process . env . npm_package_version ,
});
Validation Checks
On initialize(), VectoriaDB checks:
Does the cache file/key exist?
Does toolsHash match?
Does version match?
Does modelName match?
If any check fails, the cache is invalidated and re-indexing occurs.
Manual Storage Operations
// Save current state to storage
await toolIndex . saveToStorage ();
// Load from storage (done automatically on initialize)
await toolIndex . loadFromStorage ();
// Clear storage
await toolIndex . clearStorage ();
Multi-Tenant Isolation
Use namespaces to isolate different indexes:
// Tenant A
const tenantAIndex = new VectoriaDB ({
storageAdapter : new RedisStorageAdapter ({
client : redisClient ,
namespace : ' tenant-a ' ,
}),
});
// Tenant B
const tenantBIndex = new VectoriaDB ({
storageAdapter : new RedisStorageAdapter ({
client : redisClient ,
namespace : ' tenant-b ' ,
}),
});
Choosing an Adapter
File Adapter Single-server deployments
Redis Adapter Multi-pod environments
Memory Adapter Development and testing
Cache Invalidation Advanced cache control
Deployment Production configuration