hnswlib 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/ext/hnswlib/hnswlibext.hpp +21 -9
- data/ext/hnswlib/src/bruteforce.h +5 -1
- data/ext/hnswlib/src/hnswalg.h +8 -7
- 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: 293c9038e57db28357f77c753988b593ef921a2d8caf7234f4a547547580f2cb
|
4
|
+
data.tar.gz: 668eba08220e29d970f886b91382a335834ac746d9a208d9add986f2ff21fbfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a748a2d3f8291453221b60b55f184b152f56aa35ec5a0830d7b6c6f82adb90e09d757737f0b0527e3404f30c61d7da7f8567c1a7d087045fada991e6152a333
|
7
|
+
data.tar.gz: 4f5fbf6a8b14e4179862f3e9030bf8e08fa971e874e518141261e2f83942fdb96b68217adcb0dbd2a26b12b5684ef7b645fd7b7fa8025b03fc6e08694a14d9c9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.6.1] - 2022-04-30
|
2
|
+
|
3
|
+
- Change the `search_knn` method of `BruteforceSearch` to output warning message instead of rasing RuntimeError
|
4
|
+
when the number of search results is less than the requested number of neighbors.
|
5
|
+
- Fix to raise RuntimeError when failing to open file on the `load_index` method of `BruteforceSearch`.
|
6
|
+
- Add guard to not free unallocated memory space.
|
7
|
+
|
1
8
|
## [0.6.0] - 2022-04-16
|
2
9
|
|
3
10
|
**Breaking change:**
|
data/ext/hnswlib/hnswlibext.hpp
CHANGED
@@ -366,14 +366,24 @@ private:
|
|
366
366
|
space = RbHnswlibInnerProductSpace::get_hnsw_ipspace(ivspace);
|
367
367
|
}
|
368
368
|
hnswlib::HierarchicalNSW<float>* index = get_hnsw_hierarchicalnsw(self);
|
369
|
-
if (index->data_level0_memory_)
|
369
|
+
if (index->data_level0_memory_) {
|
370
|
+
free(index->data_level0_memory_);
|
371
|
+
index->data_level0_memory_ = nullptr;
|
372
|
+
}
|
370
373
|
if (index->linkLists_) {
|
371
374
|
for (hnswlib::tableint i = 0; i < index->cur_element_count; i++) {
|
372
|
-
if (index->element_levels_[i] > 0 && index->linkLists_[i])
|
375
|
+
if (index->element_levels_[i] > 0 && index->linkLists_[i]) {
|
376
|
+
free(index->linkLists_[i]);
|
377
|
+
index->linkLists_[i] = nullptr;
|
378
|
+
}
|
373
379
|
}
|
374
380
|
free(index->linkLists_);
|
381
|
+
index->linkLists_ = nullptr;
|
382
|
+
}
|
383
|
+
if (index->visited_list_pool_) {
|
384
|
+
delete index->visited_list_pool_;
|
385
|
+
index->visited_list_pool_ = nullptr;
|
375
386
|
}
|
376
|
-
if (index->visited_list_pool_) delete index->visited_list_pool_;
|
377
387
|
try {
|
378
388
|
index->loadIndex(filename, space);
|
379
389
|
} catch (const std::runtime_error& e) {
|
@@ -590,17 +600,16 @@ private:
|
|
590
600
|
ruby_xfree(vec);
|
591
601
|
|
592
602
|
if (result.size() != (size_t)NUM2INT(k)) {
|
593
|
-
|
594
|
-
return Qnil;
|
603
|
+
rb_warning("Cannot return as many search results as the requested number of neighbors.");
|
595
604
|
}
|
596
605
|
|
597
606
|
VALUE distances_arr = rb_ary_new2(result.size());
|
598
607
|
VALUE neighbors_arr = rb_ary_new2(result.size());
|
599
608
|
|
600
|
-
|
609
|
+
while (!result.empty()) {
|
601
610
|
const std::pair<float, size_t>& result_tuple = result.top();
|
602
|
-
|
603
|
-
|
611
|
+
rb_ary_unshift(distances_arr, DBL2NUM((double)result_tuple.first));
|
612
|
+
rb_ary_unshift(neighbors_arr, INT2NUM((int)result_tuple.second));
|
604
613
|
result.pop();
|
605
614
|
}
|
606
615
|
|
@@ -627,7 +636,10 @@ private:
|
|
627
636
|
space = RbHnswlibInnerProductSpace::get_hnsw_ipspace(ivspace);
|
628
637
|
}
|
629
638
|
hnswlib::BruteforceSearch<float>* index = get_hnsw_bruteforcesearch(self);
|
630
|
-
if (index->data_)
|
639
|
+
if (index->data_) {
|
640
|
+
free(index->data_);
|
641
|
+
index->data_ = nullptr;
|
642
|
+
}
|
631
643
|
try {
|
632
644
|
index->loadIndex(filename, space);
|
633
645
|
} catch (const std::runtime_error& e) {
|
@@ -29,7 +29,7 @@ namespace hnswlib {
|
|
29
29
|
}
|
30
30
|
|
31
31
|
~BruteforceSearch() {
|
32
|
-
free(data_);
|
32
|
+
if (data_) free(data_);
|
33
33
|
}
|
34
34
|
|
35
35
|
char *data_;
|
@@ -129,6 +129,10 @@ namespace hnswlib {
|
|
129
129
|
|
130
130
|
|
131
131
|
std::ifstream input(location, std::ios::binary);
|
132
|
+
|
133
|
+
if (!input.is_open())
|
134
|
+
throw std::runtime_error("Cannot open file");
|
135
|
+
|
132
136
|
std::streampos position;
|
133
137
|
|
134
138
|
readBinaryPOD(input, maxelements_);
|
data/ext/hnswlib/src/hnswalg.h
CHANGED
@@ -76,14 +76,15 @@ namespace hnswlib {
|
|
76
76
|
};
|
77
77
|
|
78
78
|
~HierarchicalNSW() {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
if (data_level0_memory_) free(data_level0_memory_);
|
80
|
+
if (linkLists_) {
|
81
|
+
for (tableint i = 0; i < cur_element_count; i++) {
|
82
|
+
if (element_levels_[i] > 0)
|
83
|
+
if (linkLists_[i]) free(linkLists_[i]);
|
84
|
+
}
|
85
|
+
free(linkLists_);
|
84
86
|
}
|
85
|
-
|
86
|
-
delete visited_list_pool_;
|
87
|
+
if (visited_list_pool_) delete visited_list_pool_;
|
87
88
|
}
|
88
89
|
|
89
90
|
size_t max_elements_;
|
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Hnswlib.rb provides Ruby bindings for the Hnswlib.
|
14
14
|
email:
|