Skip to main content
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

AdapterUse CasePersistence
MemoryStorageAdapterDevelopment, testingNone (default)
FileStorageAdapterSingle-server deploymentLocal disk
RedisStorageAdapterMulti-pod deploymentShared 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

  1. Initialize: VectoriaDB checks for cached data
  2. Validate: Cache is validated against toolsHash, version, and modelName
  3. Load or Index: Valid cache is loaded; otherwise re-indexing occurs
  4. 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:
  1. Does the cache file/key exist?
  2. Does toolsHash match?
  3. Does version match?
  4. Does modelName match?
If any check fails, the cache is invalidated and re-indexing occurs.

Manual Storage Operations

src/manual-storage.ts
// 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:
src/multi-tenant.ts
// 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