Creates and returns an EncryptedIndex instance based on the provided configuration.
async createIndex({
    indexName: string,                                      // required
    indexKey: Uint8Array,                                   // required
    indexConfig?: IndexConfig,                              // optional, default: IndexIVFFlat()
    metric?: 'euclidean' | 'squared_euclidean' | 'cosine',  // optional, default: 'euclidean'
    embeddingModel?: string                                 // optional, default: undefined
}): 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.
indexConfigIndexIVFPQ | IndexIVFFlat | IndexIVF(Optional) Configuration object specifying the index type (ivf, ivfpq, or ivfflat). Defaults to IndexIVFFlat().
metric'euclidean' | 'squared_euclidean' | 'cosine'(Optional) Distance metric to use for the index. Defaults to 'euclidean'.
embeddingModelstring(Optional) Name of the embedding model used to auto-generate embeddings on the server. Defaults to undefined, no auto-generation.

Returns

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

Exceptions

Example Usage

Automatic Index Config

import { Client } from 'cyborgdb';

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

const indexName = "my_vector_index";
const indexKey: Uint8Array = client.generateKey(); // Generate secure 32-byte key

try {
    const index = await client.createIndex({
        indexName,
        indexKey
    });
    console.log('Index created successfully:', index);
} catch (error) {
    console.error('Failed to create index:', error.message);
}
For more info on generateKey, refer to Generate Key.

IVFFlat Index with Embedding Model

import { Client, IndexIVFFlat } from 'cyborgdb';

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

const indexName = "semantic_search_index";
const indexKey: Uint8Array = client.generateKey();

const indexConfig: IndexIVFFlat = new IndexIVFFlat();

try {
    const index = await client.createIndex({
        indexName,
        indexKey,
        indexConfig,
        embeddingModel: 'all-MiniLM-L6-v2'  // Embedding model
    });
    
    console.log('IVFPQ index with embeddings created successfully');
} catch (error) {
    console.error('Index creation failed:', error.message);
}
For more info on auto-generating embeddings, refer to Auto-Generate Embeddings.