microsoft / SPTAG

A distributed approximate nearest neighborhood search (ANN) library which provides a high quality vector index build, search and distributed online serving toolkits for large scale vector search scenario.
MIT License
4.8k stars 582 forks source link

Encoding issues in output of search #45

Open shanepeckham opened 5 years ago

shanepeckham commented 5 years ago

Describe the bug Bad encoding in output of search

To Reproduce Steps to reproduce the behavior:

  1. Build an index with algorithm BKT using the cli
  2. Build a search using a cli
  3. Open output file of search
  4. Contains bad encoding part way through the file

Expected behavior Consistent encoding throughout the results

Output Melanoma:0.680@1807.00273v1.Photorealistic_Style_Transfer_for_Videos.pdf|1.005@^_O�:�^B�>�|1807.00273v1.Photorealistic_Style_Transfer_for_Videos.pdf��?�<:i��v3~Y�$��<�n)8^\��=�J^R<J^?�<~@hW���~K;~L~V^A�~FO~U;�^?

Desktop (please complete the following information):

CloudBreadPaPa commented 5 years ago

same result from my side. looks like a bug of search with metadata.

repro steps. copy attached _queryembeddings.txt and _titleembeddings.txt file. These're 2048d vector with simple metadata file.

Run below commands and check results.txt file.

./indexbuilder -d 2048 -v Float -i ../shane-test/query_embeddings.txt -o ../output3 -a BKT 

./indexsearcher ../output3 Index.QueryFile=../shane-test/title_embeddings.txt Index.ResultFile=../output3/results.txt Index.K=2

First line of first prediction looks okay but next, errors. the broken text, it should be t2 metadata name value but might be some encoding? or text printing issues on it.

results.txt file text

m1:0.680@t1|0.998@`�|
m2:0.654@��|0.973@`�|
m3:0.719@��|0.980@`�|
m4:0.753@��|0.978@`�|
m5:0.707@��|0.994@`�|
m6:0.696@��|1.001@`�|
m7:0.755@��|0.985@`�|
m8:0.720@��|1.002@`�|
m9:0.833@��|0.975@`�|
m10:0.723@��|1.000@`�|
m11:0.680@��|0.998@`�|
m12:0.654@��|0.973@`�|
m13:0.719@��|0.980@`�|
m14:0.753@��|0.978@`�|
m15:0.707@��|0.994@`�|
m16:0.696@��|1.001@`�|
m17:0.755@��|0.985@`�|
m18:0.720@��|1.002@`�|
m19:0.833@��|0.975@`�|
m20:0.723@��|1.000@`�|

attaching the test files.

SPTAG-result-with-metadata.zip

MaJaHa95 commented 5 years ago

I spent a bit of time debugging this the other day, and seemed to find that inserting elements one at a time (using AddIndex) resolved it. Relatively slow, but maybe that's a hint toward what might be at play?

lambday commented 5 years ago

Faced the same issue on Windows. I was trying with dummy vectors of dimension 10.

  1. Here's the input file to the index builder executable (target.txt).
    hello   100|101|103|104|105|106|107|108|109|110
    hullo   99|100|101|103|104|105|106|107|108|109
    hola    85|86|87|88|89|90|91|92|93|94
    hi  120|121|122|123|124|125|126|127|119|118
    what's up   -10|-11|-12|-13|-14|-15|-16|-17|-18|-19
  2. Ran index builder
    indexbuilder.exe -d 10 -v float -i D:\path\to\data\target.txt -o D:\path\to\data\gen -a BKT Index.DistCalcMethod=Cosine
  3. My search input file (source.txt)
    this    -120|-121|-122|-123|-124|-125|-126|-127|-128|-129
    magnificiant    250|251|252|253|254|255|256|257|258|259
    helloo  101|102|103|104|105|106|107|108|109|120
    hwllo   98|99|100|101|102|103|104|105|106|107
    search  1|2|3|4|5|6|7|8|9|10
  4. Ran index search
    indexsearcher.exe D:\path\to\data\gen Index.QueryFile=D:\path\to\data\source.txt Index.ResultFile=D:\path\to\data\gen\result.txt Index.K=4
  5. Content of result.txt
    this:2.000@  ðÂC|2.000@C   |2.000@C |2.000@¸$P}÷   |
    magnificiant:0.000@C    |0.000@l e |0.000@C |0.000@         |
    helloo:0.000@    C|0.001@    C|0.001@C   |0.001@ |
    hwllo:0.000@C Åî|0.000@    C|0.000@C   |0.000@ |
    search:0.100@  ðÂC|0.114@C    |0.114@C   |0.114@C |

    I don't know what to make of it. Any help is appreciated.

lambday commented 5 years ago

Okay not sure how much it helps, but this is something I tried with the index searcher.

  1. Removed the if (...) thing here and the else block. So this is how it looks in my local

    for (int j = 0; j < K; j++)
    {
     //if (results[i].GetResult(j)->VID < 0) {
         fp << results[i].GetResult(j)->Dist << "@" << results[i].GetResult(j)->VID; // << std::endl;
     //}
     /*else {
         ByteArray vm = index.GetMetadata(results[i].GetResult(j)->VID);
         fp << (results[i].GetResult(j)->Dist / basesquare) << "@";
         fp.write((const char*)vm.Data(), vm.Length());
     }*/
    fp << "|";
    }
  2. Increased the precision here to 6 (since the distance is float32_t so we can't get better than that).

  3. Output file:

    this:1.999734@1|1.999734@2|1.999734@3|1.999734@4|
    magnificiant:0.000064@1|0.000064@2|0.000064@3|0.000064@4|
    helloo:0.000382@0|0.001155@1|0.001155@2|0.001155@3|
    hwllo:0.000005@0|0.000392@1|0.000392@2|0.000392@3|
    search:0.100150@0|0.113595@1|0.113595@2|0.113595@3|