Open xansrnitu opened 9 months ago
Can you please provide a minimal reproducible example which includes create table
, insert into
and your search query. E.g. like this:
➜ ~ mysql -P9306 -h0
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23358
Server version: 6.2.13 267b05c3a@24012222 dev (columnar 2.2.5 1d1e432@231204) (secondary 2.2.5 1d1e432@231204) (knn 2.2.5 1d1e432@231204) git branch master...origin/master
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create table test ( title text, image_vector float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='l2' );
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test values ( 1, 'yellow bag', (0.653448,0.192478,0.017971,0.339821) ), ( 2, 'white bag', (-0.148894,0.748278,0.091892,-0.095406) );
Query OK, 2 rows affected (0.01 sec)
mysql> select title, knn_dist() from test where knn ( image_vector, 5, (0.286569,-0.031816,0.066684,0.032926) );
+------------+------------+
| title | knn_dist() |
+------------+------------+
| yellow bag | 0.28146550 |
| white bag | 0.81527930 |
+------------+------------+
2 rows in set (0.00 sec)
--- 2 out of 2 results in 0ms ---
Sure. Here it is -
mysql> create table test_table (content text, content_vector float_vector knn_type='hnsw' knn_dims='384' hnsw_similarity='cosine'); Query OK, 0 rows affected (0.00 sec)
insertion sql -
insert into test_table values ( 1, 'The capital city of Uttar Pradesh is Lucknow.',(0.06482091546058655, 0.04992128536105156, -0.03429781645536423, 0.026320653036236763, -0.009687593206763268, 0.01179866399616003, 0.004409298300743103, -0.01785661093890667, -0.09590322524309158, -0.01006210409104824, 0.016009870916604996, -0.12434668838977814, -0.020932624116539955, -0.06882227957248688, 0.020757293328642845, -0.0025973336305469275, 0.09881345927715302, 0.0019554374739527702, 0.08176830410957336, -0.1057162657380104, -0.07408052682876587, -0.026800718158483505, 0.0510084368288517, -0.02934758923947811, 0.04715917631983757, 0.030601687729358673, 0.0002789408026728779, -0.008580046705901623, 0.012862227857112885, -0.05232050269842148, 0.1114281564950943, -0.01832321472465992, -0.010838007554411888, -0.025491593405604362, -0.05287948623299599, 0.07078016549348831, -0.018588192760944366, 0.005674791522324085, 0.12451225519180298, -0.04396867752075195, 0.11632400751113892, 0.04034367948770523, -0.02234485000371933, -0.05281723290681839, 0.03560516983270645, -0.009733027778565884, 0.016981204971671104, -0.01904718205332756, -0.0221172496676445, -0.04327552765607834, 0.029408074915409088, -0.05015785992145538, -0.029000280424952507, -0.0627661794424057, -0.017665142193436623, -0.06745558232069016, 0.04562167823314667, 0.025913843885064125, -0.05845576897263527, 0.023129232227802277, -0.06782524287700653, 0.05111556127667427, 0.0176242608577013, 0.0460895337164402, 0.024225136265158653, -0.02694002166390419, 0.029928192496299744, -0.016062170267105103, 0.016708480194211006, -0.06875284761190414, -0.020549483597278595, 0.025116391479969025, 0.026381734758615494, -0.058338094502687454, -0.05094703286886215, -0.05185637250542641, 0.010776680894196033, 0.028104711323976517, 0.06571896374225616, 0.0220874585211277, -0.08572608232498169, -0.011421817354857922, -0.006878388114273548, 0.0189790241420269, -0.06547429412603378, 0.026981202885508537, -0.05079017952084541, -0.017946884036064148, -0.055698949843645096, -0.048960939049720764, 0.03902903199195862, 0.04179072007536888, -0.027790479362010956, 0.025074973702430725, -0.025060545653104782, 0.04205888509750366, -0.039338912814855576, -0.04142407327890396, -0.01233632117509842, 0.00653756782412529, -0.05161905288696289, 0.0025052870623767376, -0.033369772136211395, 0.02182653546333313, -0.03213304281234741, -0.0036571144592016935, -0.042951490730047226, -0.0277724452316761, -0.033435773104429245, -0.005305944941937923, 0.018029607832431793, 0.037417396903038025, 0.017181238159537315, 0.02643471583724022, 0.01194708701223135, 0.09099791198968887, -0.029966114088892937, -0.013841962441802025, -0.049566373229026794, -0.035440512001514435, -0.11595731973648071, -0.03921404480934143, -0.022447023540735245, 0.01697845570743084, -0.0619276687502861, -0.11142934113740921, -0.03916054964065552, -6.078577899044007e-33, -0.029456527903676033, -0.046578045934438705, 0.03768320381641388, 0.004133111797273159, -0.06685203313827515, -0.03763018175959587, 0.044151581823825836, -0.05346596986055374, -0.027279887348413467, -0.004606899805366993, 0.01321921031922102, -0.1368519514799118, 0.05520038679242134, -0.011957261711359024, 0.08951473981142044, -0.028361095115542412, 0.041944604367017746, 0.018210548907518387, -0.04884594678878784, 0.0072183613665401936, -0.043671734631061554, -0.03750285878777504, -0.0717604011297226, -0.08534064143896103, -0.028280073776841164, -0.004378854297101498, 0.03288616985082626, 0.09250205755233765, 0.040987417101860046, 0.0011889026500284672, 0.056012142449617386, 0.09130873531103134, -0.024854809045791626, 0.053032826632261276, -0.03173600509762764, 0.03463532030582428, -0.01169117446988821, -0.0274259801954031, -0.05220950022339821, -0.0008523532887920737, -0.053598616272211075, 0.03822256624698639, -0.0006149214459583163, -0.03490142524242401, -0.031777072697877884, 0.06556002050638199, -0.006123066414147615, 0.0022767113987356424, 0.03809332847595215, -0.043361734598875046, -0.041438959538936615, 0.011960203759372234, 0.04021666944026947, 0.01709781400859356, 0.029787326231598854, 0.031030690297484398, -0.07112845778465271, 0.008569818921387196, 0.05839313939213753, 0.15410208702087402, -0.003681182861328125, -0.021215083077549934, -0.08402945101261139, 0.027156515046954155, -0.027800381183624268, -0.023969663307070732, 0.0699777901172638, -0.016330868005752563, 0.048132024705410004, 0.07959488779306412, 0.0451931431889534, 0.013464187271893024, -0.0003824577433988452, 0.07180611044168472, -0.052828725427389145, 0.025036051869392395, 0.0062473611906170845, 0.008519499562680721, -0.043585117906332016, 0.05220074579119682, 0.05215125530958176, 0.04888764023780823, -0.047547779977321625, -0.08879595249891281, 0.15181465446949005, -0.05074972286820412, -0.01668126881122589, -0.027455739676952362, -0.04654162749648094, -0.02620253898203373, 0.008067038841545582, 0.018032681196928024, 0.01002639438956976, 0.023883264511823654, 0.006333629135042429, 1.3369413367390284e-33, 0.06534791737794876, -0.026056397706270218, -0.0809331014752388, -0.05019157752394676, -0.04701877385377884, 0.042431265115737915, 0.12461554259061813, -0.01780806854367256, -0.050303295254707336, 0.05757782980799675, -0.046190258115530014, 0.035705044865608215, 0.040408920496702194, -0.021427027881145477, 0.0735001340508461, 0.011265089735388756, 0.011742585338652134, 0.02631988935172558, -0.06628582626581192, 0.02132044918835163, -0.07101915031671524, 0.03078136406838894, -0.1538163721561432, -0.06546951085329056, 0.026620905846357346, -0.051242876797914505, -0.1617601364850998, -0.0024413953069597483, -0.06519318372011185, -0.03859483450651169, 0.012186173349618912, -0.06914299726486206, -0.12480893731117249, 0.09702786058187485, 0.02642073854804039, -0.02139950357377529, 0.05911185219883919, -0.07446742057800293, 0.045271314680576324, 0.03199991211295128, -0.04724122956395149, 0.06467762589454651, 0.06257136166095734, 0.08647197484970093, 0.06417220085859299, 0.003292545210570097, -0.040703870356082916, 0.023571981117129326, -0.025455843657255173, 0.05741902440786362, 0.00038647011388093233, -0.05743066966533661, 0.04087774455547333, 0.02584318071603775, 0.06117433309555054, 0.08033672720193863, 0.007273032795637846, 0.06303175538778305, -0.03102913685142994, -0.10810790210962296, 0.01722388155758381, -0.0249248705804348, 0.009433611296117306, 0.07658936828374863, -0.08852456510066986, 0.009506282396614552, 0.02306794933974743, -0.06006643548607826, 0.048894573003053665, -0.014441486448049545, 0.04875165969133377, 0.007772950921207666, -0.05729253217577934, 0.008025131188333035, -0.07494957000017166, 0.0476347841322422, 0.03379659727215767, 0.09253711253404617, 0.016099708154797554, -0.027535472065210342, 0.1291743665933609, 0.0741562768816948, 0.028188351541757584, -0.07637868821620941, 0.011635500937700272, 0.04068224877119064, 0.0266109649091959, -0.02422288991510868, 0.029400186613202095, -0.05802464112639427, 0.031234342604875565, 0.01683625765144825, 0.01809609681367874, -0.017968276515603065, 0.04509495571255684, -2.2079850836576043e-08, -0.016516827046871185, -0.044284213334321976, -0.04216821491718292, 0.03774471953511238, 0.0072920434176921844, 0.0436013787984848, 0.016658512875437737, -0.04157709330320358, -0.04154917970299721, 0.004683543927967548, -0.012803655117750168, -0.018749674782156944, -0.0506889708340168, 0.01217014342546463, -0.04210936278104782, -0.023202205076813698, 0.007226691115647554, 0.015686262398958206, 0.03178316727280617, -0.028077714145183563, -0.05697041377425194, -0.0076336548663675785, -0.004964582622051239, 0.06090867519378662, 0.020856687799096107, -0.00793258287012577, 0.014063490554690361, -0.05261142551898956, 0.0633118525147438, 0.01638849265873432, 0.020914021879434586, 0.03007942996919155, 0.06577474623918533, -0.09084001928567886, 0.09569169580936432, 0.019712962210178375, 0.0678594559431076, 0.019654806703329086, 0.04794074967503548, 0.03854553773999214, 0.059142716228961945, -0.049287356436252594, 0.1346089392900467, -0.022184303030371666, 0.06552704423666, 0.031068429350852966, 0.015437418594956398, -0.059191957116127014, -0.05589597299695015, -0.04879779368638992, -0.06350339949131012, -0.0433633029460907, 0.04284078627824783, 0.013974619098007679, 0.004040117375552654, -0.012953526340425014, -0.14210595190525055, -0.05669940635561943, -0.01813357323408127, 0.01552248653024435, 0.11360668390989304, 0.07483407109975815, 0.05998560041189194, -0.0024166391231119633));
select sql-
select content, knn_dist() from test_table where knn ( content_vector, 5, (0.039400361478328705, 0.03291686996817589, -0.03521652892231941, 0.0503256693482399, -0.021705757826566696, -0.03538743779063225, -0.010091155767440796, -0.001861955621279776, -0.08917419612407684, -0.02797577530145645, 0.018109984695911407, -0.15754610300064087, -0.026915807276964188, -0.07373688369989395, -0.003222099505364895, -0.041277479380369186, 0.07844182103872299, -0.0193732138723135, 0.11503950506448746, -0.11390843987464905, -0.0734306052327156, -0.03628923371434212, 0.032250598073005676, -0.029256096109747887, 0.040944769978523254, 0.0325363390147686, 0.01594902202486992, -0.02466769516468048, -0.03176739811897278, -0.045060958713293076, 0.0618099719285965, -0.06511795520782471, 0.02614971622824669, 0.00047550126328133047, -0.03343825787305832, 0.06541404873132706, 0.011969256214797497, 0.022566435858607292, 0.09440282732248306, -0.034244585782289505, 0.07342161238193512, 0.028059320524334908, 0.016448376700282097, -0.019640600308775902, 0.04936521500349045, -0.012174294330179691, -0.0010165045969188213, 0.012577196583151817, 0.015510383993387222, -0.04867100343108177, 0.0215749628841877, -0.0064097680151462555, -0.0716998502612114, -0.0217656958848238, -0.018020164221525192, -0.03763725608587265, 0.044057365506887436, -0.015162146650254726, -0.0383300743997097, 0.07343754172325134, -0.06093975156545639, 0.04979526251554489, -0.02124367654323578, 0.053617339581251144, 0.0855056643486023, -0.03272668272256851, 0.023070212453603745, -0.024968700483441353, 0.007349049672484398, -0.06819375604391098, -0.002642123494297266, 0.011557545512914658, 0.037295203655958176, -0.05695534497499466, -0.03505320847034454, -0.06907611340284348, -0.02233273722231388, 0.012394657358527184, 0.04204864054918289, 0.01958216167986393, -0.075689397752285, 0.013610051944851875, -0.004419006872922182, 0.06220664829015732, -0.061197925359010696, 0.038657303899526596, -0.028761837631464005, -0.021792976185679436, -0.03149930015206337, -0.0555666983127594, 0.06542011350393295, 0.03801325708627701, -0.05338123440742493, 0.04999314248561859, -0.05899163708090782, 0.05467355251312256, -0.04357548803091049, -0.02977103367447853, -0.05462189391255379, 0.007743102964013815, -0.03832957521080971, -0.0030889115296304226, -0.016611458733677864, -0.003288902807980776, -0.07695620507001877, 0.016904007643461227, -0.01569935865700245, -0.042842648923397064, -0.040371499955654144, 0.03040495328605175, -0.038055695593357086, 0.02606748230755329, -0.04614444077014923, 0.02289075218141079, 0.022546589374542236, 0.03910815343260765, 0.009068850427865982, -0.017486168071627617, -0.06527229398488998, -0.05971920117735863, -0.08486129343509674, -0.05783925950527191, -0.027934392914175987, 0.004406413994729519, -0.10050063580274582, -0.08441127836704254, -0.054413117468357086, -6.0926199137485484e-33, -0.02003992535173893, -0.06645941734313965, 0.061569906771183014, 0.031261373311281204, -0.09098590165376663, -0.007735047489404678, 0.03447912260890007, -0.06949391961097717, -0.01385411061346531, 0.019136600196361542, 0.02587386965751648, -0.1613064408302307, 0.004871261306107044, -0.04546062648296356, 0.10681931674480438, -0.03143885359168053, 0.004188291262835264, 0.04820200055837631, -0.0635150671005249, -0.012187191285192966, -0.050467994064092636, 0.04707322269678116, -0.06413251906633377, -0.11869526654481888, -0.00822642631828785, -0.0041225748136639595, -0.01776275411248207, 0.061632853001356125, 0.03785533085465431, 0.010274436324834824, 0.06228845566511154, 0.0846332460641861, -0.0351577065885067, 0.06797506660223007, -0.031482722610235214, 0.04953403025865555, -0.000487973156850785, -0.06346078217029572, -0.029974861070513725, 0.013818463310599327, -0.02469082735478878, 0.03183627501130104, -0.020197495818138123, -0.006206996273249388, -0.008357943966984749, 0.027797551825642586, -0.013002551160752773, -0.025573227554559708, 0.03486579284071922, -0.04449675232172012, -0.007034475915133953, 0.009955202229321003, -0.03447085618972778, 0.017124537378549576, 0.031904470175504684, 0.040200263261795044, -0.030375413596630096, -0.03426678478717804, 0.0789761170744896, 0.15356841683387756, -0.007749452721327543, 0.018187055364251137, -0.039633650332689285, 0.0057756626047194, -0.0043510436080396175, -0.005618011578917503, 0.06944657862186432, 0.007463261019438505, 0.06504189968109131, 0.0732140764594078, 0.02808529883623123, 0.014073632657527924, -0.035767797380685806, 0.0741928294301033, -0.03546743467450142, 0.010225637815892696, 0.018867528066039085, 0.03569617122411728, -0.031210890039801598, 0.06004517897963524, 0.011485242284834385, 0.02433539554476738, -0.046409234404563904, 0.008625813759863377, 0.1647210270166397, -0.04562300816178322, -0.05166885629296303, -0.034926317632198334, -0.05571971833705902, -0.03702155128121376, -0.01244123000651598, 0.015630122274160385, 0.016705485060811043, 0.03993142396211624, -0.02281648851931095, 1.9889287274096332e-33, 0.026748675853013992, -0.07855979353189468, -0.07491922378540039, -0.025046871975064278, -0.07008074969053268, 0.014933544211089611, 0.10520888864994049, 0.045006006956100464, -0.022541677579283714, 0.05113279074430466, -0.07582405209541321, 0.011290057562291622, 0.07470495253801346, -0.006621385458856821, 0.10674373060464859, 0.03397534787654877, 0.05441197380423546, 0.06009897589683533, -0.10512126982212067, 0.00251168105751276, -0.07073135673999786, 0.023499315604567528, -0.11261684447526932, -0.05296175181865692, 0.020252695307135582, -0.0262316707521677, -0.14585363864898682, -0.010455037467181683, -0.061574701219797134, -0.03592634201049805, 0.024031363427639008, -0.055954691022634506, -0.11982572078704834, 0.0687517300248146, 0.0033843866549432278, -0.0075232298113405704, 0.08187714219093323, -0.04765114188194275, 0.04529637470841408, 0.06692932546138763, -0.028575075790286064, 0.05738282948732376, 0.07064869999885559, 0.13786080479621887, 0.07201071083545685, 0.02603287063539028, 0.00829070433974266, 0.048708733171224594, -0.02848454937338829, 0.09929480403661728, 0.012958141975104809, -0.0667564645409584, 0.024380065500736237, 0.031152574345469475, 0.05480052903294563, 0.03446302190423012, -0.022702742367982864, 0.08708023279905319, -0.043927151709795, -0.1146966740489006, 0.056840233504772186, 0.007554410956799984, -0.009315861389040947, 0.07436615973711014, -0.03262993320822716, 0.023126419633626938, 0.03737719729542732, -0.02547895349562168, 0.044566620141267776, -0.04742495343089104, 0.10476760566234589, 0.022099299356341362, -0.03953292965888977, -0.002192448591813445, -0.058971237391233444, 0.04755580425262451, 0.07808065414428711, 0.07434992492198944, 0.042856283485889435, -0.016486041247844696, 0.048336297273635864, 0.09260814636945724, 0.008590247482061386, -0.07388044148683548, -0.005808695685118437, 0.060788508504629135, 0.05555510148406029, -0.03346933051943779, 0.04686138406395912, -0.02255815453827381, 0.0015474820975214243, 0.03171731159090996, 0.026125049218535423, -0.030306288972496986, 0.02288391813635826, -1.7988135425639484e-08, -0.0008649295778013766, -0.012948621064424515, -0.03472248837351799, 0.019027400761842728, -0.021788524463772774, 0.03240593895316124, -0.0049513960257172585, -0.04739075154066086, -0.01587488315999508, -3.3113420272457006e-07, 0.025563932955265045, 0.024572262540459633, -0.057154834270477295, -0.021360905840992928, -0.0770401656627655, -0.051631852984428406, 0.011719483882188797, 0.04198926314711571, 0.004222826100885868, -0.0376339815557003, -0.04838724061846733, -0.004758486989885569, -0.015201208181679249, 0.05343189090490341, 0.014786732383072376, -0.00528594059869647, 0.02611462213099003, -0.01476211752742529, 0.07295969873666763, 0.022666115313768387, 0.032798901200294495, 0.011021117679774761, 0.028016729280352592, -0.08964649587869644, 0.05672395974397659, 0.031166186556220055, 0.035954345017671585, -0.007248388137668371, 0.042897798120975494, -0.038485728204250336, 0.05153529718518257, -0.02304188348352909, 0.13088321685791016, 0.0018594616558402777, 0.07432031631469727, 0.028188729658722878, -0.005484302528202534, -0.037547964602708817, -0.024765292182564735, -0.09358104318380356, -0.11897563189268112, -0.0021920225117355585, 0.060817599296569824, 0.0066648018546402454, 0.0163790974766016, -0.04564284160733223, -0.09075187146663666, -0.04448777437210083, -0.014347223564982414, 0.025733264163136482, 0.1166100800037384, 0.015347518026828766, 0.04779069870710373, 0.0298114363104105));
--this query returns-
+-----------------------------------------------+------------+ | content | knn_dist() | +-----------------------------------------------+------------+ | The capital city of Uttar Pradesh is Lucknow. | 0.26123598 | +-----------------------------------------------+------------+ 1 row in set (0.00 sec) --- 1 out of 1 results in 0ms ---
Now, these vector embeddings are the same vectors outputted and used by my standalone python code above.
The source select query vector is of the text "What is the capital city of Uttar Pradesh?".
Standalone python code -
strs = ["The capital city of Uttar Pradesh is Lucknow.","What is the capital city of Uttar Pradesh?"] vecs = embed_transformer.encode(strs) distance = 1 - cos_sim(vecs[0],vecs[1]) print(distance)
prints 0.13061797618865967
Sorry for the big vectors(sql).
With pgvector I get the 3rd different result :)
postgres=# drop table if exists test_table; CREATE TABLE test_table (id bigserial PRIMARY KEY, content_vector vector(384)); insert into test_table(content_vector) values ('[0.06482091546058655, 0.04992128536105156, -0.03429781645536423, 0.026320653036236763, -0.009687593206763268, 0.01179866399616003, 0.004409298300743103, -0.01785661093890667, -0.09590322524309158, -0.01006210409104824, 0.016009870916604996, -0.12434668838977814, -0.020932624116539955, -0.06882227957248688, 0.020757293328642845, -0.0025973336305469275, 0.09881345927715302, 0.0019554374739527702, 0.08176830410957336, -0.1057162657380104, -0.07408052682876587, -0.026800718158483505, 0.0510084368288517, -0.02934758923947811, 0.04715917631983757, 0.030601687729358673, 0.0002789408026728779, -0.008580046705901623, 0.012862227857112885, -0.05232050269842148, 0.1114281564950943, -0.01832321472465992, -0.010838007554411888, -0.025491593405604362, -0.05287948623299599, 0.07078016549348831, -0.018588192760944366, 0.005674791522324085, 0.12451225519180298, -0.04396867752075195, 0.11632400751113892, 0.04034367948770523, -0.02234485000371933, -0.05281723290681839, 0.03560516983270645, -0.009733027778565884, 0.016981204971671104, -0.01904718205332756, -0.0221172496676445, -0.04327552765607834, 0.029408074915409088, -0.05015785992145538, -0.029000280424952507, -0.0627661794424057, -0.017665142193436623, -0.06745558232069016, 0.04562167823314667, 0.025913843885064125, -0.05845576897263527, 0.023129232227802277, -0.06782524287700653, 0.05111556127667427, 0.0176242608577013, 0.0460895337164402, 0.024225136265158653, -0.02694002166390419, 0.029928192496299744, -0.016062170267105103, 0.016708480194211006, -0.06875284761190414, -0.020549483597278595, 0.025116391479969025, 0.026381734758615494, -0.058338094502687454, -0.05094703286886215, -0.05185637250542641, 0.010776680894196033, 0.028104711323976517, 0.06571896374225616, 0.0220874585211277, -0.08572608232498169, -0.011421817354857922, -0.006878388114273548, 0.0189790241420269, -0.06547429412603378, 0.026981202885508537, -0.05079017952084541, -0.017946884036064148, -0.055698949843645096, -0.048960939049720764, 0.03902903199195862, 0.04179072007536888, -0.027790479362010956, 0.025074973702430725, -0.025060545653104782, 0.04205888509750366, -0.039338912814855576, -0.04142407327890396, -0.01233632117509842, 0.00653756782412529, -0.05161905288696289, 0.0025052870623767376, -0.033369772136211395, 0.02182653546333313, -0.03213304281234741, -0.0036571144592016935, -0.042951490730047226, -0.0277724452316761, -0.033435773104429245, -0.005305944941937923, 0.018029607832431793, 0.037417396903038025, 0.017181238159537315, 0.02643471583724022, 0.01194708701223135, 0.09099791198968887, -0.029966114088892937, -0.013841962441802025, -0.049566373229026794, -0.035440512001514435, -0.11595731973648071, -0.03921404480934143, -0.022447023540735245, 0.01697845570743084, -0.0619276687502861, -0.11142934113740921, -0.03916054964065552, -6.078577899044007e-33, -0.029456527903676033, -0.046578045934438705, 0.03768320381641388, 0.004133111797273159, -0.06685203313827515, -0.03763018175959587, 0.044151581823825836, -0.05346596986055374, -0.027279887348413467, -0.004606899805366993, 0.01321921031922102, -0.1368519514799118, 0.05520038679242134, -0.011957261711359024, 0.08951473981142044, -0.028361095115542412, 0.041944604367017746, 0.018210548907518387, -0.04884594678878784, 0.0072183613665401936, -0.043671734631061554, -0.03750285878777504, -0.0717604011297226, -0.08534064143896103, -0.028280073776841164, -0.004378854297101498, 0.03288616985082626, 0.09250205755233765, 0.040987417101860046, 0.0011889026500284672, 0.056012142449617386, 0.09130873531103134, -0.024854809045791626, 0.053032826632261276, -0.03173600509762764, 0.03463532030582428, -0.01169117446988821, -0.0274259801954031, -0.05220950022339821, -0.0008523532887920737, -0.053598616272211075, 0.03822256624698639, -0.0006149214459583163, -0.03490142524242401, -0.031777072697877884, 0.06556002050638199, -0.006123066414147615, 0.0022767113987356424, 0.03809332847595215, -0.043361734598875046, -0.041438959538936615, 0.011960203759372234, 0.04021666944026947, 0.01709781400859356, 0.029787326231598854, 0.031030690297484398, -0.07112845778465271, 0.008569818921387196, 0.05839313939213753, 0.15410208702087402, -0.003681182861328125, -0.021215083077549934, -0.08402945101261139, 0.027156515046954155, -0.027800381183624268, -0.023969663307070732, 0.0699777901172638, -0.016330868005752563, 0.048132024705410004, 0.07959488779306412, 0.0451931431889534, 0.013464187271893024, -0.0003824577433988452, 0.07180611044168472, -0.052828725427389145, 0.025036051869392395, 0.0062473611906170845, 0.008519499562680721, -0.043585117906332016, 0.05220074579119682, 0.05215125530958176, 0.04888764023780823, -0.047547779977321625, -0.08879595249891281, 0.15181465446949005, -0.05074972286820412, -0.01668126881122589, -0.027455739676952362, -0.04654162749648094, -0.02620253898203373, 0.008067038841545582, 0.018032681196928024, 0.01002639438956976, 0.023883264511823654, 0.006333629135042429, 1.3369413367390284e-33, 0.06534791737794876, -0.026056397706270218, -0.0809331014752388, -0.05019157752394676, -0.04701877385377884, 0.042431265115737915, 0.12461554259061813, -0.01780806854367256, -0.050303295254707336, 0.05757782980799675, -0.046190258115530014, 0.035705044865608215, 0.040408920496702194, -0.021427027881145477, 0.0735001340508461, 0.011265089735388756, 0.011742585338652134, 0.02631988935172558, -0.06628582626581192, 0.02132044918835163, -0.07101915031671524, 0.03078136406838894, -0.1538163721561432, -0.06546951085329056, 0.026620905846357346, -0.051242876797914505, -0.1617601364850998, -0.0024413953069597483, -0.06519318372011185, -0.03859483450651169, 0.012186173349618912, -0.06914299726486206, -0.12480893731117249, 0.09702786058187485, 0.02642073854804039, -0.02139950357377529, 0.05911185219883919, -0.07446742057800293, 0.045271314680576324, 0.03199991211295128, -0.04724122956395149, 0.06467762589454651, 0.06257136166095734, 0.08647197484970093, 0.06417220085859299, 0.003292545210570097, -0.040703870356082916, 0.023571981117129326, -0.025455843657255173, 0.05741902440786362, 0.00038647011388093233, -0.05743066966533661, 0.04087774455547333, 0.02584318071603775, 0.06117433309555054, 0.08033672720193863, 0.007273032795637846, 0.06303175538778305, -0.03102913685142994, -0.10810790210962296, 0.01722388155758381, -0.0249248705804348, 0.009433611296117306, 0.07658936828374863, -0.08852456510066986, 0.009506282396614552, 0.02306794933974743, -0.06006643548607826, 0.048894573003053665, -0.014441486448049545, 0.04875165969133377, 0.007772950921207666, -0.05729253217577934, 0.008025131188333035, -0.07494957000017166, 0.0476347841322422, 0.03379659727215767, 0.09253711253404617, 0.016099708154797554, -0.027535472065210342, 0.1291743665933609, 0.0741562768816948, 0.028188351541757584, -0.07637868821620941, 0.011635500937700272, 0.04068224877119064, 0.0266109649091959, -0.02422288991510868, 0.029400186613202095, -0.05802464112639427, 0.031234342604875565, 0.01683625765144825, 0.01809609681367874, -0.017968276515603065, 0.04509495571255684, -2.2079850836576043e-08, -0.016516827046871185, -0.044284213334321976, -0.04216821491718292, 0.03774471953511238, 0.0072920434176921844, 0.0436013787984848, 0.016658512875437737, -0.04157709330320358, -0.04154917970299721, 0.004683543927967548, -0.012803655117750168, -0.018749674782156944, -0.0506889708340168, 0.01217014342546463, -0.04210936278104782, -0.023202205076813698, 0.007226691115647554, 0.015686262398958206, 0.03178316727280617, -0.028077714145183563, -0.05697041377425194, -0.0076336548663675785, -0.004964582622051239, 0.06090867519378662, 0.020856687799096107, -0.00793258287012577, 0.014063490554690361, -0.05261142551898956, 0.0633118525147438, 0.01638849265873432, 0.020914021879434586, 0.03007942996919155, 0.06577474623918533, -0.09084001928567886, 0.09569169580936432, 0.019712962210178375, 0.0678594559431076, 0.019654806703329086, 0.04794074967503548, 0.03854553773999214, 0.059142716228961945, -0.049287356436252594, 0.1346089392900467, -0.022184303030371666, 0.06552704423666, 0.031068429350852966, 0.015437418594956398, -0.059191957116127014, -0.05589597299695015, -0.04879779368638992, -0.06350339949131012, -0.0433633029460907, 0.04284078627824783, 0.013974619098007679, 0.004040117375552654, -0.012953526340425014, -0.14210595190525055, -0.05669940635561943, -0.01813357323408127, 0.01552248653024435, 0.11360668390989304, 0.07483407109975815, 0.05998560041189194, -0.0024166391231119633]'); SELECT 1 - (content_vector <-> '[0.039400361478328705, 0.03291686996817589, -0.03521652892231941, 0.0503256693482399, -0.021705757826566696, -0.03538743779063225, -0.010091155767440796, -0.001861955621279776, -0.08917419612407684, -0.02797577530145645, 0.018109984695911407, -0.15754610300064087, -0.026915807276964188, -0.07373688369989395, -0.003222099505364895, -0.041277479380369186, 0.07844182103872299, -0.0193732138723135, 0.11503950506448746, -0.11390843987464905, -0.0734306052327156, -0.03628923371434212, 0.032250598073005676, -0.029256096109747887, 0.040944769978523254, 0.0325363390147686, 0.01594902202486992, -0.02466769516468048, -0.03176739811897278, -0.045060958713293076, 0.0618099719285965, -0.06511795520782471, 0.02614971622824669, 0.00047550126328133047, -0.03343825787305832, 0.06541404873132706, 0.011969256214797497, 0.022566435858607292, 0.09440282732248306, -0.034244585782289505, 0.07342161238193512, 0.028059320524334908, 0.016448376700282097, -0.019640600308775902, 0.04936521500349045, -0.012174294330179691, -0.0010165045969188213, 0.012577196583151817, 0.015510383993387222, -0.04867100343108177, 0.0215749628841877, -0.0064097680151462555, -0.0716998502612114, -0.0217656958848238, -0.018020164221525192, -0.03763725608587265, 0.044057365506887436, -0.015162146650254726, -0.0383300743997097, 0.07343754172325134, -0.06093975156545639, 0.04979526251554489, -0.02124367654323578, 0.053617339581251144, 0.0855056643486023, -0.03272668272256851, 0.023070212453603745, -0.024968700483441353, 0.007349049672484398, -0.06819375604391098, -0.002642123494297266, 0.011557545512914658, 0.037295203655958176, -0.05695534497499466, -0.03505320847034454, -0.06907611340284348, -0.02233273722231388, 0.012394657358527184, 0.04204864054918289, 0.01958216167986393, -0.075689397752285, 0.013610051944851875, -0.004419006872922182, 0.06220664829015732, -0.061197925359010696, 0.038657303899526596, -0.028761837631464005, -0.021792976185679436, -0.03149930015206337, -0.0555666983127594, 0.06542011350393295, 0.03801325708627701, -0.05338123440742493, 0.04999314248561859, -0.05899163708090782, 0.05467355251312256, -0.04357548803091049, -0.02977103367447853, -0.05462189391255379, 0.007743102964013815, -0.03832957521080971, -0.0030889115296304226, -0.016611458733677864, -0.003288902807980776, -0.07695620507001877, 0.016904007643461227, -0.01569935865700245, -0.042842648923397064, -0.040371499955654144, 0.03040495328605175, -0.038055695593357086, 0.02606748230755329, -0.04614444077014923, 0.02289075218141079, 0.022546589374542236, 0.03910815343260765, 0.009068850427865982, -0.017486168071627617, -0.06527229398488998, -0.05971920117735863, -0.08486129343509674, -0.05783925950527191, -0.027934392914175987, 0.004406413994729519, -0.10050063580274582, -0.08441127836704254, -0.054413117468357086, -6.0926199137485484e-33, -0.02003992535173893, -0.06645941734313965, 0.061569906771183014, 0.031261373311281204, -0.09098590165376663, -0.007735047489404678, 0.03447912260890007, -0.06949391961097717, -0.01385411061346531, 0.019136600196361542, 0.02587386965751648, -0.1613064408302307, 0.004871261306107044, -0.04546062648296356, 0.10681931674480438, -0.03143885359168053, 0.004188291262835264, 0.04820200055837631, -0.0635150671005249, -0.012187191285192966, -0.050467994064092636, 0.04707322269678116, -0.06413251906633377, -0.11869526654481888, -0.00822642631828785, -0.0041225748136639595, -0.01776275411248207, 0.061632853001356125, 0.03785533085465431, 0.010274436324834824, 0.06228845566511154, 0.0846332460641861, -0.0351577065885067, 0.06797506660223007, -0.031482722610235214, 0.04953403025865555, -0.000487973156850785, -0.06346078217029572, -0.029974861070513725, 0.013818463310599327, -0.02469082735478878, 0.03183627501130104, -0.020197495818138123, -0.006206996273249388, -0.008357943966984749, 0.027797551825642586, -0.013002551160752773, -0.025573227554559708, 0.03486579284071922, -0.04449675232172012, -0.007034475915133953, 0.009955202229321003, -0.03447085618972778, 0.017124537378549576, 0.031904470175504684, 0.040200263261795044, -0.030375413596630096, -0.03426678478717804, 0.0789761170744896, 0.15356841683387756, -0.007749452721327543, 0.018187055364251137, -0.039633650332689285, 0.0057756626047194, -0.0043510436080396175, -0.005618011578917503, 0.06944657862186432, 0.007463261019438505, 0.06504189968109131, 0.0732140764594078, 0.02808529883623123, 0.014073632657527924, -0.035767797380685806, 0.0741928294301033, -0.03546743467450142, 0.010225637815892696, 0.018867528066039085, 0.03569617122411728, -0.031210890039801598, 0.06004517897963524, 0.011485242284834385, 0.02433539554476738, -0.046409234404563904, 0.008625813759863377, 0.1647210270166397, -0.04562300816178322, -0.05166885629296303, -0.034926317632198334, -0.05571971833705902, -0.03702155128121376, -0.01244123000651598, 0.015630122274160385, 0.016705485060811043, 0.03993142396211624, -0.02281648851931095, 1.9889287274096332e-33, 0.026748675853013992, -0.07855979353189468, -0.07491922378540039, -0.025046871975064278, -0.07008074969053268, 0.014933544211089611, 0.10520888864994049, 0.045006006956100464, -0.022541677579283714, 0.05113279074430466, -0.07582405209541321, 0.011290057562291622, 0.07470495253801346, -0.006621385458856821, 0.10674373060464859, 0.03397534787654877, 0.05441197380423546, 0.06009897589683533, -0.10512126982212067, 0.00251168105751276, -0.07073135673999786, 0.023499315604567528, -0.11261684447526932, -0.05296175181865692, 0.020252695307135582, -0.0262316707521677, -0.14585363864898682, -0.010455037467181683, -0.061574701219797134, -0.03592634201049805, 0.024031363427639008, -0.055954691022634506, -0.11982572078704834, 0.0687517300248146, 0.0033843866549432278, -0.0075232298113405704, 0.08187714219093323, -0.04765114188194275, 0.04529637470841408, 0.06692932546138763, -0.028575075790286064, 0.05738282948732376, 0.07064869999885559, 0.13786080479621887, 0.07201071083545685, 0.02603287063539028, 0.00829070433974266, 0.048708733171224594, -0.02848454937338829, 0.09929480403661728, 0.012958141975104809, -0.0667564645409584, 0.024380065500736237, 0.031152574345469475, 0.05480052903294563, 0.03446302190423012, -0.022702742367982864, 0.08708023279905319, -0.043927151709795, -0.1146966740489006, 0.056840233504772186, 0.007554410956799984, -0.009315861389040947, 0.07436615973711014, -0.03262993320822716, 0.023126419633626938, 0.03737719729542732, -0.02547895349562168, 0.044566620141267776, -0.04742495343089104, 0.10476760566234589, 0.022099299356341362, -0.03953292965888977, -0.002192448591813445, -0.058971237391233444, 0.04755580425262451, 0.07808065414428711, 0.07434992492198944, 0.042856283485889435, -0.016486041247844696, 0.048336297273635864, 0.09260814636945724, 0.008590247482061386, -0.07388044148683548, -0.005808695685118437, 0.060788508504629135, 0.05555510148406029, -0.03346933051943779, 0.04686138406395912, -0.02255815453827381, 0.0015474820975214243, 0.03171731159090996, 0.026125049218535423, -0.030306288972496986, 0.02288391813635826, -1.7988135425639484e-08, -0.0008649295778013766, -0.012948621064424515, -0.03472248837351799, 0.019027400761842728, -0.021788524463772774, 0.03240593895316124, -0.0049513960257172585, -0.04739075154066086, -0.01587488315999508, -3.3113420272457006e-07, 0.025563932955265045, 0.024572262540459633, -0.057154834270477295, -0.021360905840992928, -0.0770401656627655, -0.051631852984428406, 0.011719483882188797, 0.04198926314711571, 0.004222826100885868, -0.0376339815557003, -0.04838724061846733, -0.004758486989885569, -0.015201208181679249, 0.05343189090490341, 0.014786732383072376, -0.00528594059869647, 0.02611462213099003, -0.01476211752742529, 0.07295969873666763, 0.022666115313768387, 0.032798901200294495, 0.011021117679774761, 0.028016729280352592, -0.08964649587869644, 0.05672395974397659, 0.031166186556220055, 0.035954345017671585, -0.007248388137668371, 0.042897798120975494, -0.038485728204250336, 0.05153529718518257, -0.02304188348352909, 0.13088321685791016, 0.0018594616558402777, 0.07432031631469727, 0.028188729658722878, -0.005484302528202534, -0.037547964602708817, -0.024765292182564735, -0.09358104318380356, -0.11897563189268112, -0.0021920225117355585, 0.060817599296569824, 0.0066648018546402454, 0.0163790974766016, -0.04564284160733223, -0.09075187146663666, -0.04448777437210083, -0.014347223564982414, 0.025733264163136482, 0.1166100800037384, 0.015347518026828766, 0.04779069870710373, 0.0298114363104105]') AS cosine_similarity FROM test_table ORDER BY cosine_similarity ASC LIMIT 20;
DROP TABLE
CREATE TABLE
INSERT 0 1
cosine_similarity
-------------------
0.488887505357537
(1 row)
On Vespa AI, using https://github.com/vespa-engine/sample-apps/raw/master/simple-semantic-search/model/e5-small-v2-int8.onnx embedding(outputs 384 dim vector), I am getting 'cosine': 0.9367196307676168 for the same pair of input contents.
Though not certain, looking at the 2 sentences, I feel the similarity should be high.
You can check out this related issue that is now fixed: https://github.com/manticoresoftware/manticoresearch/issues/2005
I am getting a higher cosine _knn_dist value for a hit than my own standalone calculation. My standalone code `from numpy.linalg import norm from sentence_transformers import SentenceTransformer
embed_transformer = SentenceTransformer('all-MiniLM-L6-v2') cos_sim = lambda a,b: (a @ b.T) / (norm(a)*norm(b)) strs = ["Uttar Pradesh's capital city is Lucknow.","What is the capital city of Uttar Pradesh?"] vecs = embed_transformer.encode(strs) distance = 1 - cos_sim(vecs[0],vecs[1]) print(distance)`
gives distance = 0.12863826751708984
However, manticore knn search is returning .25727645 for the same query and target sentence -
{'aggregations': None, 'hits': {'hits': [{'_id': '2740690609156129169', '_knn_dist': 0.25727645, '_score': 1, '_source': {'content': "Uttar Pradesh's capital city is " 'Lucknow.', 'meta': {'chunk_id': 1, 'title': 'india'}}}, {'_id': '2740690609156129172',
Also often time, I am getting cosine _knn_dist > 1.0 when I am not expecting a value > 1.0 I have tried with some other texts as well, but having the same observations.Am I interpreting this wrong? Or there is an issue here?
Thanks.