getIndexName
async getIndexName(): Promise<string>
Retrieves the name of the encrypted index from the CyborgDB service.
Returns
Promise<string>: A Promise that resolves to the unique name identifier of the index.
Exceptions
- Throws if the API request fails due to network connectivity issues
- Throws if authentication fails (invalid API key or encryption key)
- Throws if the index doesn’t exist on the server
Example Usage
try {
const indexName = await index.getIndexName();
console.log('Index name:', indexName);
// Output: "my-vectors"
// Use for verification
if (indexName === 'expected-index-name') {
console.log('✓ Connected to correct index');
}
} catch (error) {
console.error('Failed to get index name:', error.message);
}
getIndexType
async getIndexType(): Promise<string | undefined>
Retrieves the type of the index from the CyborgDB service.
Returns
Promise<string | undefined>: A Promise that resolves to the index type ('ivfflat', 'ivfpq', or 'ivfsq'), or undefined if not set.
Exceptions
- Throws if the API request fails due to network connectivity issues
- Throws if authentication fails (invalid API key or encryption key)
- Throws if the index doesn’t exist on the server
Example Usage
try {
const indexType = await index.getIndexType();
console.log('Index type:', indexType);
// Output: "ivfflat"
switch (indexType) {
case 'ivfpq':
console.log('Using IVFPQ index for memory efficiency');
break;
case 'ivfflat':
console.log('Using IVFFlat index for high accuracy');
break;
case 'ivfsq':
console.log('Using IVFSQ index for balanced speed and size');
break;
default:
console.log('Unknown or undefined index type');
}
} catch (error) {
console.error('Failed to get index type:', error.message);
}
isTrained
async isTrained(): Promise<boolean>
Checks whether the index has been trained by querying the CyborgDB service. Training is required for optimal query performance on IVF-based indexes.
Returns
Promise<boolean>: A Promise that resolves to true if the index has been trained, false otherwise.
Exceptions
- Throws if the API request fails due to network connectivity issues
- Throws if authentication fails (invalid API key or encryption key)
- Throws if the index doesn’t exist on the server
Example Usage
try {
const trained = await index.isTrained();
console.log('Index trained:', trained);
if (!trained) {
console.log('Index needs training for optimal performance');
await index.train();
// Verify training completed
const isNowTrained = await index.isTrained();
console.log('Training completed:', isNowTrained);
} else {
console.log('Index is ready for queries');
}
} catch (error) {
console.error('Failed to check training status:', error.message);
}
getIndexConfig
async getIndexConfig(): Promise<IndexIVFFlat | IndexIVFSQ | IndexIVFPQ>
Retrieves the complete index configuration from the CyborgDB service and returns a copy to prevent external modification of the internal state. The return type depends on the index type.
Returns
Promise<IndexIVFFlat>: For IVF Flat indexes
Promise<IndexIVFSQ>: For IVFSQ indexes
Promise<IndexIVFPQ>: For IVF PQ indexes
Exceptions
- Throws if the API request fails due to network connectivity issues
- Throws if authentication fails (invalid API key or encryption key)
- Throws if the index doesn’t exist on the server
Example Usage
try {
const config = await index.getIndexConfig();
console.log('Index configuration:', config);
// Access common properties
console.log('Type:', config.type);
console.log('Dimension:', config.dimension);
// Type-specific properties
if (config.type === 'ivfpq') {
const pqConfig = config as IndexIVFPQ;
console.log('PQ dimension:', pqConfig.pqDim);
console.log('PQ bits:', pqConfig.pqBits);
} else if (config.type === 'ivfsq') {
const sqConfig = config as IndexIVFSQ;
console.log('SQ bits:', sqConfig.sqBits);
}
} catch (error) {
console.error('Failed to get index config:', error.message);
}
Configuration Properties
Common Properties (All Index Types)
| Property | Type | Description |
|---|
dimension | number | Vector dimensionality |
IVFPQ-Specific Properties
| Property | Type | Description |
|---|
pqDim | number | Product quantization dimension |
pqBits | number | Number of bits for quantization |
isTraining
Unlike the other methods on this page, isTraining() is a Client method, not an EncryptedIndex method. Call it on the client instance, not on an index.
async isTraining(): Promise<{
training_indexes: string[];
retrain_threshold: number;
}>
Checks if any indexes are currently being trained on the CyborgDB service. This is a Client method, not an EncryptedIndex method.
Returns
Promise<object>: A Promise that resolves to an object containing:
training_indexes: Array of index names that are currently being trained
retrain_threshold: The multiplier used for the retraining threshold
Exceptions
- Throws if the API request fails due to network connectivity issues
- Throws if authentication fails (invalid API key)
- Throws if the server returns an error response
Example Usage
import { Client } from 'cyborgdb';
const client = new Client({ baseUrl: 'http://localhost:8000', apiKey: 'your-api-key' });
try {
const trainingStatus = await client.isTraining();
console.log('Training status:', trainingStatus);
// Output: { training_indexes: ['index1', 'index2'], retrain_threshold: 2.0 }
if (trainingStatus.training_indexes.length > 0) {
console.log('Indexes currently training:');
trainingStatus.training_indexes.forEach(indexName => {
console.log(` - ${indexName}`);
});
} else {
console.log('No indexes are currently being trained');
}
} catch (error) {
console.error('Failed to check training status:', error.message);
}