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

# Train an Encrypted Index

<Note>This functionality is only present in the [core library](../get-started/about#deployment-models) version of CyborgDB.
In other versions (microservice, serverless), it is automatically called once enough vector embeddings have been indexed.</Note>

CyborgDB uses `IVF*` index types, which leverage clustering algorithms to segment the index into smaller sections for efficient querying. These clustering algorithms must be trained on the specific data being indexed in order to adequately represent that data.

In the core library version of CyborgDB, this training must be explicitly called once enough vectors have been added:

<CodeGroup>
  ```python Python theme={null}
  # Train the encrypted index
  index.train()
  ```

  ```cpp C++ theme={null}
  // Train the encrypted index
  index.Train();
  ```
</CodeGroup>

<Tip>You must have at least `2 * n_lists` number of vectors in the index (ingested via `upsert`) before you can call `train`.</Tip>

## Training Parameters

Parameters are available to customize the training process:

| Parameter    | Type    | Default | Description                                                                                   |
| ------------ | ------- | ------- | --------------------------------------------------------------------------------------------- |
| `batch_size` | `int`   | `0`     | *(Optional)* Size of each batch for training. `0` auto-selects the batch size.                |
| `max_iters`  | `int`   | `0`     | *(Optional)* Maximum number of iterations for training. `0` auto-selects the iteration count. |
| `tolerance`  | `float` | `1e-6`  | *(Optional)* Convergence tolerance for training.                                              |
| `max_memory` | `int`   | `0`     | *(Optional)* Maximum memory to use for training. `0` sets no limit.                           |

## Warnings with Large Untrained Queries

While training is technically optional (you can use CyborgDB without ever calling `train`), it is recommended that you do so once you have a large number of vectors in the index (e.g., `> 50,000`). If you don't, and you call `query`, you will see a warning in the console, stating:

```
Warning: querying untrained index with more than 50000 indexed vectors.
```

## API Reference

For more information on training an encrypted index, refer to the API reference:

<CardGroup cols={2}>
  <Card title="Python API Reference" href="../../api-reference/python/encrypted-index/train" icon="python">
    API reference for `train()` in Python
  </Card>

  <Card title="C++ API Reference" href="../../api-reference/cpp/encrypted-index/train" icon="brackets-curly">
    API reference for `Train()` in C++
  </Card>
</CardGroup>
