> ## 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 a New Encrypted Index

To create an encrypted index, you need to specify an index name (must be unique) and an index key:

<CodeGroup>
  ```python Python SDK icon="python" theme={null}
  from cyborgdb import Client

  # Create a client
  client = Client(
      base_url='http://localhost:8000', 
      api_key='your-api-key'
  )

  # Generate an encryption key for the index
  index_key = client.generate_key(save=False)

  # Create an encrypted index
  index = client.create_index(
      index_name="my_index", 
      index_key=index_key
  )
  ```

  ```javascript JavaScript SDK icon="js" theme={null}
  import { Client } from 'cyborgdb';

  // Create a client
  const client = new Client({ 
      baseUrl: 'http://localhost:8000', 
      apiKey: 'your-api-key' 
  });

  // Generate an encryption key for the index
  const indexKey = client.generateKey();

  // Create an encrypted index
  const index = await client.createIndex({ 
      indexName: "my_index", 
      indexKey 
  });
  ```

  ```typescript TypeScript SDK icon="code" theme={null}
  import { Client, EncryptedIndex, CreateIndexRequest } from 'cyborgdb';

  // Create a client
  const client = new Client({ 
      baseUrl: 'http://localhost:8000', 
      apiKey: 'your-api-key' 
  });

  // Generate an encryption key for the index
  const indexKey: Uint8Array = client.generateKey();

  // Create an encrypted index
  const params: CreateIndexRequest = {
      indexName: "my_index", 
      indexKey 
  };
  const index: EncryptedIndex = await client.createIndex(params);
  ```

  ```go Go SDK icon="golang" theme={null}
  package main

  import (
      "context"
      "log"
      
      "github.com/cyborginc/cyborgdb-go"
  )

  func main() {
      // Create client
      client, err := cyborgdb.NewClient("http://localhost:8000", "your-api-key")
      if err != nil {
          log.Fatal(err)
      }
      
      // Generate encryption key
      indexKey, err := cyborgdb.GenerateKey()
      if err != nil {
          log.Fatal(err)
      }
      
      // Create encrypted index
      params := &cyborgdb.CreateIndexParams{
          IndexName: "my_index",
          IndexKey:  indexKey,
      }
      
      ctx := context.Background()
      index, err := client.CreateIndex(ctx, params)
      if err != nil {
          log.Fatal(err)
      }
      
      log.Printf("Created index: %s", index.GetIndexName())
  }
  ```

  ```bash cURL icon="rectangle-terminal" theme={null}
  curl -X POST "http://localhost:8000/v1/indexes/create" \
       -H "X-API-Key: your-api-key" \
       -H "Content-Type: application/json" \
       -d '{
         "index_name": "my_index",
         "index_key": "your_64_character_hex_key_here"
       }'
  ```
</CodeGroup>

This creates a new encrypted **DiskIVF** index — the single index type in v0.17. For details on configuration knobs (`dimension`, `metric`, `storage_precision`, `embedding_model`), see [Configure an Encrypted Index](../advanced/configure-index).

<Note>v0.17 removed the polymorphic `index_config` argument and the `IndexIVFFlat` / `IndexIVFPQ` / `IndexIVFSQ` constructors from previous versions. Optional parameters — `metric` (`"euclidean"`, `"squared_euclidean"`, `"cosine"`), `dimension`, `embedding_model`, `storage_precision`, and `kms_name` — are now flat keyword arguments on `create_index`. See the [API Reference](#api-reference) for details.</Note>

<Warning>The example above creates a random 32 byte (256-bit) index key.
This is fine for evaluation purposes, but for production use, we recommend that you use an HSM or KMS solution.
For more details, see [Managing Encryption Keys](../advanced/managing-keys).</Warning>

## Index Caching

The service-based SDKs handle caching automatically on the server side. Unlike the embedded SDKs, you don't need to specify cache sizes when creating indexes.

The CyborgDB service optimizes query performance through:

* Automatic index caching based on usage patterns
* Server-side query optimization
* Efficient index loading and memory management

## Automatic Embedding Generation

<Tip>To use automatic embedding generation, use the [Docker Service](../intro/quickstart-docker) or install with `pip install cyborgdb-service[embeddings]`</Tip>

All Client SDKs support automatic embedding generation. You can specify an embedding model when creating the index:

<CodeGroup>
  ```python Python SDK icon="python" theme={null}
  from cyborgdb import Client

  # Create a client
  client = Client(
      base_url='http://localhost:8000', 
      api_key='your-api-key'
  )

  # Generate an encryption key for the index.
  # `save=True` is available for local evaluation (caches the key under ~/.cyborgdb/);
  # leave it as `save=False` (default) and persist the key in your own secret store.
  index_key = client.generate_key(save=False)

  # Set embedding model (from HuggingFace)
  embedding_model = "all-MiniLM-L6-v2"

  # Create an encrypted index with managed embedding generation
  index = client.create_index(
      index_name="my_index", 
      index_key=index_key, 
      embedding_model=embedding_model
  )
  ```

  ```javascript JavaScript SDK icon="js"   theme={null}
  import { Client } from 'cyborgdb';

  // Create a client
  const client = new Client({ 
      baseUrl: 'http://localhost:8000', 
      apiKey: 'your-api-key' 
  });

  // Generate an encryption key for the index
  const indexKey = client.generateKey();

  // Set embedding model (from HuggingFace)
  const embeddingModel = "all-MiniLM-L6-v2";
      
  // Create an encrypted index with managed embedding generation
  const index = await client.createIndex({ 
      indexName: "my_index", 
      indexKey, 
      embeddingModel 
  });
  ```

  ```typescript TypeScript SDK icon="code" theme={null}
  import { Client, EncryptedIndex, CreateIndexRequest } from 'cyborgdb';

  // Create a client
  const client = new Client({ 
      baseUrl: 'http://localhost:8000', 
      apiKey: 'your-api-key' 
  });

  // Generate an encryption key for the index
  const indexKey: Uint8Array = client.generateKey();

  // Set embedding model (from HuggingFace)
  const embeddingModel: string = "all-MiniLM-L6-v2";
      
  // Create an encrypted index with managed embedding generation
  const params: CreateIndexRequest = {
      indexName: "my_index", 
      indexKey, 
      embeddingModel 
  };
  const index: EncryptedIndex = await client.createIndex(params);
  ```

  ```go Go SDK icon="golang" theme={null}
  package main

  import (
      "context"
      "log"
      
      "github.com/cyborginc/cyborgdb-go"
  )

  func main() {
      // Create client
      client, err := cyborgdb.NewClient("http://localhost:8000", "your-api-key")
      if err != nil {
          log.Fatal(err)
      }
      
      // Generate encryption key
      indexKey, err := cyborgdb.GenerateKey()
      if err != nil {
          log.Fatal(err)
      }
      
      // Set embedding model
      embeddingModel := "all-MiniLM-L6-v2"
      
      // Create encrypted index with managed embedding generation
      params := &cyborgdb.CreateIndexParams{
          IndexName:      "my_index",
          IndexKey:       indexKey,
          EmbeddingModel: &embeddingModel,
      }
      
      ctx := context.Background()
      index, err := client.CreateIndex(ctx, params)
      if err != nil {
          log.Fatal(err)
      }
      
      log.Printf("Created index with embeddings: %s", index.GetIndexName())
  }
  ```

  ```bash cURL icon="rectangle-terminal" theme={null}
  curl -X POST "http://localhost:8000/v1/indexes/create" \
       -H "X-API-Key: your-api-key" \
       -H "Content-Type: application/json" \
       -d '{
         "index_name": "my_index",
         "index_key": "your_64_character_hex_key_here",
         "embedding_model": "all-MiniLM-L6-v2"
       }'
  ```
</CodeGroup>

## API Reference

For more information on creating encrypted indexes, refer to the API reference:

<CardGroup cols={2}>
  <Card title="REST API Reference" href="../../rest-api/client/create-index" icon="rectangle-terminal">
    REST API reference for `/v1/indexes/create`
  </Card>

  <Card title="Python SDK Reference" href="../../python-sdk/client/create-index" icon="python">
    API reference for `create_index()` in Python
  </Card>

  <Card title="JS/TS SDK Reference" href="../../js-ts-sdk/client/create-index" icon="js">
    API reference for `createIndex()` in JavaScript/TypeScript
  </Card>

  <Card title="Go SDK Reference" href="../../go-sdk/client/create-index" icon="golang">
    API reference for `CreateIndex()` in Go
  </Card>
</CardGroup>
