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

# Create Index

Create a new encrypted index with the specified configuration.

## Request Body

```json theme={null}
{
  "index_name": "my_index",
  "index_key": "64_character_hex_string_representing_32_bytes",
  "index_config": {
    "type": "ivfflat",
    "dimension": 384,
    "n_lists": 1024,
    "metric": "euclidean"
  },
  "embedding_model": "all-MiniLM-L6-v2"
}
```

<Expandable title="parameters">
  <ParamField body="index_name" type="string" required="true">
    Unique name for the index
  </ParamField>

  <ParamField body="index_key" type="string" required="true">
    32-byte encryption key as hex string
  </ParamField>

  <ParamField body="index_config" type="object" required="true">
    Index configuration object containing:

    * `type`: Index type (`ivfflat`, `ivf`, `ivfpq`)
    * `dimension`: Embedding dimension (required for `ivfflat` and `ivf`)
    * `n_lists`: Number of inverted lists (required for `ivfflat` and `ivf`)
    * `metric`: Distance metric (`euclidean`, `cosine`, `squared_euclidean`)

    See [Index Types](#index-types) for details.
  </ParamField>

  <ParamField body="embedding_model" type="string">
    Optional sentence-transformers model for automatic embedding generation
  </ParamField>
</Expandable>

## Index Types

### IVFFlat (Recommended)

Suitable for applications requiring high recall with moderate memory usage:

```json theme={null}
{
  "type": "ivfflat",
  "dimension": 384,
  "n_lists": 1024,
  "metric": "euclidean"
}
```

**Speed:** Fast | **Recall:** Highest | **Index Size:** Biggest

### IVF

Ideal for large-scale datasets where fast retrieval is prioritized:

```json theme={null}
{
  "type": "ivf",
  "dimension": 384,
  "n_lists": 1024,
  "metric": "euclidean"
}
```

**Speed:** Fastest | **Recall:** Lowest | **Index Size:** Smallest

### IVFPQ

Product Quantization compresses embeddings, balancing memory use and recall:

```json theme={null}
{
  "type": "ivfpq",
  "dimension": 384,
  "n_lists": 1024,
  "pq_dim": 64,
  "pq_bits": 8,
  "metric": "euclidean"
}
```

**Speed:** Fast | **Recall:** High | **Index Size:** Medium

## Distance Metrics

* `"euclidean"`: Euclidean distance
* `"cosine"`: Cosine similarity
* `"squared_euclidean"`: Squared Euclidean distance

## Response

```json theme={null}
{
  "status": "success",
  "message": "Index 'my_index' created successfully"
}
```

## Exceptions

* `401`: Authentication failed (invalid API key)
* `409`: Index name already exists
* `422`: Invalid request parameters
* `500`: Internal server error

## Example Usage

```bash theme={null}
curl -X POST "http://localhost:8000/v1/indexes/create" \
     -H "X-API-Key: cyborg_your_api_key_here" \
     -H "Content-Type: application/json" \
     -d '{
       "index_name": "my_index",
       "index_key": "your_64_character_hex_key_here",
       "index_config": {
         "type": "ivfflat",
         "dimension": 384,
         "n_lists": 1024,
         "metric": "euclidean"
       }
     }'
```

## With Auto-Embedding

```bash theme={null}
curl -X POST "http://localhost:8000/v1/indexes/create" \
     -H "X-API-Key: cyborg_your_api_key_here" \
     -H "Content-Type: application/json" \
     -d '{
       "index_name": "semantic_search_index",
       "index_key": "your_64_character_hex_key_here",
       "index_config": {
         "type": "ivfflat",
         "n_lists": 1024,
         "metric": "cosine"
       },
       "embedding_model": "all-MiniLM-L6-v2"
     }'
```

<Note>When `embedding_model` is specified, the `dimension` parameter in `index_config` is optional as it will be inferred from the embedding model.</Note>
