unum-cloud / usearch

Fast Open-Source Search & Clustering engine × for Vectors & 🔜 Strings × in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram 🔍
https://unum-cloud.github.io/usearch/
Apache License 2.0
2.27k stars 143 forks source link

Bug: Insertwith multiple threads throws exception on C# Bindings #440

Closed etempm closed 5 months ago

etempm commented 5 months ago

Describe the bug

I am using following code to initialize USearch index with c#. UIndex = new USearchIndex( metricKind: MetricKind.Cos, // Choose cosine metric quantization: ScalarKind.Float32, // Only quantization to Float32, Float64 is currently supported dimensions: 512, // Define the number of dimensions in input vectors connectivity: 16, // How frequent should the connections in the graph be, optional expansionAdd: 128, // Control the recall of indexing, optional expansionSearch: 64, // Control the quality of search, optional multi: true ); Parallel.For(0L, 102400L, i => { float[] tmpVector = new float[512]; for (int j = 0; j < 512; j++) { tmpVector[j] = Random.Shared.NextSingle(); } UIndex.Add((ulong)i, tmpVector); });

When I run this, I am getting error. "Cloud.Unum.USearch.USearchException: 'USearch operation failed: Reserve capacity ahead of insertions!'"

I can not find to set or increase capacity mannualy, or in constructor method. Can you help me?

Steps to reproduce

Just run this code and exception throws.

Expected behavior

Able to set initial capacity or resize with method.

USearch version

2.12.0

Operating System

Windows 11

Hardware architecture

x86

Which interface are you using?

Other bindings

Contact Details

etempm@gmail.com

Are you open to being tagged as a contributor?

Is there an existing issue for this?

Code of Conduct

ashvardanian commented 5 months ago

You have to reserve capacity before starting insertions. https://github.com/unum-cloud/usearch/blob/5ea48c87c56a25ab57634a8f207f80ae675ed58e/csharp/src/Cloud.Unum.USearch/USearchIndex.cs#L116

etempm commented 5 months ago

Hi, thanks for fast reply. I saw that method, but it is private. I can not access that method. So I clonned repo and modified it public. When I run, same error. Access vialotion !!. I will make some test and give you info about this. Thanks again.

ashvardanian commented 5 months ago

Gotcha! Would be great if you could open a PR making that interface public 🤗

etempm commented 5 months ago

I am working some improvments on this. After finish, I will share it. Thanks again.