yahoojapan / NGT

Nearest Neighbor Search with Neighborhood Graph and Tree for High-dimensional Data
Apache License 2.0
1.22k stars 112 forks source link

Segmentation fault in NGTQG example #118

Closed smanthe closed 2 years ago

smanthe commented 2 years ago

Hi,

thank you for this nice library. I want to test the ngtqg search from this example . Everything works so far until I try to run the search command. It crashes with a segmentation fault on my Ubuntu 20.04 system and also in a Docker container with Ubuntu 22.04. On my Ubuntu 20.04 system I printed the backtrace in GDB in oder to understand what I did wrong:

~/workspace/NGT/build/bin (master)$ gdb /usr/local/bin/ngtqg
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/local/bin/ngtqg...
(gdb) run search -n 20 -e 0.02 onng-40 query.tsv
Starting program: /usr/local/bin/ngtqg search -n 20 -e 0.02 onng-40 query.tsv
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
ngt::command=search
No quantized graph. Construct it temporarily.
indexType=t
size=20
edgeSize=-1
epsilon=0.02<->0.02,0.1

Program received signal SIGSEGV, Segmentation fault.
std::_Bit_reference::operator= (this=0x7fffffffcf80, __x=true) at /usr/include/c++/9/bits/stl_bvector.h:93
93              *_M_p |= _M_mask;
(gdb) bt
#0  std::_Bit_reference::operator= (this=0x7fffffffcf80, __x=true) at /usr/include/c++/9/bits/stl_bvector.h:93
#1  0x00007ffff7e6c407 in NGT::NeighborhoodGraph::setupSeeds (this=0x555555583008, sc=..., seeds=..., results=std::priority_queue wrapping: std::vector of length 10, capacity 16 = {...}, unchecked=std::priority_queue wrapping: std::vector of length 0, capacity 0, distanceChecked=...) at /home/smanthe/workspace/NGT/lib/NGT/Graph.cpp:488
#2  0x00007ffff7ee7f26 in NGTQG::Index::searchQuantizedGraph (this=0x7fffffffda00, graph=..., sc=..., seeds=...) at /home/smanthe/workspace/NGT/lib/NGT/NGTQ/QuantizedGraph.h:218
#3  0x00007ffff7ee8b0c in NGTQG::Index::search (this=0x7fffffffda00, index=..., sc=..., seeds=...) at /home/smanthe/workspace/NGT/lib/NGT/NGTQ/QuantizedGraph.h:358
#4  0x00007ffff7ee8d96 in NGTQG::Index::search (this=0x7fffffffda00, sq=...) at /home/smanthe/workspace/NGT/lib/NGT/NGTQ/QuantizedGraph.h:380
#5  0x00007ffff7f18d8e in search (index=..., searchParameters=..., stream=...) at /home/smanthe/workspace/NGT/lib/NGT/NGTQ/NGTQGCommand.cpp:173
#6  0x00007ffff7f19a2d in NGTQG::Command::search (this=0x7fffffffdb7c, args=...) at /home/smanthe/workspace/NGT/lib/NGT/NGTQ/NGTQGCommand.cpp:246
#7  0x0000555555564c2f in NGTQG::Command::execute (this=0x7fffffffdb7c, args=...) at /home/smanthe/workspace/NGT/lib/NGT/NGTQ/NGTQGCommand.h:116
#8  0x000055555556390e in main (argc=8, argv=0x7fffffffdd58) at /home/smanthe/workspace/NGT/bin/ngtqg/ngtqg.cpp:26

Nevertheless I have no clue what is wrong here. Does someone have any idea?

Thanks in advance.

Best regards, Stephan

masajiro commented 2 years ago

I have released v1.14.6 to fix this issue.

smanthe commented 2 years ago

Now it works. Thanks a lot for the fast help.