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

# update() / updateMetadata()

> Update documents in the database

Update document text and/or metadata.

## updateMetadata()

Update metadata without re-embedding. Fast operation.

### Signature

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
updateMetadata(id: string, metadata: T): void
```

### Parameters

| Parameter  | Type     | Description         |
| ---------- | -------- | ------------------- |
| `id`       | `string` | Document ID         |
| `metadata` | `T`      | New metadata object |

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
db.updateMetadata('users:list', {
  id: 'users:list',
  toolName: 'list',
  owner: 'users',
  tags: ['read', 'legacy'],
  risk: 'safe',
  deprecated: true,
});
```

### Errors

| Error                         | Condition                 |
| ----------------------------- | ------------------------- |
| `VectoriaNotInitializedError` | Database not initialized  |
| `DocumentNotFoundError`       | Document ID doesn't exist |

***

## update()

Update text and/or metadata with smart re-embedding.

### Signature

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
async update(
  id: string,
  updates: { text?: string; metadata?: T },
  options?: { forceReembed?: boolean }
): Promise<boolean>
```

### Parameters

| Parameter              | Type      | Description                               |
| ---------------------- | --------- | ----------------------------------------- |
| `id`                   | `string`  | Document ID                               |
| `updates.text`         | `string`  | New text (optional)                       |
| `updates.metadata`     | `T`       | New metadata (optional)                   |
| `options.forceReembed` | `boolean` | Force re-embedding even if text unchanged |

### Return Value

Returns `true` if the document was re-embedded, `false` if only metadata was updated.

### Examples

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
// Metadata-only update (no re-embed)
const reembedded = await db.update('id', {
  metadata: newMetadata,
});
console.log(reembedded); // false

// Text update (triggers re-embed)
const reembedded = await db.update('id', {
  text: 'New description',
  metadata: newMetadata,
});
console.log(reembedded); // true

// Force re-embed
await db.update('id', {
  text: existingText,
  metadata: newMetadata,
}, { forceReembed: true });
```

### Errors

| Error                         | Condition                         |
| ----------------------------- | --------------------------------- |
| `VectoriaNotInitializedError` | Database not initialized          |
| `DocumentNotFoundError`       | Document ID doesn't exist         |
| `DocumentValidationError`     | Empty text or size limit exceeded |

***

## updateMany()

Update multiple documents in batch.

### Signature

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
async updateMany(
  updates: Array<{ id: string; text?: string; metadata?: T }>,
  options?: { forceReembed?: boolean }
): Promise<{ updated: number; reembedded: number }>
```

### Return Value

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
{
  updated: number;     // Total documents updated
  reembedded: number;  // Documents that required re-embedding
}
```

### Example

```ts theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
const result = await db.updateMany([
  { id: 'doc1', text: 'New text', metadata: meta1 },
  { id: 'doc2', metadata: meta2 }, // Metadata only
]);

console.log(`Updated: ${result.updated}, Re-embedded: ${result.reembedded}`);
```

## Related

<CardGroup cols={3}>
  <Card title="add()" icon="plus" href="/vectoriadb/api-reference/vectoriadb/add">
    Add documents
  </Card>

  <Card title="remove()" icon="trash" href="/vectoriadb/api-reference/vectoriadb/remove">
    Remove documents
  </Card>

  <Card title="search()" icon="magnifying-glass" href="/vectoriadb/api-reference/vectoriadb/search">
    Search documents
  </Card>
</CardGroup>
