hnswlib 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/ext/hnswlib/hnswlibext.hpp +64 -10
- data/lib/hnswlib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe29cb17343b0e602684976fa3bd91a9756226e42fdaedded8398e8d97dc83d
|
4
|
+
data.tar.gz: 5b1fca956e5a4bb3e28b46dd891f969a4dbfe7b1f03295657322ffc77b089595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 213e43f294b0c6e306aef4a700df4b733b1cbd40253a61d91b15b272b7f0e2b095a5eebc79efb5d5d8af8b01048752a87bad4f610b528d49c1809d09e8e9c51b
|
7
|
+
data.tar.gz: 2cffaef5381339dd85d8ad93aff9bf1e3ac271a7797b9e5a8c6122836d3401da17380f31db6594577d5412a0c1372609ed3e3b717c401b603370113d8d811e05
|
data/CHANGELOG.md
CHANGED
data/ext/hnswlib/hnswlibext.hpp
CHANGED
@@ -277,7 +277,12 @@ class RbHnswlibHierarchicalNSW {
|
|
277
277
|
const size_t random_seed = (size_t)NUM2INT(kw_values[4]);
|
278
278
|
|
279
279
|
hnswlib::HierarchicalNSW<float>* ptr = get_hnsw_hierarchicalnsw(self);
|
280
|
-
|
280
|
+
try {
|
281
|
+
new (ptr) hnswlib::HierarchicalNSW<float>(space, max_elements, m, ef_construction, random_seed);
|
282
|
+
} catch(const std::runtime_error& e) {
|
283
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
284
|
+
return Qnil;
|
285
|
+
}
|
281
286
|
|
282
287
|
return Qnil;
|
283
288
|
};
|
@@ -334,8 +339,14 @@ class RbHnswlibHierarchicalNSW {
|
|
334
339
|
vec[i] = (float)NUM2DBL(rb_ary_entry(arr, i));
|
335
340
|
}
|
336
341
|
|
337
|
-
std::priority_queue<std::pair<float, size_t>> result
|
338
|
-
|
342
|
+
std::priority_queue<std::pair<float, size_t>> result;
|
343
|
+
try {
|
344
|
+
result = get_hnsw_hierarchicalnsw(self)->searchKnn((void *)vec, (size_t)NUM2INT(k));
|
345
|
+
} catch(const std::runtime_error& e) {
|
346
|
+
ruby_xfree(vec);
|
347
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
348
|
+
return Qnil;
|
349
|
+
}
|
339
350
|
|
340
351
|
ruby_xfree(vec);
|
341
352
|
|
@@ -376,7 +387,21 @@ class RbHnswlibHierarchicalNSW {
|
|
376
387
|
} else {
|
377
388
|
space = RbHnswlibInnerProductSpace::get_hnsw_ipspace(ivspace);
|
378
389
|
}
|
379
|
-
get_hnsw_hierarchicalnsw(self)
|
390
|
+
hnswlib::HierarchicalNSW<float>* index = get_hnsw_hierarchicalnsw(self);
|
391
|
+
if (index->data_level0_memory_) free(index->data_level0_memory_);
|
392
|
+
if (index->linkLists_) {
|
393
|
+
for (hnswlib::tableint i = 0; i < index->cur_element_count; i++) {
|
394
|
+
if (index->element_levels_[i] > 0 && index->linkLists_[i]) free(index->linkLists_[i]);
|
395
|
+
}
|
396
|
+
free(index->linkLists_);
|
397
|
+
}
|
398
|
+
if (index->visited_list_pool_) delete index->visited_list_pool_;
|
399
|
+
try {
|
400
|
+
index->loadIndex(filename, space);
|
401
|
+
} catch(const std::runtime_error& e) {
|
402
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
403
|
+
return Qnil;
|
404
|
+
}
|
380
405
|
RB_GC_GUARD(_filename);
|
381
406
|
return Qnil;
|
382
407
|
};
|
@@ -389,8 +414,9 @@ class RbHnswlibHierarchicalNSW {
|
|
389
414
|
for (size_t i = 0; i < vec.size(); i++) {
|
390
415
|
rb_ary_store(ret, i, DBL2NUM((double)vec[i]));
|
391
416
|
}
|
392
|
-
} catch(std::runtime_error
|
417
|
+
} catch(const std::runtime_error& e) {
|
393
418
|
rb_raise(rb_eRuntimeError, "%s", e.what());
|
419
|
+
return Qnil;
|
394
420
|
}
|
395
421
|
return ret;
|
396
422
|
};
|
@@ -404,7 +430,12 @@ class RbHnswlibHierarchicalNSW {
|
|
404
430
|
};
|
405
431
|
|
406
432
|
static VALUE _hnsw_hierarchicalnsw_mark_deleted(VALUE self, VALUE idx) {
|
407
|
-
|
433
|
+
try {
|
434
|
+
get_hnsw_hierarchicalnsw(self)->markDelete((size_t)NUM2INT(idx));
|
435
|
+
} catch(const std::runtime_error& e) {
|
436
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
437
|
+
return Qnil;
|
438
|
+
}
|
408
439
|
return Qnil;
|
409
440
|
};
|
410
441
|
|
@@ -413,7 +444,12 @@ class RbHnswlibHierarchicalNSW {
|
|
413
444
|
rb_raise(rb_eArgError, "Cannot resize, max element is less than the current number of elements.");
|
414
445
|
return Qnil;
|
415
446
|
}
|
416
|
-
|
447
|
+
try {
|
448
|
+
get_hnsw_hierarchicalnsw(self)->resizeIndex((size_t)NUM2INT(new_max_elements));
|
449
|
+
} catch(const std::runtime_error& e) {
|
450
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
451
|
+
return Qnil;
|
452
|
+
}
|
417
453
|
return Qnil;
|
418
454
|
};
|
419
455
|
|
@@ -510,7 +546,12 @@ class RbHnswlibBruteforceSearch {
|
|
510
546
|
const size_t max_elements = (size_t)NUM2INT(kw_values[1]);
|
511
547
|
|
512
548
|
hnswlib::BruteforceSearch<float>* ptr = get_hnsw_bruteforcesearch(self);
|
513
|
-
|
549
|
+
try {
|
550
|
+
new (ptr) hnswlib::BruteforceSearch<float>(space, max_elements);
|
551
|
+
} catch(const std::runtime_error& e) {
|
552
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
553
|
+
return Qnil;
|
554
|
+
}
|
514
555
|
|
515
556
|
return Qnil;
|
516
557
|
};
|
@@ -538,7 +579,13 @@ class RbHnswlibBruteforceSearch {
|
|
538
579
|
vec[i] = (float)NUM2DBL(rb_ary_entry(arr, i));
|
539
580
|
}
|
540
581
|
|
541
|
-
|
582
|
+
try {
|
583
|
+
get_hnsw_bruteforcesearch(self)->addPoint((void *)vec, (size_t)NUM2INT(idx));
|
584
|
+
} catch(const std::runtime_error& e) {
|
585
|
+
ruby_xfree(vec);
|
586
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
587
|
+
return Qfalse;
|
588
|
+
}
|
542
589
|
|
543
590
|
ruby_xfree(vec);
|
544
591
|
return Qtrue;
|
@@ -609,7 +656,14 @@ class RbHnswlibBruteforceSearch {
|
|
609
656
|
} else {
|
610
657
|
space = RbHnswlibInnerProductSpace::get_hnsw_ipspace(ivspace);
|
611
658
|
}
|
612
|
-
get_hnsw_bruteforcesearch(self)
|
659
|
+
hnswlib::BruteforceSearch<float>* index = get_hnsw_bruteforcesearch(self);
|
660
|
+
if (index->data_) free(index->data_);
|
661
|
+
try {
|
662
|
+
index->loadIndex(filename, space);
|
663
|
+
} catch(const std::runtime_error& e) {
|
664
|
+
rb_raise(rb_eRuntimeError, "%s", e.what());
|
665
|
+
return Qnil;
|
666
|
+
}
|
613
667
|
RB_GC_GUARD(_filename);
|
614
668
|
return Qnil;
|
615
669
|
};
|
data/lib/hnswlib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hnswlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Hnswlib.rb provides Ruby bindings for the Hnswlib.
|
14
14
|
email:
|