Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add: reserve parameter added to Index for c# sdk#666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
jamesryanbell wants to merge1 commit intounum-cloud:main
base:main
Choose a base branch
Loading
fromjamesryanbell:main

Conversation

@jamesryanbell
Copy link

Addreserve parameter to all USearchIndex constructors

This addresses#441

Summary

This PR adds an optionalreserve parameter to all three USearchIndex constructors to allow pre-allocation of memory for incoming vectors, improving performance when the expected number of vectors is known in advance.

Changes Made

1. First Constructor (Parameter-based)

  • Before:
    publicUSearchIndex(MetricKind metricKind,ScalarKind quantization,ulong dimensions,ulong connectivity=0,ulong expansionAdd=0,ulong expansionSearch=0,bool multi= false)
  • After:
    publicUSearchIndex(MetricKind metricKind,ScalarKind quantization,ulong dimensions,ulong connectivity=0,ulong expansionAdd=0,ulong expansionSearch=0,bool multi= false,ulong reserve=0)

2. Second Constructor (IndexOptions-based)

  • Before:
    publicUSearchIndex(IndexOptions options)
  • After:
    publicUSearchIndex(IndexOptions options,ulong reserve=0)
  • Added reserve logic:if (reserve > 0) { this.IncreaseCapacity(reserve); }
  • Added XML documentation for the new parameter

3. Third Constructor (File-based)

  • Before:
    publicUSearchIndex(string path,bool view= false)
  • After:
    publicUSearchIndex(string path,bool view= false,ulong reserve=0)
  • Added reserve logic:if (reserve > 0) { this.IncreaseCapacity(reserve); }
  • Added XML documentation for the new parameter

Benefits

  • Performance: Pre-allocates memory to avoid reallocations during vector insertion
  • Consistency: All constructors now support the same reserve functionality
  • Backward Compatibility: Default value of0 ensures existing code continues to work

Usage Examples

// Pre-allocate for 1000 vectorsvarindex1=newUSearchIndex(MetricKind.Cos,ScalarKind.Float32,128,reserve:1000);// Pre-allocate when loading from filevarindex2=newUSearchIndex("index.usearch",reserve:5000);// Pre-allocate with IndexOptionsvaroptions=newIndexOptions{/* ... */};varindex3=newUSearchIndex(options,reserve:2000);

Breaking Changes

None - this is a purely additive change with default parameter values.

@jamesryanbell
Copy link
Author

Hi@ashvardanian, do you know when someone will be able to review this please

@ashvardanian
Copy link
Contributor

Hi@jamesryanbell! Thanks for the PR!

I don't yet see the relationship between the proposed APIs and multi-threading in#441.

Why do we need a reserve argument in multiple methods as opposed to a single reserve method?

@jamesryanbell
Copy link
Author

Hi@ashvardanian, when I try and create an index using multiple threads I run into an issue where the capacity is not increased. This change would allow me to set the capacity before the parallel operation.

I can't resize increase the capacity currently asIncreaseCapacity is a private method

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@jamesryanbell@ashvardanian

[8]ページ先頭

©2009-2025 Movatter.jp