Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions csharp/src/Cloud.Unum.USearch/USearchIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ public class USearchIndex : IDisposable
/// <param name="expansionAdd">The optional expansion factor used for index construction when adding vectors.</param>
/// <param name="expansionSearch">The optional expansion factor used for index construction during search operations.</param>
/// <param name="multi">When set allows multiple vectors to map to the same key.</param>
/// <param name="reserve">Reserves memory for a specified number of incoming vectors.</param>
public USearchIndex(
MetricKind metricKind,
ScalarKind quantization,
ulong dimensions,
ulong connectivity = 0,
ulong expansionAdd = 0,
ulong expansionSearch = 0,
bool multi = false
bool multi = false,
ulong reserve = 0
)
{
IndexOptions initOptions = new()
Expand All @@ -48,25 +50,37 @@ public USearchIndex(
this._index = usearch_init(ref initOptions, out IntPtr error);
HandleError(error);
this._cachedDimensions = dimensions;

if (reserve > 0)
{
this.IncreaseCapacity(reserve);
}
}

/// <summary>
/// Initializes a new instance of the USearchIndex class with specified options.
/// </summary>
/// <param name="options">The options structure containing initialization parameters.</param>
public USearchIndex(IndexOptions options)
/// <param name="reserve">Reserves memory for a specified number of incoming vectors.</param>
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);
}
}

/// <summary>
/// Initializes a new instance of the USearchIndex class and loads or views the index from a specified file.
/// </summary>
/// <param name="path">The file path from where the index will be loaded or viewed.</param>
/// <param name="view">If true, creates a view of the index without copying it into memory.</param>
public USearchIndex(string path, bool view = false)
/// <param name="reserve">Reserves memory for a specified number of incoming vectors.</param>
public USearchIndex(string path, bool view = false, ulong reserve = 0)
{
IndexOptions initOptions = new();
this._index = usearch_init(ref initOptions, out IntPtr error);
Expand All @@ -84,6 +98,11 @@ public USearchIndex(string path, bool view = false)
HandleError(error);

this._cachedDimensions = this.Dimensions();

if (reserve > 0)
{
this.IncreaseCapacity(reserve);
}
}

/// <summary>
Expand Down