Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Wrong kNN similarity score when indexing with dynamic object #287

Closed
meocong opened this issue Dec 27, 2020 · 9 comments
Closed

Wrong kNN similarity score when indexing with dynamic object #287

meocong opened this issue Dec 27, 2020 · 9 comments
Assignees

Comments

@meocong
Copy link

meocong commented Dec 27, 2020

I have a search index which mapping like:
{ "settings" : { "index": { "knn": True, "knn.algo_param.m": 40, "knn.algo_param.ef_search" : 300, "knn.algo_param.ef_construction" : 500, "knn.space_type": "cosinesimil", "sort.field" : "created", "sort.order" : "desc" }, "translog.flush_threshold_size": "10gb" }, "mappings": { "embedding": { "type": "knn_vector", "dimension": embedding_size }, "metadata" : { "type" : "object", "dynamic" : True }, } } }

And I used elasticsearch-py as ES Client
When I index this embed with metadata, the query distance was wrong:
[ 0.037263173609972, -0.018216436728835106, -0.004558993503451347, 0.07959768176078796, 0.07989051192998886, 0.012814756482839584, 0.015803413465619087, 0.08274413645267487, 0.03609683737158775, -0.011350080370903015, -0.0053525823168456554, -0.0305563323199749, -0.06880204379558563, 0.03622889518737793, 0.050995949655771255, -0.025420812889933586, -0.06512117385864258, -0.008494238369166851, -0.019643913954496384, -0.07068609446287155, -0.05977993831038475, 0.04946266859769821, -0.07362569123506546, -0.016564900055527687, -0.08390657603740692, -0.05054805055260658, 0.018434297293424606, -0.03548923879861832, 0.04917234927415848, 0.09585133194923401, 0.015353847295045853, -0.022964736446738243, 0.015726866200566292, 0.010365299880504608, 0.0783892273902893, 0.006507471669465303, -0.04006418585777283, 0.06607645004987717, 0.03665514662861824, -0.03890605643391609, -0.011760648339986801, 0.024083642289042473, -0.009215307421982288, -0.0049561322666704655, 0.006363628897815943, 0.008048318326473236, -0.003745386376976967, 0.02580953948199749, -0.06578125059604645, -0.0370902344584465, -0.003528075758367777, -0.04137365147471428, 0.0012078227009624243, 0.031010087579488754, -0.03667023405432701, 0.026806296780705452, -0.07674309611320496, 0.00774197094142437, 0.026287836953997612, -0.02411346696317196, 0.08144571632146835, -0.03790346533060074, 0.02004757896065712, -0.084548719227314, 0.052061039954423904, 0.002885557012632489, 0.06331291049718857, -0.04129819944500923, 0.004486288409680128, 0.010346610099077225, -0.07399092614650726, -0.010419618338346481, -0.0735739916563034, -0.059170618653297424, -0.06999015063047409, -0.02327519841492176, 0.029682202264666557, -0.09672211855649948, -0.008318258449435234, 0.02668585442006588, 0.0032646527979522943, 0.027273036539554596, -0.0026671600062400103, 0.016971826553344727, -0.012384451925754547, -0.002321461448445916, -0.03354991227388382, -0.07989618182182312, -0.03138858079910278, -0.0693620964884758, -0.030341502279043198, -0.03499758243560791, -0.1026044487953186, -0.022180745378136635, -0.06968171149492264, 0.0682888999581337, 0.05142496898770332, 0.005643143318593502, 0.05277480557560921, -0.07117999345064163, -0.016624780371785164, -0.03883321210741997, 0.0115026431158185, 0.035665541887283325, -0.030561063438653946, 0.05573006346821785, -0.025369727984070778, -0.03573627769947052, 0.0000224998493649764, 0.013213029131293297, 0.01986151933670044, -0.0821150466799736, -0.09211292117834091, 0.034138064831495285, -0.07069820910692215, -0.028749601915478706, 0.07249609380960464, 0.10072050243616104, -0.041241604834795, -0.009322109632194042, 0.1005382388830185, -0.004095138981938362, -0.0687415599822998, -0.06107919290661812, -0.002243657363578677, 0.04815675690770149, -0.03721601516008377, 0.022138940170407295, 0.04392855614423752, -0.08088497817516327, -0.0846010223031044, -0.030622653663158417, -0.005563275422900915, 0.017919771373271942, -0.048754334449768066, 0.0066888947039842606, -0.09707227349281311, -0.03723284602165222, 0.03705482557415962, -0.0032887246925383806, 0.026608433574438095, -0.07832545042037964, -0.030232151970267296, -0.01829528622329235, -0.008502054959535599, -0.006241258233785629, 0.061233039945364, 0.010501914657652378, 0.019421132281422615, 0.04494457691907883, -0.03116494044661522, 0.043408945202827454, -0.0011531219352036715, 0.02074318565428257, 0.08666485548019409, -0.07636262476444244, -0.014165027067065239, -0.040834371000528336, 0.0217592716217041, -0.023645274341106415, 0.02644733525812626, 0.0005355252651497722, -0.004228723701089621, -0.007352218497544527, -0.0816148966550827, -0.015554971992969513, 0.041399143636226654, -0.0070635294541716576, 0.02755082957446575, 0.020663654431700706, 0.044594649225473404, 0.017418280243873596, 0.07084275782108307, -0.04765666276216507, 0.036626994609832764, 0.0932992473244667, 0.03193278983235359, -0.05602934956550598, -0.0316975861787796, -0.03246193379163742, 0.12980471551418304, 0.037086158990859985, 0.0327596440911293, 0.02336449921131134, 0.05759095400571823, 0.0369928702712059, 0.03700479492545128, 0.07754728198051453, -0.0051034907810389996, 0.03087734803557396, -0.017125209793448448, 0.013604028150439262, -0.013344885781407356, 0.006817361805588007, -0.019982032477855682, -0.024375440552830696, 0.0653417706489563, -0.0595424510538578, 0.006447163410484791, -0.01640154793858528, 0.07327067852020264, 0.037511903792619705, 0.049675919115543365, -0.08608879894018173, -0.0063058980740606785, -0.07476097345352173, -0.07401261478662491, -0.047466035932302475, -0.10077552497386932, -0.02367408573627472, -0.0005367286503314972, -0.0017889561131596565, -0.011825595051050186, -0.04959608241915703, -0.031462639570236206, 0.020847303792834282, -0.018933234736323357, -0.03255035728216171, -0.003779577324166894, 0.022511787712574005, 0.0019466469530016184, -0.06070536747574806, 0.06258838623762131, -0.01976674608886242, -0.02440044842660427, 0.060873620212078094, -0.07669112831354141, 0.03522828593850136, -0.05681828036904335, 0.03427561745047569, 0.000996480812318623, -0.021226488053798676, 0.0655045360326767, -0.025221101939678192, -0.011316396296024323, 0.0681799128651619, 0.04621202126145363, -0.025468086823821068, 0.01807475835084915, -0.014386991038918495, 0.0019396488787606359, 0.022886620834469795, -0.0010213210480287671, 0.09730038791894913, -0.030261192470788956, -0.01649407111108303, -0.0004955011536367238, 0.019119255244731903, -0.0002751367283053696, -0.002133734989911318, 0.06518407166004181, 0.009633061476051807, -0.02843107096850872, -0.0005848341970704496, -0.036992479115724564, 0.06501653790473938, 0.09563631564378738, 0.029564382508397102, -0.022941598668694496, 0.003516822587698698, 0.03271457925438881, -0.043424420058727264, -0.05629047378897667, -0.03657449409365654, -0.03431433439254761, 0.036528561264276505, 0.07317173480987549, -0.034036535769701004, -0.0026243675965815783, -0.004585317801684141, -0.047921326011419296, 0.02388872019946575, 0.014465521089732647, 0.014964987523853779, -0.04491099715232849, -0.008873678743839264, -0.015072984620928764, -0.08266056329011917, -0.024171052500605583, 0.009772568009793758, 0.04693647101521492, -0.0011840719962492585, 0.047622550278902054, 0.028842536732554436, -0.030173782259225845, -0.06658226996660233, 0.07248932123184204, -0.05310962349176407, 0.0037100634071975946, -0.060254327952861786, -0.008333781734108925, -0.022807639092206955, -0.05519996955990791, -0.01912641152739525, 0.11623362451791763, -0.01129679661244154, 0.09121367335319519, -0.0013569077709689736, -0.01825873553752899, -0.020371822640299797, 0.010050986893475056, 0.07918893545866013, -0.0012387679889798164, 0.02164320833981037, -0.032633550465106964, -0.02346399985253811, 0.023397177457809448, 0.06182123348116875, -0.009464443661272526, 0.006509842816740274, -0.07694955915212631, -0.07592269033193588, 0.0007434940780512989, -0.0072793010622262955, 0.02915513701736927, -0.004247195553034544, -0.00992619153112173, 0.0030347115825861692, 0.04699843376874924, 0.01044213306158781, 0.052446480840444565, -0.05837160721421242, -0.035101935267448425, -0.07576660066843033, -0.03469289839267731, 0.008993887342512608, 0.014306964352726936, -0.011470116674900055, 0.027155887335538864, 0.08324583619832993, 0.04643924906849861, -0.03518175706267357, 0.041961751878261566, -0.01058282982558012, 0.019319279119372368, 0.043468546122312546, -0.015157409012317657, 0.020989924669265747, -0.046159252524375916, -0.0451599545776844, 0.013490014709532261, -0.08460063487291336, -0.0280591007322073, -0.04157939553260803, 0.06655951589345932, 0.02160792425274849, -0.013536253944039345, 0.0917583703994751, 0.007688938174396753, 0.0231007132679224, -0.016854673624038696, 0.013624290004372597, 0.006390426307916641, 0.005424118600785732, -0.10546944290399551, 0.09586309641599655, -0.009338713251054287, 0.013514471240341663, -0.02974412962794304, 0.024234818294644356, 0.024486232548952103, -0.014278661459684372, 0.027987180277705193, -0.04375944286584854, 0.004171374253928661, 0.01417035423219204, 0.05396703630685806, -0.021581795066595078, -0.03475490212440491, 0.01896699145436287, -0.004528381861746311, 0.033877480775117874, 0.012988225556910038, -0.05597303435206413, -0.013196657411754131, 0.01565122976899147, -0.020526813343167305, 0.020510641857981682, 0.06522854417562485, 0.04313145950436592, 0.07728300243616104, 0.06528604030609131, 0.024234028533101082, -0.010294430889189243, 0.02796143852174282, -0.06863653659820557, 0.005425567738711834, -0.009430808946490288, -0.06748224794864655, -0.037163686007261276, 0.08400656282901764, -0.020388396456837654, 0.02782825566828251, -0.030048519372940063, -0.0019203744595870376, 0.008786785416305065, -0.007551749236881733, 0.044888030737638474, 0.04592861980199814, -0.018768414855003357, -0.010175485163927078, 0.07201039791107178, 0.004107866436243057, 0.04263611510396004, -0.016138747334480286, -0.0338248535990715, -0.0005209784721955657, -0.02509334310889244, 0.04321465268731117, 0.026152735576033592, -0.021030813455581665, -0.0057948376052081585, 0.026956455782055855, -0.00930420309305191, 0.05010760948061943, 0.01766514591872692, -0.06831716001033783, -0.001022274256683886, -0.04230201244354248, -0.014928815886378288, 0.0009295871714130044, -0.0053897700272500515, 0.06458262354135513, -0.07470262050628662, -0.04663756489753723, 0.04411783814430237, -0.025760509073734283, 0.022318126633763313, -0.04192043095827103, 0.04873393476009369, -0.01991807483136654, 0.01309330016374588, 0.029809599742293358, 0.027285540476441383, -0.026769237592816353, 0.025623368099331856, 0.02964669093489647, 0.0715741291642189, -0.02453751675784588, -0.07416415959596634, -0.05215096473693848, -0.05862095579504967, -0.0590754859149456, -0.046479277312755585, 0.10459524393081665, -0.004071772564202547, 0.015310854651033878, -0.016200095415115356, 0.0120016410946846, 0.04025576263666153, -0.0036530806683003902, 0.08738277107477188, -0.02574797160923481, -0.0755753144621849, -0.019789205864071846, -0.07044748961925507, -0.00011256723519181833, -0.022549407556653023, 0.06422507762908936, 0.019166843965649605, -0.021565724164247513, 0.04467006400227547, 0.025970080867409706, 0.0573829710483551, 0.05481162667274475, 0.009486562572419643, 0.02777300588786602, 0.056672558188438416, -0.005245564505457878, 0.03042636625468731, 0.017900820821523666, -0.04296683520078659, -0.027095690369606018, 0.018531011417508125, 0.05217589810490608, 0.03364231809973717, 0.09001708030700684, -0.07102002203464508, -0.0068385060876607895, 0.025189723819494247, -0.007371359039098024, 0.0037070775870233774, 0.03165135905146599, 0.05778880789875984, 0.002834290498867631, -0.002538183471187949, -0.0058490922674536705, 0.018681326881051064, -0.03907618671655655, 0.0582517646253109, 0.05600285530090332, 0.015832429751753807, 0.012576359324157238, 0.03717444837093353, 0.0034582153894007206, -0.027649331837892532, -0.06459272652864456, -0.012780023738741875, -0.04069197177886963, -0.006966845598071814, -0.0360754169523716, 0.039527975022792816, 0.07035267353057861, -0.006098531186580658, 0.017583930864930153, 0.04638461768627167, 0.01916419342160225, -0.011305112391710281, 0.057736944407224655, -0.035676371306180954, 0.08085744827985764, -0.14227783679962158 ]

The query embed:
[ 0.032370831817388535, -0.03377137705683708, -0.021205294877290726, 0.01937955804169178, 0.04269463196396828, 0.026321198791265488, -0.030910944566130638, 0.09882353991270065, -0.0129059674218297, -0.014407685957849026, -0.005836111959069967, -0.036090295761823654, -0.03125961497426033, 0.055144160985946655, -0.011212932877242565, -0.059339430183172226, -0.07777924090623856, 0.05414244532585144, -0.021871352568268776, -0.05836957320570946, 0.007690288592129946, -0.00021521825692616403, -0.02521892823278904, 0.012459928169846535, -0.053102560341358185, -0.01518862135708332, 0.03990304842591286, -0.06103765219449997, 0.012745959684252739, 0.04346402734518051, 0.0024683272931724787, 0.027135515585541725, 0.04369870200753212, 0.028489669784903526, 0.07654868811368942, -0.05477472394704819, 0.02188221551477909, 0.1030707135796547, 0.000633623858448118, -0.01568126678466797, 0.03655052185058594, -0.07107966393232346, -0.042810630053281784, -0.03631829842925072, 0.06299921125173569, 0.015819774940609932, -0.018293213099241257, 0.06889940798282623, -0.07452747970819473, -0.04380883648991585, 0.0013350378721952438, 0.017924822866916656, -0.025409836322069168, 0.050991181284189224, 0.009432629682123661, 0.020999141037464142, -0.03700132668018341, -0.008969602175056934, 0.00834549032151699, -0.019667048007249832, 0.024103496223688126, -0.0039594885893166065, 0.01304396241903305, 0.001124147092923522, 0.046910110861063004, 0.02235879749059677, 0.03417301923036575, -0.03071613982319832, 0.03852314129471779, 0.053606562316417694, -0.0035719166044145823, -0.035536546260118484, -0.03570566326379776, -0.05460083484649658, -0.06561397761106491, -0.03235233947634697, 0.09679611772298813, -0.0454171858727932, -0.024317853152751923, 0.024933690205216408, 0.012158393859863281, 0.022137001156806946, 0.05308643355965614, 0.013510767370462418, -0.03995060548186302, 0.020413098856806755, -0.047375645488500595, -0.05715882405638695, -0.011468225158751011, -0.0817624181509018, -0.021230127662420273, -0.015890849754214287, -0.056490860879421234, -0.009664038196206093, -0.08747082203626633, 0.050294987857341766, 0.03822249174118042, 0.02155919000506401, -0.009845955297350883, -0.08256673067808151, 0.00033363449620082974, -0.04663991183042526, 0.024369530379772186, 0.003612180706113577, 0.06132925674319267, 0.05303915962576866, -0.12457585334777832, -0.10081899911165237, 0.051926616579294205, 0.007657007314264774, -0.030823979526758194, -0.06896104663610458, -0.025806786492466927, 0.05288662016391754, -0.0903901532292366, -0.027344757691025734, 0.06948185712099075, 0.037617865949869156, -0.019564233720302582, -0.04817476123571396, 0.04733259975910187, 0.003937867004424334, -0.020708801224827766, -0.027989884838461876, 0.03729194775223732, 0.060059815645217896, -0.05101514607667923, 0.05904581397771835, 0.0028778465930372477, -0.04913000762462616, -0.051853809505701065, -0.005531279370188713, -0.0090172765776515, 0.021869702264666557, -0.02015826478600502, 0.03470252454280853, 0.025782624259591103, 0.01952282525599003, 0.018776847049593925, 0.04762233793735504, 0.008699771948158741, -0.03855511546134949, -0.11239054799079895, -0.0020155515521764755, 0.06326539069414139, -0.022251365706324577, 0.0689966082572937, 0.009198873303830624, 0.02565649524331093, 0.03870255500078201, 0.025950439274311066, 0.050188206136226654, 0.07110915333032608, 0.08901596814393997, 0.04085028916597366, -0.06832695752382278, 0.04230545088648796, 0.019102459773421288, 0.023758413270115852, -0.013092336244881153, -0.0047188447788357735, -0.014464760199189186, -0.06112737953662872, -0.0637427419424057, -0.040155306458473206, -0.07212163507938385, 0.01154094748198986, 0.0005302979843690991, 0.036223627626895905, 0.028677063062787056, 0.013970088213682175, -0.015618732199072838, 0.05186542496085167, -0.07001528143882751, 0.0167302917689085, 0.015734925866127014, 0.02081962488591671, -0.053455326706171036, -0.0336746871471405, -0.0676112249493599, 0.054354455322027206, -0.01806182973086834, 0.004748019389808178, 0.03003825806081295, 0.031161963939666748, 0.018524352461099625, 0.03638102486729622, 0.05988100543618202, -0.015824640169739723, -0.04698175564408302, 0.027935167774558067, 0.01180102676153183, -0.03072209283709526, -0.007616363000124693, -0.011108366772532463, -0.001881257863715291, 0.09684883803129196, -0.09146302938461304, 0.0014554180670529604, 0.019014466553926468, 0.05464866757392883, 0.012996423058211803, 0.040164314210414886, 0.0124382134526968, 0.016847390681505203, -0.08121922612190247, -0.009141501039266586, 0.008005495183169842, 0.004357794765383005, 0.01058402843773365, -0.007101020775735378, 0.029230523854494095, 0.07149556279182434, -0.03354915976524353, -0.00820765271782875, -0.004801284987479448, -0.06377096474170685, 0.033168449997901917, -0.051150623708963394, 0.035243794322013855, -0.059607166796922684, -0.0423770509660244, 0.04688834771513939, -0.0696265697479248, -0.06722665578126907, 0.07022532820701599, -0.015169396065175533, 0.004968315362930298, -0.04826939478516579, 0.026842758059501648, -0.06535325944423676, 0.035284996032714844, 0.05495170131325722, -0.0653470978140831, 0.03408331796526909, 0.03284178301692009, 0.04318161681294441, -0.06174468249082565, 0.00808134488761425, 0.0974450632929802, 0.0069821602664887905, 0.001521683414466679, 0.007908585481345654, 0.049708351492881775, -0.019872555509209633, -0.004471758846193552, -0.03641873970627785, 0.034750763326883316, -0.05857580155134201, 0.015943914651870728, 0.04395651817321777, 0.031937241554260254, -0.04082052782177925, 0.03949163109064102, -0.03101036697626114, 0.06517139077186584, 0.06269712746143341, 0.050933536142110825, -0.0059241000562906265, 0.010587767697870731, -0.015881003811955452, -0.006684933323413134, -0.041199080646038055, -0.0452922061085701, -0.08550628274679184, 0.01345175039023161, 0.08117372542619705, -0.030118227005004883, 0.009642491117119789, 0.02148156426846981, -0.047597482800483704, 0.07137567549943924, 0.0435938723385334, -0.017646659165620804, -0.07099169492721558, -0.07175929844379425, -0.03732408583164215, -0.008531048893928528, -0.007910783402621746, -0.019845712929964066, -0.004094064701348543, -0.06507646292448044, -0.005921058356761932, -0.003286015707999468, 0.00012264611723367125, -0.040247298777103424, -0.015603075735270977, -0.04310672730207443, 0.014500788412988186, -0.05126124620437622, -0.06287256628274918, 0.03325897827744484, -0.031159693375229836, -0.03480363264679909, 0.09539687633514404, -0.003530657384544611, 0.002237466163933277, 0.05531422421336174, 0.008303540758788586, 0.008939812891185284, 0.027225453406572342, 0.04219437763094902, -0.056823864579200745, 0.0013061758363619447, -0.01022765226662159, 0.01212119497358799, 0.007484812289476395, -0.04854108765721321, 0.004220195114612579, 0.029519097879529, -0.0614142082631588, -0.019284449517726898, 0.015486892312765121, -0.019980594515800476, 0.03260516747832298, -0.033684518188238144, 0.040840886533260345, -0.035466209053993225, 0.09460732340812683, -0.0402718260884285, -0.00831831805408001, -0.03939379006624222, -0.008426407352089882, 0.009424381889402866, 0.008064213208854198, 0.01668349653482437, 0.049861762672662735, -0.01004786230623722, 0.010255593806505203, 0.04829106852412224, 0.0052644601091742516, -0.045940712094306946, 0.02319081500172615, 0.013385450467467308, 0.00732497638091445, 0.0700044184923172, 0.04605413228273392, -0.018734805285930634, 0.009223074652254581, -0.03100014664232731, -0.02870279736816883, -0.015247291885316372, -0.029831625521183014, -0.05114094913005829, 0.012598787434399128, 0.023610176518559456, 0.08830961585044861, 0.04534866660833359, -0.04009425267577171, -0.04665980860590935, 0.003305786056444049, 0.059080954641103745, -0.043850820511579514, 0.05889350175857544, -0.1139133870601654, 0.0918339192867279, 0.012981852516531944, 0.07707061618566513, -0.051220353692770004, 0.022995999082922935, 0.020639518275856972, 0.0805780366063118, 0.0033798357471823692, -0.008540786802768707, 0.019759267568588257, 0.0071108401753008366, -0.03743661940097809, 0.015474332496523857, 0.0006796361412853003, 0.07536649703979492, -0.016332507133483887, 0.04991329833865166, -0.04814603552222252, 0.017385156825184822, 0.013304677791893482, 0.010025611147284508, -0.03210652992129326, 0.05752558261156082, 0.0191153883934021, -0.011561200954020023, 0.0387858971953392, 0.014909974299371243, 0.012330884113907814, 0.02290995419025421, 0.0326695442199707, 0.006424613296985626, -0.016490833833813667, -0.05990185961127281, -0.08637622743844986, -0.0033870995976030827, 0.003682096255943179, -0.03809376433491707, 0.05920565128326416, 0.02741917595267296, -0.018870141357183456, -0.03793351724743843, -0.051086850464344025, 0.0035757783334702253, 0.06172250583767891, -0.041698116809129715, 0.024368535727262497, 0.11668334156274796, -0.009570460766553879, -0.008375450037419796, -0.03773447126150131, -0.09455733001232147, 0.009474764578044415, 0.00694293063133955, -0.02730422094464302, 0.0910031646490097, -0.006402932573109865, -0.0011898442171514034, 0.019365616142749786, -0.03436144441366196, -0.023847395554184914, 0.05975084379315376, -0.00041146812145598233, -0.009023168124258518, -0.07868200540542603, 0.025424718856811523, -0.04806781932711601, -0.02637501060962677, 0.061930153518915176, -0.10042908042669296, -0.01775226555764675, 0.04256825149059296, 0.017247984185814857, 0.009917188435792923, -0.07308360934257507, 0.026912232860922813, -0.03817182406783104, 0.08270321041345596, 0.05357053875923157, 0.05925304815173149, 0.07573410123586655, 0.09990694373846054, 0.06552378833293915, 0.03791278228163719, -0.04279882833361626, -0.08994870632886887, -0.0038558857049793005, -0.042919058352708817, 0.002153335837647319, -0.006853328552097082, 0.09576518833637238, -0.02844860590994358, -0.02967027761042118, 0.05562229081988335, 0.06757520884275436, 0.0073522902093827724, 0.031454551964998245, 0.14728878438472748, -0.0038865895476192236, -0.08905111253261566, -0.022430287674069405, -0.05238676071166992, 0.01058166939765215, -0.006726799067109823, 0.07050933688879013, 0.015486595220863819, -0.003162241540849209, -0.021724846214056015, 0.03597573935985565, 0.0572783425450325, 0.04346407204866409, 0.004834870807826519, -0.00998721458017826, 0.10255321115255356, -0.04348938912153244, -0.0017877811333164573, -0.02068762667477131, -0.029348749667406082, -0.026827631518244743, 0.003076134482398629, -0.05056048929691315, -0.016289329156279564, 0.09072903543710709, -0.0065864985808730125, 0.021226070821285248, 0.031206030398607254, -0.01145165041089058, 0.01676655374467373, -0.03906470537185669, 0.02626493200659752, -0.029049823060631752, -0.055395424365997314, -0.014146389439702034, 0.03601466491818428, 0.04094002768397331, 0.03970395028591156, 0.010246777907013893, 0.0167248472571373, 0.013710962608456612, 0.0004450533597264439, -0.029919857159256935, -0.04874173551797867, -0.0568200908601284, 0.03749905526638031, 0.024120813235640526, 0.02150309644639492, -0.01054674107581377, 0.02939278446137905, 0.09899700433015823, 0.038911305367946625, -0.00699472613632679, 0.01337258517742157, -0.023821717128157616, 0.0006470513180829585, 0.030013667419552803, -0.00904859323054552, 0.08600936084985733, -0.10576676577329636 ]

The result:
With dynamic=True metadata object: "similarity": 0.5550214
With dynamic=False metadata object: "similarity": 0.71384406

How can I fix this, or it's ODFE's problem, can you check, thank you for your help!

@meocong
Copy link
Author

meocong commented Dec 27, 2020

@jmazanec15 Can you take some time to check this issue, because I think it's critical.

@meocong meocong changed the title Wrong kNN value when indexing with dynamic object Wrong kNN similarity score when indexing with dynamic object Dec 28, 2020
@jmazanec15
Copy link
Member

Hi @meocong, thanks for posting. It appears that when dynamic is set to True, it calculates the l2 distance (1/(1+euclidean^2)); when dynamic is set to False it calculates cosine.

We are having a similar discussion in the forums here: https://discuss.opendistrocommunity.dev/t/cosine-similarity-formula/4390/14.

I will take a closer look at this problem with the dynamic field in metadata and see if its related. I will update this issue when I find something.

@meocong
Copy link
Author

meocong commented Dec 29, 2020

@jmazanec15 Thank you for your quick reply, I know that it's holiday now but I am applying ODFE into Production, so hopefully you can debug it soon.

@jmazanec15
Copy link
Member

jmazanec15 commented Dec 29, 2020

Hi @meocong,

Verified that this bug has same root cause as https://discuss.opendistrocommunity.dev/t/cosine-similarity-formula/4390/14.

Here are reproduction steps:

curl -X PUT "localhost:9200/myindex" -H 'Content-Type: application/json' -d'
{
  "settings" : {
      "index": {
        "knn": "true",
        "knn.space_type": "cosinesimil"
      }
  },
  "mappings": {
    "properties": {
      "embedding": {
        "type": "knn_vector",
        "dimension": 2
      },
      "metadata" : {
        "type" : "object",
        "dynamic" : true
      }
    }
  }
}
'

curl -X POST "localhost:9200/myindex/_doc" -H 'Content-Type: application/json' -d'
{
  "metadata": {"test": "object"},
  "embedding":  [1, 2]
}
'

curl -X POST "localhost:9200/myindex/_search" -H 'Content-Type: application/json' -d'
{
  "size" : 1,
  "query": {
    "knn": {
      "embedding": {
        "vector": [3, 4],
        "k": 1
      }
    }
  }
}
'
{"took":4,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":0.26120389,"hits":[{"_index":"myindex","_type":"_doc","_id":"v7XLr3YBIf7zL2czQtly","_score":0.26120389,"_source":
{
  "metadata": {"test": "object"},
  "embedding":  [1, 2]
}
}]}}

The score returned is Euclidean: 1/(1 + sqrt((3-1)^2 + (4-2)^2)) = 0.26.

Making this change fixes the issue:

curl -X POST "localhost:9200/myindex/_search" -H 'Content-Type: application/json' -d'
{
  "size" : 1,
  "query": {
    "knn": {
      "embedding": {
        "vector": [3, 4],
        "k": 1
      }
    }
  }
}
'

{"took":87,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":0.984126,"hits":[{"_index":"myindex","_type":"_doc","_id":"O_fNr3YB8wZdPbAJ4nrv","_score":0.984126,"_source":
{
  "metadata": {"test": "object"},
  "embedding":  [1, 2]
}

I will submit a PR to fix this today. We will backport changes to older branches where this bug is present.

What ODFE version and artifact type (Docker, Deb, RPM, TAR, ...) are you using?

@meocong
Copy link
Author

meocong commented Dec 30, 2020

@jmazanec15 I am having this bug on versions 1.11.0 and 1.12.0 with docker image amazon/opendistro-for-elasticsearch
Thank you for your hardworking, hope it comes to 1.12.1 soon

@jmazanec15
Copy link
Member

Hi @meocong, apologies for the delay. Unfortunately, we will not release a 1.12.1 Docker image with the patch.

As a workaround, you can build the patch into a custom Docker image with the following Dockerfile:

FROM amazon/opendistro-for-elasticsearch:1.12.0
RUN yum -y update \
    && yum install -y git \
    && yum clean all \
    && rm -rf /tmp/plugins \
    && mkdir /tmp/plugins \
    && git clone --recursive --branch opendistro-1.12 https://github.com/opendistro-for-elasticsearch/k-NN.git /usr/share/elasticsearch/k-NN \
    && cd /usr/share/elasticsearch/k-NN \
    && ./gradlew build -x integTest -x test -x jacocoTestReport \
    && cp build/distributions/opendistro-knn-1.12.0.0.zip /tmp/plugins/ \
    && rm -rf /usr/share/elasticsearch/k-NN \
    && yum remove git -y && yum clean all -y

WORKDIR /usr/share/elasticsearch

RUN elasticsearch-plugin remove opendistro-knn \
  && elasticsearch-plugin install --batch file:/tmp/plugins/opendistro-knn-1.12.0.0.zip

Running docker build --tag=odfe-1.12-knn-patch . will build it (assuming you are in the same directory as the Dockerfile).

@meocong
Copy link
Author

meocong commented Jan 14, 2021

@jmazanec15 I am really appreciate your work, I tested and I worked. Hope that the new version is coming soon.

@marcoaleixo
Copy link

When this fix will be available in the AWS Elasticsearch?
Sorry if you guys aren't related directly to AWS services.

@vamshin
Copy link
Member

vamshin commented Jan 27, 2021

@marcoaleixo this fix would be available on AWS Elasticsearch around Feb15th as part of software update. If you need assistance with fix immediately or any other help, please feel free to cut support ticket to AWS Elasticsearch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants