> ## Documentation Index
> Fetch the complete documentation index at: https://www.paradedb.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Vector Indexes

> Settings and practices for building and maintaining vector indexes

These actions apply to a ParadeDB index with a vector field. The general advice in [Index Creation](https://www.paradedb.com/docs/operate/performance-tuning/create-index.md) and [Write Throughput](https://www.paradedb.com/docs/operate/performance-tuning/writes.md) applies as well.

## Building a Large Index

`CREATE INDEX` and `REINDEX` on a vector column group the vectors into clusters and compress them, which takes more CPU and memory than a text-only build. Load the data first, then create the index.

### Workers

The build uses the leader plus up to `max_parallel_maintenance_workers` workers, within `max_parallel_workers` and `max_worker_processes`.

```sql theme={null}
SET max_parallel_maintenance_workers = 8;
```

### Memory

`maintenance_work_mem` is divided evenly among the build processes, including the leader. Each process uses up to 1 GiB of its share and needs at least 15 MB. As a starting point, give each process 1 GiB:

```sql theme={null}
-- 8 workers and the leader
SET maintenance_work_mem = '9GB';
```

### Progress

`pg_stat_progress_create_index` shows the current phase:

```sql theme={null}
SELECT phase, tuples_done, tuples_total
FROM pg_stat_progress_create_index;
```

Row counters pause during the training and clustering phases. This is normal: they are the most CPU-intensive steps.

A build that takes a minute or longer ends with a `NOTICE` summarizing rows, segments, size, and time. [Troubleshooting](https://www.paradedb.com/docs/reference/vector/troubleshooting.md#warnings-and-notices-during-a-build) lists the other messages a build can print.

## Writes and Merges

A vector index stays correct as rows are inserted, updated, and deleted, with no rebuild.

Newly written rows are not clustered. A query compares against each of them, which is exact and costs time in proportion to how many there are. [Background merging](https://www.paradedb.com/docs/operate/performance-tuning/writes.md#ensuring-merging-happens-in-the-background) combines them into larger segments and clusters them. Keep it enabled.

To see how much of an index is clustered:

```sql theme={null}
SELECT vector_format,
       count(*) AS segments,
       sum(vector_num_vectors) AS vectors
FROM paradedb.vector_info('search_idx', 'embedding')
GROUP BY vector_format;
```

`ivf` rows are clustered and `flat` rows are not. An index answers fastest when nearly all of its vectors are in `ivf` segments.

## When to Rebuild

Routine writes do not require a rebuild. Run `REINDEX` in these cases:

| Situation | Why |
| - | - |
| You changed an [index option](https://www.paradedb.com/docs/reference/indexing/field-types/vector.md#index-options) with `ALTER INDEX`. | A rebuild applies the new value to the whole index. |
| A query fails with `has an unsupported vector storage format` after an upgrade. | The index was written by a release with a different vector storage format. |

```sql theme={null}
REINDEX INDEX CONCURRENTLY search_idx;
```

To change the distance metric, drop the index and create it with a different operator class. `REINDEX` keeps the existing one.


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