diff --git a/csharp/src/Cloud.Unum.USearch/USearchIndex.cs b/csharp/src/Cloud.Unum.USearch/USearchIndex.cs index 22d3ab671..3486855fc 100644 --- a/csharp/src/Cloud.Unum.USearch/USearchIndex.cs +++ b/csharp/src/Cloud.Unum.USearch/USearchIndex.cs @@ -23,6 +23,7 @@ public class USearchIndex : IDisposable /// The optional expansion factor used for index construction when adding vectors. /// The optional expansion factor used for index construction during search operations. /// When set allows multiple vectors to map to the same key. + /// Reserves memory for a specified number of incoming vectors. public USearchIndex( MetricKind metricKind, ScalarKind quantization, @@ -30,7 +31,8 @@ public USearchIndex( ulong connectivity = 0, ulong expansionAdd = 0, ulong expansionSearch = 0, - bool multi = false + bool multi = false, + ulong reserve = 0 ) { IndexOptions initOptions = new() @@ -48,17 +50,28 @@ public USearchIndex( this._index = usearch_init(ref initOptions, out IntPtr error); HandleError(error); this._cachedDimensions = dimensions; + + if (reserve > 0) + { + this.IncreaseCapacity(reserve); + } } /// /// Initializes a new instance of the USearchIndex class with specified options. /// /// The options structure containing initialization parameters. - public USearchIndex(IndexOptions options) + /// Reserves memory for a specified number of incoming vectors. + public USearchIndex(IndexOptions options, ulong reserve = 0) { this._index = usearch_init(ref options, out IntPtr error); HandleError(error); this._cachedDimensions = options.dimensions; + + if (reserve > 0) + { + this.IncreaseCapacity(reserve); + } } /// @@ -66,7 +79,8 @@ public USearchIndex(IndexOptions options) /// /// The file path from where the index will be loaded or viewed. /// If true, creates a view of the index without copying it into memory. - public USearchIndex(string path, bool view = false) + /// Reserves memory for a specified number of incoming vectors. + public USearchIndex(string path, bool view = false, ulong reserve = 0) { IndexOptions initOptions = new(); this._index = usearch_init(ref initOptions, out IntPtr error); @@ -84,6 +98,11 @@ public USearchIndex(string path, bool view = false) HandleError(error); this._cachedDimensions = this.Dimensions(); + + if (reserve > 0) + { + this.IncreaseCapacity(reserve); + } } ///