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

# Error Classes

> VectoriaDB error types and codes

All VectoriaDB errors extend `VectoriaError` and include machine-readable `code` values.

## Error Types

| Error                         | Code                        | Description                |
| ----------------------------- | --------------------------- | -------------------------- |
| `VectoriaNotInitializedError` | `NOT_INITIALIZED`           | Call `initialize()` first  |
| `DocumentValidationError`     | `DOCUMENT_VALIDATION_ERROR` | Invalid document data      |
| `DocumentNotFoundError`       | `DOCUMENT_NOT_FOUND`        | Document ID doesn't exist  |
| `DocumentExistsError`         | `DOCUMENT_EXISTS`           | Document ID already exists |
| `DuplicateDocumentError`      | `DUPLICATE_DOCUMENT`        | Duplicate in batch         |
| `QueryValidationError`        | `QUERY_VALIDATION_ERROR`    | Invalid search query       |
| `EmbeddingError`              | `EMBEDDING_ERROR`           | Model embedding failed     |
| `StorageError`                | `STORAGE_ERROR`             | Storage operation failed   |
| `ConfigurationError`          | `CONFIGURATION_ERROR`       | Invalid config             |

## Importing Errors

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
import {
  VectoriaError,
  VectoriaNotInitializedError,
  DocumentValidationError,
  DocumentNotFoundError,
  DocumentExistsError,
  DuplicateDocumentError,
  QueryValidationError,
  EmbeddingError,
  StorageError,
  ConfigurationError,
} from 'vectoriadb';
```

## VectoriaError

Base class for all VectoriaDB errors.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class VectoriaError extends Error {
  readonly code: string;

  constructor(message: string, code: string);
}
```

***

## VectoriaNotInitializedError

Thrown when operations are attempted before initialization.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class VectoriaNotInitializedError extends VectoriaError {
  constructor(operation: string);
}
```

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
try {
  await db.add('id', 'text', metadata);
} catch (error) {
  if (error instanceof VectoriaNotInitializedError) {
    await db.initialize();
    await db.add('id', 'text', metadata);
  }
}
```

***

## DocumentValidationError

Thrown when document validation fails.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class DocumentValidationError extends VectoriaError {
  readonly documentId?: string;

  constructor(message: string, documentId?: string);
}
```

***

## DocumentNotFoundError

Thrown when a document ID doesn't exist.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class DocumentNotFoundError extends VectoriaError {
  readonly documentId: string;

  constructor(documentId: string);
}
```

***

## DocumentExistsError

Thrown when adding a document with an existing ID.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class DocumentExistsError extends VectoriaError {
  readonly documentId: string;

  constructor(documentId: string);
}
```

***

## DuplicateDocumentError

Thrown when duplicates are found in batch operations.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class DuplicateDocumentError extends VectoriaError {
  readonly documentId: string;
  readonly context: 'batch' | 'existing';

  constructor(documentId: string, context: 'batch' | 'existing');
}
```

***

## QueryValidationError

Thrown when search parameters are invalid.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class QueryValidationError extends VectoriaError {
  constructor(message: string);
}
```

***

## EmbeddingError

Thrown when embedding generation fails.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class EmbeddingError extends VectoriaError {
  readonly details?: any;

  constructor(message: string, details?: any);
}
```

***

## StorageError

Thrown when storage operations fail.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class StorageError extends VectoriaError {
  readonly originalError?: Error;

  constructor(message: string, originalError?: Error);
}
```

***

## ConfigurationError

Thrown when configuration is invalid.

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
class ConfigurationError extends VectoriaError {
  constructor(message: string);
}
```

## Error Handling Pattern

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
try {
  await db.addMany(documents);
} catch (error) {
  if (error instanceof VectoriaNotInitializedError) {
    await db.initialize();
    return; // Retry
  }

  if (error instanceof DocumentValidationError) {
    console.warn(`Invalid document: ${error.documentId}`);
    return;
  }

  if (error instanceof VectoriaError) {
    console.error(`VectoriaDB error [${error.code}]:`, error.message);
    return;
  }

  throw error; // Re-throw unexpected errors
}
```

## Related

<CardGroup cols={2}>
  <Card title="Common Errors" icon="triangle-exclamation" href="/vectoriadb/troubleshooting/common-errors">
    Error solutions
  </Card>

  <Card title="FAQ" icon="circle-question" href="/vectoriadb/troubleshooting/faq">
    Frequently asked questions
  </Card>
</CardGroup>
