Skip to main content

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.

Avoid re-indexing on every boot by using storage adapters. VectoriaDB supports file, Redis, and in-memory storage.

Storage Adapters

AdapterUse CasePersistence
MemoryStorageAdapterDevelopment, testingNone (default)
FileStorageAdapterSingle-server deploymentLocal disk
RedisStorageAdapterMulti-pod deploymentShared cache
Persist embeddings to local disk:
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
}

File Adapter Options

OptionTypeDefaultDescription
cacheDirstring./.cache/vectoriadbDirectory for cache files
namespacestring'default'Namespace for isolation

Cache Invalidation

VectoriaDB automatically invalidates the cache when documents change. Use toolsHash and version to control invalidation:
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,
});

How Invalidation Works

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.

Warm-up Pattern

Common pattern for production deployments:
export async function warmToolIndex(documents: ToolDocument[]) {
  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();

  // Only re-index if cache was invalidated
  if (toolIndex.size() === 0) {
    console.log('Cache miss - re-indexing...');
    await toolIndex.addMany(documents);
    await toolIndex.saveToStorage();
  } else {
    console.log('Cache hit - loaded from storage');
  }

  return toolIndex;
}

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',
  }),
});

Error Handling

import { StorageError } from 'vectoriadb';

try {
  await toolIndex.saveToStorage();
} catch (error) {
  if (error instanceof StorageError) {
    console.error('Storage operation failed:', error.message);
    // Fallback to in-memory only
  }
}

Overview

Getting started

HNSW

Scaling with HNSW index

Indexing

Adding documents