Training requires at least 10,000 vectors and at least
2 * n_lists vectors in the index (ingested via upsert). If the index has fewer, train does not return an error: the service logs a warning and the index stays untrained. Use is_trained() to check whether training took effect.Training Parameters
Parameters are available to customize the training process:n_lists is the number of clusters into which each vector in the index can be categorized. Typically, the higher the value, the higher the recall (but also the slower the indexing process). As a good rule of thumb, n_lists should be:
- A base-2 number (e.g.,
2,048,4,096). Not a requirement, but yields performance optimizations. - Each cluster should have between
100-10,000vectors; son_listsshould be roughly between1/100-1/10,000of the total number of items which will be indexed.
n_lists value based on the number of vectors in the index.
How automatic training works
After each upsert, the service checks whether the index should be trained or retrained:- First training. An untrained index is trained automatically once it holds more than
AUTO_TRAIN_MIN_VECTORSvectors (default65536). - Retraining. A trained index is retrained automatically when the optimal
n_listsfor its current vector count grows past the index’s currentn_lists. The optimaln_listsis the square root of the vector count, rounded to a power of two and capped at65,536. In practice, an index is retrained roughly each time its vector count grows about 4x.
n_lists for the vector count at the time it runs. Training runs in the background, so the upsert that triggers it returns immediately.
For an index that was first trained automatically, the progression looks like this:
If you train with an explicit
n_lists, the index is retrained automatically only once the optimal n_lists exceeds the value you chose.
To change the first-training threshold, set AUTO_TRAIN_MIN_VECTORS. To turn off automatic training and retraining entirely, set AUTO_TRAIN_DISABLED=true; you then train indexes yourself with train(). See the Environment Variables guide.
Avoid the large-untrained-query warning
While training is technically optional (you can use CyborgDB without ever callingtrain), it is recommended that you do so once you have a large number of vectors in the index (e.g., > 50,000). If you don’t, and you call query, you will see a warning in the console, stating:
API Reference
For more information on training an encrypted index, refer to the API reference:REST API Reference
REST API reference for
/v1/indexes/trainPython SDK Reference
API reference for
train() in PythonJS/TS SDK Reference
API reference for
train() in JavaScript/TypeScriptGo SDK Reference
API reference for
Train() in Go