I have the following table structure for my table called storage_faceencoding.
id: UUID
feature_1: Float
feature_2: Float
feature_3: Float
...
feature_128: Float
I want to query against those 128 feature columns and return the id along with the distance value.
I'm querying against those 128 feature columns like so:
SELECT * from storage_faceencoding ORDER BY sqrt(power(feature_1 - -0.054835572838783264, 2) + power(feature_2 - 0.034169211983680725, 2) + power(feature_3 - 0.0789899230003357, 2) + power(feature_4 - -0.12306179106235504, 2) + power(feature_5 - -0.14243610203266144, 2) + power(feature_6 - 0.0015480183064937592, 2) + power(feature_7 - -0.03730906546115875, 2) + power(feature_8 - -0.04611199349164963, 2) + power(feature_9 - 0.17417974770069122, 2) + power(feature_10 - -0.07324142754077911, 2) + power(feature_11 - 0.2784380316734314, 2) + power(feature_12 - -0.05557965114712715, 2) + power(feature_13 - -0.28433677554130554, 2) + power(feature_14 - 0.003816460259258747, 2) + power(feature_15 - -0.004081043414771557, 2) + power(feature_16 - 0.14893895387649536, 2) + power(feature_17 - -0.12637391686439514, 2) + power(feature_18 - -0.0776168555021286, 2) + power(feature_19 - -0.07115891575813293, 2) + power(feature_20 - 0.013110934756696224, 2) + power(feature_21 - -0.03728703036904335, 2) + power(feature_22 - 0.0312555767595768, 2) + power(feature_23 - -0.013231765478849411, 2) + power(feature_24 - 0.08345625549554825, 2) + power(feature_25 - -0.14501842856407166, 2) + power(feature_26 - -0.3354545533657074, 2) + power(feature_27 - -0.06517831236124039, 2) + power(feature_28 - -0.16320215165615082, 2) + power(feature_29 - -0.029647808521986008, 2) + power(feature_30 - -0.026274608448147774, 2) + power(feature_31 - 0.008217697963118553, 2) + power(feature_32 - 0.09989964962005615, 2) + power(feature_33 - -0.10960874706506729, 2) + power(feature_34 - -0.04241098091006279, 2) + power(feature_35 - 0.03659277781844139, 2) + power(feature_36 - 0.05843937397003174, 2) + power(feature_37 - -0.1882062405347824, 2) + power(feature_38 - -0.1472000777721405, 2) + power(feature_39 - 0.1806768774986267, 2) + power(feature_40 - -0.047331131994724274, 2) + power(feature_41 - -0.1587458848953247, 2) + power(feature_42 - -0.03949886932969093, 2) + power(feature_43 - 0.025885790586471558, 2) + power(feature_44 - 0.23678790032863617, 2) + power(feature_45 - 0.10318232327699661, 2) + power(feature_46 - -0.02302492968738079, 2) + power(feature_47 - 0.1084280014038086, 2) + power(feature_48 - -0.047027621418237686, 2) + power(feature_49 - 0.07425221800804138, 2) + power(feature_50 - -0.2947121560573578, 2) + power(feature_51 - 0.0031417328864336014, 2) + power(feature_52 - 0.121400848031044, 2) + power(feature_53 - 0.07688573747873306, 2) + power(feature_54 - 0.09685630351305008, 2) + power(feature_55 - 0.10917495936155319, 2) + power(feature_56 - -0.1276204138994217, 2) + power(feature_57 - 0.08362210541963577, 2) + power(feature_58 - 0.16328635811805725, 2) + power(feature_59 - -0.25213390588760376, 2) + power(feature_60 - 0.05785408616065979, 2) + power(feature_61 - 0.018559012562036514, 2) + power(feature_62 - -0.01683107763528824, 2) + power(feature_63 - -0.01742824725806713, 2) + power(feature_64 - -0.1193951666355133, 2) + power(feature_65 - 0.2622459828853607, 2) + power(feature_66 - 0.12121666967868805, 2) + power(feature_67 - -0.1520567685365677, 2) + power(feature_68 - -0.1122896820306778, 2) + power(feature_69 - 0.14081937074661255, 2) + power(feature_70 - -0.14206485450267792, 2) + power(feature_71 - -0.10112465173006058, 2) + power(feature_72 - 0.07290071249008179, 2) + power(feature_73 - -0.16641031205654144, 2) + power(feature_74 - -0.21917763352394104, 2) + power(feature_75 - -0.25251486897468567, 2) + power(feature_76 - -0.0048762112855911255, 2) + power(feature_77 - 0.37720248103141785, 2) + power(feature_78 - 0.1548663228750229, 2) + power(feature_79 - -0.12398210912942886, 2) + power(feature_80 - 0.041234225034713745, 2) + power(feature_81 - -0.06544441729784012, 2) + power(feature_82 - -0.09197349101305008, 2) + power(feature_83 - -0.021058330312371254, 2) + power(feature_84 - 0.039639901369810104, 2) + power(feature_85 - -0.0023813657462596893, 2) + power(feature_86 - -0.07752023637294769, 2) + power(feature_87 - -0.03788585215806961, 2) + power(feature_88 - 0.01571604609489441, 2) + power(feature_89 - 0.22586794197559357, 2) + power(feature_90 - -0.08962416648864746, 2) + power(feature_91 - 0.027185270562767982, 2) + power(feature_92 - 0.21015749871730804, 2) + power(feature_93 - 0.014571629464626312, 2) + power(feature_94 - -0.03427625447511673, 2) + power(feature_95 - -0.031976763159036636, 2) + power(feature_96 - -0.02412014827132225, 2) + power(feature_97 - -0.0572514683008194, 2) + power(feature_98 - 0.025131937116384506, 2) + power(feature_99 - -0.055663101375103, 2) + power(feature_100 - 0.06940365582704544, 2) + power(feature_101 - -0.008616405539214611, 2) + power(feature_102 - -0.08647502958774567, 2) + power(feature_103 - -0.002743437420576811, 2) + power(feature_104 - 0.06195132061839104, 2) + power(feature_105 - -0.21810059249401093, 2) + power(feature_106 - 0.18355928361415863, 2) + power(feature_107 - 0.028437575325369835, 2) + power(feature_108 - -0.02596919797360897, 2) + power(feature_109 - 0.03891913592815399, 2) + power(feature_110 - 0.017703840509057045, 2) + power(feature_111 - -0.14867563545703888, 2) + power(feature_112 - -0.035795167088508606, 2) + power(feature_113 - 0.21177658438682556, 2) + power(feature_114 - -0.3009713888168335, 2) + power(feature_115 - 0.20549386739730835, 2) + power(feature_116 - 0.15210166573524475, 2) + power(feature_117 - 0.1311473250389099, 2) + power(feature_118 - 0.1054188460111618, 2) + power(feature_119 - 0.017464492470026016, 2) + power(feature_120 - -0.011423288844525814, 2) + power(feature_121 - -0.0072870198637247086, 2) + power(feature_122 - -0.021593499928712845, 2) + power(feature_123 - -0.21365071833133698, 2) + power(feature_124 - -0.09368597716093063, 2) + power(feature_125 - 0.06633836776018143, 2) + power(feature_126 - -0.05478530377149582, 2) + power(feature_127 - -0.009351606480777264, 2) + power(feature_128 - 0.04693271964788437, 2) ) LIMIT 5
This works and orders the results by the euclidean distance however I also want the distance value returned (i.e. SELECT it).
How would I go about getting that distance value?
Thanks in advance.
You can use an alias to show that distance on the result and then order by that distance:
SELECT *, (sqrt(power(feature_1 - -0.054835572838783264, 2) + power(feature_2 - 0.034169211983680725, 2) + power(feature_3 - 0.0789899230003357, 2) + power(feature_4 - -0.12306179106235504, 2) + power(feature_5 - -0.14243610203266144, 2) + power(feature_6 - 0.0015480183064937592, 2) + power(feature_7 - -0.03730906546115875, 2) + power(feature_8 - -0.04611199349164963, 2) + power(feature_9 - 0.17417974770069122, 2) + power(feature_10 - -0.07324142754077911, 2) + power(feature_11 - 0.2784380316734314, 2) + power(feature_12 - -0.05557965114712715, 2) + power(feature_13 - -0.28433677554130554, 2) + power(feature_14 - 0.003816460259258747, 2) + power(feature_15 - -0.004081043414771557, 2) + power(feature_16 - 0.14893895387649536, 2) + power(feature_17 - -0.12637391686439514, 2) + power(feature_18 - -0.0776168555021286, 2) + power(feature_19 - -0.07115891575813293, 2) + power(feature_20 - 0.013110934756696224, 2) + power(feature_21 - -0.03728703036904335, 2) + power(feature_22 - 0.0312555767595768, 2) + power(feature_23 - -0.013231765478849411, 2) + power(feature_24 - 0.08345625549554825, 2) + power(feature_25 - -0.14501842856407166, 2) + power(feature_26 - -0.3354545533657074, 2) + power(feature_27 - -0.06517831236124039, 2) + power(feature_28 - -0.16320215165615082, 2) + power(feature_29 - -0.029647808521986008, 2) + power(feature_30 - -0.026274608448147774, 2) + power(feature_31 - 0.008217697963118553, 2) + power(feature_32 - 0.09989964962005615, 2) + power(feature_33 - -0.10960874706506729, 2) + power(feature_34 - -0.04241098091006279, 2) + power(feature_35 - 0.03659277781844139, 2) + power(feature_36 - 0.05843937397003174, 2) + power(feature_37 - -0.1882062405347824, 2) + power(feature_38 - -0.1472000777721405, 2) + power(feature_39 - 0.1806768774986267, 2) + power(feature_40 - -0.047331131994724274, 2) + power(feature_41 - -0.1587458848953247, 2) + power(feature_42 - -0.03949886932969093, 2) + power(feature_43 - 0.025885790586471558, 2) + power(feature_44 - 0.23678790032863617, 2) + power(feature_45 - 0.10318232327699661, 2) + power(feature_46 - -0.02302492968738079, 2) + power(feature_47 - 0.1084280014038086, 2) + power(feature_48 - -0.047027621418237686, 2) + power(feature_49 - 0.07425221800804138, 2) + power(feature_50 - -0.2947121560573578, 2) + power(feature_51 - 0.0031417328864336014, 2) + power(feature_52 - 0.121400848031044, 2) + power(feature_53 - 0.07688573747873306, 2) + power(feature_54 - 0.09685630351305008, 2) + power(feature_55 - 0.10917495936155319, 2) + power(feature_56 - -0.1276204138994217, 2) + power(feature_57 - 0.08362210541963577, 2) + power(feature_58 - 0.16328635811805725, 2) + power(feature_59 - -0.25213390588760376, 2) + power(feature_60 - 0.05785408616065979, 2) + power(feature_61 - 0.018559012562036514, 2) + power(feature_62 - -0.01683107763528824, 2) + power(feature_63 - -0.01742824725806713, 2) + power(feature_64 - -0.1193951666355133, 2) + power(feature_65 - 0.2622459828853607, 2) + power(feature_66 - 0.12121666967868805, 2) + power(feature_67 - -0.1520567685365677, 2) + power(feature_68 - -0.1122896820306778, 2) + power(feature_69 - 0.14081937074661255, 2) + power(feature_70 - -0.14206485450267792, 2) + power(feature_71 - -0.10112465173006058, 2) + power(feature_72 - 0.07290071249008179, 2) + power(feature_73 - -0.16641031205654144, 2) + power(feature_74 - -0.21917763352394104, 2) + power(feature_75 - -0.25251486897468567, 2) + power(feature_76 - -0.0048762112855911255, 2) + power(feature_77 - 0.37720248103141785, 2) + power(feature_78 - 0.1548663228750229, 2) + power(feature_79 - -0.12398210912942886, 2) + power(feature_80 - 0.041234225034713745, 2) + power(feature_81 - -0.06544441729784012, 2) + power(feature_82 - -0.09197349101305008, 2) + power(feature_83 - -0.021058330312371254, 2) + power(feature_84 - 0.039639901369810104, 2) + power(feature_85 - -0.0023813657462596893, 2) + power(feature_86 - -0.07752023637294769, 2) + power(feature_87 - -0.03788585215806961, 2) + power(feature_88 - 0.01571604609489441, 2) + power(feature_89 - 0.22586794197559357, 2) + power(feature_90 - -0.08962416648864746, 2) + power(feature_91 - 0.027185270562767982, 2) + power(feature_92 - 0.21015749871730804, 2) + power(feature_93 - 0.014571629464626312, 2) + power(feature_94 - -0.03427625447511673, 2) + power(feature_95 - -0.031976763159036636, 2) + power(feature_96 - -0.02412014827132225, 2) + power(feature_97 - -0.0572514683008194, 2) + power(feature_98 - 0.025131937116384506, 2) + power(feature_99 - -0.055663101375103, 2) + power(feature_100 - 0.06940365582704544, 2) + power(feature_101 - -0.008616405539214611, 2) + power(feature_102 - -0.08647502958774567, 2) + power(feature_103 - -0.002743437420576811, 2) + power(feature_104 - 0.06195132061839104, 2) + power(feature_105 - -0.21810059249401093, 2) + power(feature_106 - 0.18355928361415863, 2) + power(feature_107 - 0.028437575325369835, 2) + power(feature_108 - -0.02596919797360897, 2) + power(feature_109 - 0.03891913592815399, 2) + power(feature_110 - 0.017703840509057045, 2) + power(feature_111 - -0.14867563545703888, 2) + power(feature_112 - -0.035795167088508606, 2) + power(feature_113 - 0.21177658438682556, 2) + power(feature_114 - -0.3009713888168335, 2) + power(feature_115 - 0.20549386739730835, 2) + power(feature_116 - 0.15210166573524475, 2) + power(feature_117 - 0.1311473250389099, 2) + power(feature_118 - 0.1054188460111618, 2) + power(feature_119 - 0.017464492470026016, 2) + power(feature_120 - -0.011423288844525814, 2) + power(feature_121 - -0.0072870198637247086, 2) + power(feature_122 - -0.021593499928712845, 2) + power(feature_123 - -0.21365071833133698, 2) + power(feature_124 - -0.09368597716093063, 2) + power(feature_125 - 0.06633836776018143, 2) + power(feature_126 - -0.05478530377149582, 2) + power(feature_127 - -0.009351606480777264, 2) + power(feature_128 - 0.04693271964788437, 2) )) as distance
from storage_faceencoding ORDER BY distance LIMIT 5