> ## 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.

# Production Configuration

> Configure VectoriaDB for production deployments

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

```ts title="src/config/vectoriadb.ts" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
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

<Steps>
  <Step title="Configure Storage">
    Choose a storage adapter based on your deployment:

    * **Single server**: `FileStorageAdapter`
    * **Multi-pod/Kubernetes**: `RedisStorageAdapter`
    * **Serverless**: Pre-warm with bundled embeddings
  </Step>

  <Step title="Set Resource Limits">
    Configure limits to prevent resource exhaustion:

    ```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    const db = new VectoriaDB({
      maxDocuments: 100000,
      maxDocumentSize: 100000,
      maxBatchSize: 500,
    });
    ```
  </Step>

  <Step title="Enable HNSW for Scale">
    For datasets > 10,000 documents:

    ```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
    const db = new VectoriaDB({
      useHNSW: true,
      hnsw: { M: 16, efConstruction: 200, efSearch: 50 },
    });
    ```
  </Step>

  <Step title="Set Up Health Checks">
    Implement health endpoints for monitoring.
  </Step>
</Steps>

## Startup Initialization

```ts title="src/startup.ts" theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
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;
  }
}
```

## Related

<CardGroup cols={3}>
  <Card title="Docker" icon="docker" href="/vectoriadb/deployment/docker">
    Container deployment
  </Card>

  <Card title="Environment Variables" icon="list" href="/vectoriadb/deployment/environment-variables">
    Configuration reference
  </Card>

  <Card title="Health Monitoring" icon="heart-pulse" href="/vectoriadb/deployment/health-monitoring">
    Monitoring setup
  </Card>
</CardGroup>
