Skip to main content
Learn how to configure VectoriaDB for production environments.

Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                     Your Application                         │
├─────────────────────────────────────────────────────────────┤
│                       VectoriaDB                             │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────┐  │
│  │  Embedding  │  │    Index    │  │      Storage        │  │
│  │   Model     │  │ (HNSW/BF)   │  │  (File/Redis/Mem)   │  │
│  └─────────────┘  └─────────────┘  └─────────────────────┘  │
└─────────────────────────────────────────────────────────────┘
         │                                      │
         ▼                                      ▼
   .cache/transformers                    .cache/vectoriadb
   (model weights)                        (embeddings)

Production Configuration

src/config/vectoriadb.ts
import { VectoriaDB, FileStorageAdapter, SerializationUtils } from 'vectoriadb';

export function createProductionDB<T extends DocumentMetadata>(
  documents: Array<{ id: string; text: string; metadata: T }>
) {
  return new VectoriaDB<T>({
    // Model configuration
    modelName: process.env.VECTORIA_MODEL || 'Xenova/all-MiniLM-L6-v2',
    cacheDir: process.env.VECTORIA_MODEL_CACHE || './.cache/transformers',

    // Storage configuration
    storageAdapter: new FileStorageAdapter({
      cacheDir: process.env.VECTORIA_CACHE_DIR || './.cache/vectoriadb',
      namespace: process.env.VECTORIA_NAMESPACE || 'production',
    }),

    // Cache invalidation
    toolsHash: SerializationUtils.createToolsHash(documents),
    version: process.env.npm_package_version,

    // Resource limits
    maxDocuments: parseInt(process.env.VECTORIA_MAX_DOCS || '100000'),
    maxDocumentSize: parseInt(process.env.VECTORIA_MAX_DOC_SIZE || '100000'),
    maxBatchSize: parseInt(process.env.VECTORIA_MAX_BATCH || '500'),

    // Search defaults
    defaultSimilarityThreshold: parseFloat(process.env.VECTORIA_THRESHOLD || '0.4'),
    defaultTopK: parseInt(process.env.VECTORIA_TOP_K || '10'),

    // HNSW configuration
    useHNSW: process.env.VECTORIA_USE_HNSW === 'true',
    hnsw: {
      M: parseInt(process.env.VECTORIA_HNSW_M || '16'),
      efConstruction: parseInt(process.env.VECTORIA_HNSW_EF_CONSTRUCTION || '200'),
      efSearch: parseInt(process.env.VECTORIA_HNSW_EF_SEARCH || '50'),
    },

    // Error handling
    verboseErrors: process.env.NODE_ENV !== 'production',
  });
}

Pre-deployment Checklist

1

Configure Storage

Choose a storage adapter based on your deployment:
  • Single server: FileStorageAdapter
  • Multi-pod/Kubernetes: RedisStorageAdapter
  • Serverless: Pre-warm with bundled embeddings
2

Set Resource Limits

Configure limits to prevent resource exhaustion:
const db = new VectoriaDB({
  maxDocuments: 100000,
  maxDocumentSize: 100000,
  maxBatchSize: 500,
});
3

Enable HNSW for Scale

For datasets > 10,000 documents:
const db = new VectoriaDB({
  useHNSW: true,
  hnsw: { M: 16, efConstruction: 200, efSearch: 50 },
});
4

Set Up Health Checks

Implement health endpoints for monitoring.

Startup Initialization

src/startup.ts
import { toolIndex } from './vectoriadb';
import { collectDocuments } from './documents';

export async function startupInitialization() {
  console.log('Starting VectoriaDB initialization...');
  const startTime = Date.now();

  try {
    // Initialize the database
    await toolIndex.initialize();
    console.log(`Model loaded in ${Date.now() - startTime}ms`);

    // Load from storage or index documents
    if (toolIndex.size() === 0) {
      console.log('Cache miss - indexing documents...');
      const documents = await collectDocuments();
      await toolIndex.addMany(documents);
      await toolIndex.saveToStorage();
      console.log(`Indexed ${documents.length} documents`);
    } else {
      console.log(`Loaded ${toolIndex.size()} documents from cache`);
    }

    // Warmup query
    await toolIndex.search('warmup query', { topK: 1 });

    console.log(`VectoriaDB ready in ${Date.now() - startTime}ms`);
  } catch (error) {
    console.error('VectoriaDB initialization failed:', error);
    throw error;
  }
}

Docker

Container deployment

Environment Variables

Configuration reference

Health Monitoring

Monitoring setup