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

# add() / addMany()

> Add documents to the database

Add single or multiple documents to the vector database.

## add()

Add a single document.

### Signature

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
async add(id: string, text: string, metadata: T): Promise<void>
```

### Parameters

| Parameter | Type | Description |
| - | - | - |
| `id` | `string` | Unique document identifier |
| `text` | `string` | Text content to embed |
| `metadata` | `T` | Document metadata (must include `id` field matching the `id` parameter) |

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
await db.add('users:list', 'List all users with pagination', {
  id: 'users:list',
  toolName: 'list',
  owner: 'users',
  tags: ['read'],
  risk: 'safe',
});
```

### Errors

| Error | Condition |
| - | - |
| `VectoriaNotInitializedError` | Database not initialized |
| `DocumentExistsError` | Document ID already exists |
| `DocumentValidationError` | Empty text, size limit exceeded, or `metadata.id` mismatch |

***

## addMany()

Add multiple documents in a batch.

### Signature

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
async addMany(documents: Array<{ id: string; text: string; metadata: T }>): Promise<void>
```

### Parameters

| Parameter | Type | Description |
| - | - | - |
| `documents` | `Array<{ id, text, metadata }>` | Array of documents to add |

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
await db.addMany([
  {
    id: 'users:list',
    text: 'List all users with pagination',
    metadata: { id: 'users:list', toolName: 'list', owner: 'users', tags: ['read'], risk: 'safe' },
  },
  {
    id: 'users:create',
    text: 'Create a new user account',
    metadata: { id: 'users:create', toolName: 'create', owner: 'users', tags: ['write'], risk: 'safe' },
  },
]);
```

### Errors

| Error | Condition |
| - | - |
| `VectoriaNotInitializedError` | Database not initialized |
| `DuplicateDocumentError` | Duplicate ID in batch or existing document |
| `DocumentValidationError` | Empty text, size limit exceeded, batch size exceeded, or `metadata.id` mismatch |

### Validation

`addMany` performs these validations before processing:

* No duplicate IDs within the batch
* No IDs that already exist in the database
* All texts are non-empty
* All texts are within `maxDocumentSize`
* Batch size doesn't exceed `maxBatchSize`
* All `metadata.id` values match document IDs

## Performance

* `addMany` is significantly faster than calling `add` in a loop due to batch embedding generation.
* Embeddings are generated at \~100-200 documents/second.
* Use appropriate `maxBatchSize` to avoid memory spikes.

## Related

> **[search()](https://docs.agentfront.dev/vectoriadb/api-reference/vectoriadb/search.md)**
>
> Query documents

> **[update()](https://docs.agentfront.dev/vectoriadb/api-reference/vectoriadb/update.md)**
>
> Update documents

> **[remove()](https://docs.agentfront.dev/vectoriadb/api-reference/vectoriadb/remove.md)**
>
> Remove documents


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.