Creates and returns an EncryptedIndex instance based on the provided configuration.
async createIndex(
    indexName: string, 
    indexKey: Uint8Array, 
    indexConfig: IndexIVFPQModel | IndexIVFFlatModel | IndexIVFModel,
    embeddingModel?: string
): Promise<EncryptedIndex>

Parameters

ParameterTypeDescription
indexNamestringName of the index to create. Must be unique within the CyborgDB service.
indexKeyUint8Array32-byte encryption key for the index, used to secure the index data.
indexConfigIndexIVFPQModel | IndexIVFFlatModel | IndexIVFModelConfiguration object specifying the index type (ivf, ivfpq, or ivfflat) and relevant parameters such as dimension, nLists, pqDim, and pqBits.
embeddingModelstring(Optional) Name of the embedding model used to auto-generate embeddings on the server. Defaults to undefined, no auto-generation.
For more info on auto-generating embeddings, refer to Auto-Generate Embeddings.

Returns

Promise<EncryptedIndex>: A Promise that resolves to an instance of the newly created encrypted index.

Exceptions

Example Usage

Basic IVFFlat Index Creation

import { Client, IndexIVFFlatModel } from 'cyborgdb';

const client = new Client('http://localhost:8000', 'your-api-key');

const indexName = "my_vector_index";
const indexKey = crypto.getRandomValues(new Uint8Array(32)); // Generate secure 32-byte key

const indexConfig: IndexIVFFlatModel = {
    dimension: 768,
    nLists: 1024,
    metric: 'cosine'
};

try {
    const index = await client.createIndex(
        indexName, 
        indexKey, 
        indexConfig
    );
    console.log('Index created successfully:', index);
} catch (error) {
    console.error('Failed to create index:', error.message);
}

IVFPQ Index with Embedding Model

import { Client, IndexIVFPQModel } from 'cyborgdb';

const client = new Client('http://localhost:8000', 'your-api-key');

const indexName = "semantic_search_index";
const indexKey = crypto.getRandomValues(new Uint8Array(32));

const indexConfig: IndexIVFPQModel = {
    dimension: 1536,
    nLists: 2048,
    metric: 'cosine',
    pqDim: 64,
    pqBits: 8
};

try {
    const index = await client.createIndex(
        indexName,
        indexKey,
        indexConfig,
        'all-MiniLM-L6-v2'  // OpenAI embedding model
    );
    
    console.log('IVFPQ index with embeddings created successfully');
} catch (error) {
    console.error('Index creation failed:', error.message);
}