# Persistence - Recover Vector Database

Describes procedures to recover lost or corrupt Vector Databases. In case of an issue with the vector database, Unique AI is able to recreate a specific collection or even all collections on a cluster via maintenance endpoints.

To be able to use these maintenance endpoints you need to obtain a token of a service user which belongs to the “root” organization in Zitadel. With a user JWT token of this root organization, which holds the Unique Zitadel project, you are able to call those maintenance endpoints.

# Get Token of Root Organisation User

Check here how to get a token: [How To Get An API Token](https://docs.unique.ai/it-operators/identity-and-access-management-iam/how-to-get-an-api-token)

# Maintenance Endpoints

Refer to [Multitenant Region URLs](https://docs.unique.ai/it-operators/installing-and-upgrading-unique/multitenant-region-urls) to find the correct base URL for your deployment.

## Rebuild Specific Collection of Vector DB

Unique AI provides the following endpoint to rebuild a new collection for a specific organization on a tenant. In order to do so you need the following information:

- apiUrl (can be taken from the frontend calls - e.g. `gateway.myTenant.unique.app`)
- token of the root organisation user
- companyId = Zitadel organisation ID
- (optional query: `createNewCollection` - default is true. If set to false it will upsert the vectors in the existing collection.)

```bash
curl --location --request POST 'https://{apiUrl}/ingestion/v1/maintenance/rebuild-vector-db?companyId=220404780256722957' \
--header 'Authorization: Bearer token'
```

This will now asynchronously either create a new collection or upsert the existing collection based on the vector data which is existing in the postgres database for this specific company/organisation. You will find information log lines starting with `RebuildVectorDatabase` in the ingestion service including the line `RebuildVectorDatabase: Finished ...`, which indicates that the rebuild worked successfully. As soon as the process is finished it will switch to use automatically the new collection for the vector search.

## Rebuild full Vector DB

By calling this endpoint Unique AI will rebuild a new collection for every organisation on this tenant. In order to do so you need the following information:

- apiUrl (can be taken from the frontend calls - e.g. `gateway.myTenant.unique.app`)
- token of the root organisation user

```bash
curl --location --request POST 'https://{apiUrl}/ingestion/v1/maintenance/rebuild-full-vector-db' \
--header 'Authorization: Bearer token'
```

This will now asynchronously create a new collection based on the vector data which is existing in the postgres database. You will find information log lines starting with `RebuildVectorDatabase` in the ingestion service including the line `RebuildVectorDatabase: Finished full sync for x companies`, which indicates that the rebuild worked successfully. As soon as one collection is finished it will switch to use automatically this new collection for this company.
