Creates a new encrypted vector index using comprehensive parameters. The new index is empty and ready for vector operations.
func (c *Client) CreateIndex(ctx context.Context, params *CreateIndexParams) (*EncryptedIndex, error)

Parameters

ParameterTypeDescription
ctxcontext.ContextContext for cancellation/timeouts
params*CreateIndexParamsComplete configuration for the new index

CreateIndexParams

FieldTypeRequiredDescription
IndexNamestringYesUnique identifier for the index
IndexKey[]byteYes32-byte encryption key
IndexConfigIndexModelNoIndex configuration (IVF, IVFFlat, or IVFPQ)
Metric*stringNoDistance metric (e.g., “euclidean”, “cosine”)
EmbeddingModel*stringNoAssociated embedding model name

Returns

TypeDescription
*EncryptedIndexHandle for performing vector operations on the new index
errorAny error encountered during index creation

Exceptions

Example Usage

Automatic Index Config

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
    key, err := cyborgdb.GenerateKey()
    if err != nil {
        log.Fatal(err)
    }
    
    // Create basic index
    params := &cyborgdb.CreateIndexParams{
        IndexName: "my-documents",
        IndexKey:  key,  // Pass bytes directly
    }
    
    ctx := context.Background()
    index, err := client.CreateIndex(ctx, params)
    if err != nil {
        log.Fatal(err)
    }
    
    log.Printf("Created index: %s", index.GetIndexName())
}
For more info on generateKey, refer to Generate Key.

IVFFlat Index with Embedding Model

// Initialize client
client, _ := cyborgdb.NewClient("http://localhost:8000", "your-api-key")
key, _ := cyborgdb.GenerateKey()

// Create an IVFFlat index with automatic embedding generation
config := cyborgdb.IndexIVFFlat()

embeddingModel := "text-embedding-3-large"

params := &cyborgdb.CreateIndexParams{
    IndexName:      "large-dataset",
    IndexKey:       key,
    IndexConfig:    config,
    Metric:         &metric,
    EmbeddingModel: &embeddingModel,
}

ctx := context.Background()
index, err := client.CreateIndex(ctx, params)
if err != nil {
    log.Fatal(err)
}
For more info on auto-generating embeddings, refer to Auto-Generate Embeddings.