ClickHouse/tests/performance/norm_distance.xml
Robert Schulze 25fb44f16d
Extend performance test norm_dist.xml
Dimension = 200 (instead of 10) is more realistic for vector search use cases.
2024-01-19 13:09:08 +00:00

143 lines
11 KiB
XML

<test>
<substitutions>
<substitution>
<name>element_type</name>
<values>
<value>UInt8</value>
<value>Int16</value>
<value>Int32</value>
<value>Int64</value>
<value>Float32</value>
<value>Float64</value>
</values>
</substitution>
</substitutions>
<create_query>
CREATE TABLE vecs_{element_type} (
v Array({element_type})
) ENGINE=Memory;
</create_query>
<!-- Gererate arrays with random data -->
<!-- Dimension = 200 is realistic for vector search use cases -->
<fill_query>
INSERT INTO vecs_{element_type}
SELECT v FROM (
SELECT
number AS n,
[
rand(n*10), rand(n*10+1), rand(n*10+2), rand(n*10+3), rand(n*10+4), rand(n*10+5), rand(n*10+6), rand(n*10+7), rand(n*10+8), rand(n*10+9),
rand(n*10+10), rand(n*10+11), rand(n*10+12), rand(n*10+13), rand(n*10+14), rand(n*10+15), rand(n*10+16), rand(n*10+17), rand(n*10+18), rand(n*10+19),
rand(n*10+20), rand(n*10+21), rand(n*10+22), rand(n*10+23), rand(n*10+24), rand(n*10+25), rand(n*10+26), rand(n*10+27), rand(n*10+28), rand(n*10+29),
rand(n*10+30), rand(n*10+31), rand(n*10+32), rand(n*10+33), rand(n*10+34), rand(n*10+35), rand(n*10+36), rand(n*10+37), rand(n*10+38), rand(n*10+39),
rand(n*10+40), rand(n*10+41), rand(n*10+42), rand(n*10+43), rand(n*10+44), rand(n*10+45), rand(n*10+46), rand(n*10+47), rand(n*10+48), rand(n*10+49),
rand(n*10+50), rand(n*10+51), rand(n*10+52), rand(n*10+53), rand(n*10+54), rand(n*10+55), rand(n*10+56), rand(n*10+57), rand(n*10+58), rand(n*10+59),
rand(n*10+60), rand(n*10+61), rand(n*10+62), rand(n*10+63), rand(n*10+64), rand(n*10+65), rand(n*10+66), rand(n*10+67), rand(n*10+68), rand(n*10+69),
rand(n*10+70), rand(n*10+71), rand(n*10+72), rand(n*10+73), rand(n*10+74), rand(n*10+75), rand(n*10+76), rand(n*10+77), rand(n*10+78), rand(n*10+79),
rand(n*10+80), rand(n*10+81), rand(n*10+82), rand(n*10+83), rand(n*10+84), rand(n*10+85), rand(n*10+86), rand(n*10+87), rand(n*10+88), rand(n*10+89),
rand(n*10+90), rand(n*10+91), rand(n*10+92), rand(n*10+93), rand(n*10+94), rand(n*10+95), rand(n*10+96), rand(n*10+97), rand(n*10+98), rand(n*10+99),
rand(n*10+100), rand(n*10+101), rand(n*10+102), rand(n*10+103), rand(n*10+104), rand(n*10+105), rand(n*10+106), rand(n*10+107), rand(n*10+108), rand(n*10+109),
rand(n*10+110), rand(n*10+111), rand(n*10+112), rand(n*10+113), rand(n*10+114), rand(n*10+115), rand(n*10+116), rand(n*10+117), rand(n*10+118), rand(n*10+119),
rand(n*10+120), rand(n*10+121), rand(n*10+122), rand(n*10+123), rand(n*10+124), rand(n*10+125), rand(n*10+126), rand(n*10+127), rand(n*10+128), rand(n*10+129),
rand(n*10+130), rand(n*10+131), rand(n*10+132), rand(n*10+133), rand(n*10+134), rand(n*10+135), rand(n*10+136), rand(n*10+137), rand(n*10+138), rand(n*10+139),
rand(n*10+140), rand(n*10+141), rand(n*10+142), rand(n*10+143), rand(n*10+144), rand(n*10+145), rand(n*10+146), rand(n*10+147), rand(n*10+148), rand(n*10+149),
rand(n*10+150), rand(n*10+151), rand(n*10+152), rand(n*10+153), rand(n*10+154), rand(n*10+155), rand(n*10+156), rand(n*10+157), rand(n*10+158), rand(n*10+159),
rand(n*10+160), rand(n*10+161), rand(n*10+162), rand(n*10+163), rand(n*10+164), rand(n*10+165), rand(n*10+166), rand(n*10+167), rand(n*10+168), rand(n*10+169),
rand(n*10+170), rand(n*10+170), rand(n*10+172), rand(n*10+173), rand(n*10+174), rand(n*10+175), rand(n*10+176), rand(n*10+177), rand(n*10+178), rand(n*10+179),
rand(n*10+180), rand(n*10+181), rand(n*10+182), rand(n*10+183), rand(n*10+184), rand(n*10+185), rand(n*10+186), rand(n*10+187), rand(n*10+188), rand(n*10+189),
rand(n*10+190), rand(n*10+191), rand(n*10+192), rand(n*10+193), rand(n*10+194), rand(n*10+195), rand(n*10+196), rand(n*10+197), rand(n*10+198), rand(n*10+199)
] AS v
FROM system.numbers
LIMIT 10000000
);
</fill_query>
<!-- The same data in the form of tuples -->
<create_query>
CREATE TABLE tuples_{element_type} (
t Tuple(
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type},
{element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}, {element_type}
)
) ENGINE=Memory;
</create_query>
<fill_query>
INSERT INTO tuples_{element_type}
SELECT (
v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10],
v[11], v[12], v[13], v[14], v[15], v[16], v[17], v[18], v[19], v[20],
v[21], v[22], v[23], v[24], v[25], v[26], v[27], v[28], v[29], v[30],
v[31], v[32], v[33], v[34], v[35], v[36], v[37], v[38], v[39], v[40],
v[41], v[42], v[43], v[44], v[45], v[46], v[47], v[48], v[49], v[50],
v[51], v[52], v[53], v[54], v[55], v[56], v[57], v[58], v[59], v[60],
v[61], v[62], v[63], v[64], v[65], v[66], v[67], v[68], v[69], v[70],
v[71], v[72], v[73], v[74], v[75], v[76], v[77], v[78], v[79], v[80],
v[81], v[82], v[83], v[84], v[85], v[86], v[87], v[88], v[89], v[90],
v[91], v[92], v[93], v[94], v[95], v[96], v[97], v[98], v[99], v[100],
v[101], v[102], v[103], v[104], v[105], v[106], v[107], v[108], v[109], v[110],
v[111], v[112], v[113], v[114], v[115], v[116], v[117], v[118], v[119], v[120],
v[121], v[122], v[123], v[124], v[125], v[126], v[127], v[128], v[129], v[130],
v[131], v[132], v[133], v[134], v[135], v[136], v[137], v[138], v[139], v[140],
v[141], v[142], v[143], v[144], v[145], v[146], v[147], v[148], v[149], v[150],
v[151], v[152], v[153], v[154], v[155], v[156], v[157], v[158], v[159], v[160],
v[161], v[162], v[163], v[164], v[165], v[166], v[167], v[168], v[169], v[170],
v[171], v[172], v[173], v[174], v[175], v[176], v[177], v[178], v[179], v[180],
v[181], v[182], v[183], v[184], v[185], v[186], v[187], v[188], v[189], v[190],
v[191], v[192], v[193], v[194], v[195], v[196], v[197], v[198], v[199], v[200]
) FROM vecs_{element_type};
</fill_query>
<settings>
<max_threads>1</max_threads>
</settings>
<!-- Norm kinds-->
<substitutions>
<substitution>
<name>norm</name>
<values>
<value>L1</value>
<value>L2</value>
<value>Linf</value>
</values>
</substitution>
</substitutions>
<!-- Tuples -->
<query>SELECT sum(dist) FROM (SELECT {norm}Norm(t) AS dist FROM tuples_{element_type})</query>
<query>WITH (SELECT t FROM tuples_{element_type} limit 1) AS a SELECT sum(dist) FROM (SELECT {norm}Distance(a, t) AS dist FROM tuples_{element_type})</query>
<query>WITH (SELECT t FROM tuples_{element_type} limit 1) AS a SELECT sum(dist) FROM (SELECT cosineDistance(a, t) AS dist FROM tuples_{element_type})</query>
<!-- Arrays -->
<query>SELECT sum(dist) FROM (SELECT {norm}Norm(v) AS dist FROM vecs_{element_type})</query>
<query>WITH (SELECT v FROM vecs_{element_type} limit 1) AS a SELECT sum(dist) FROM (SELECT {norm}Distance(a, v) AS dist FROM vecs_{element_type})</query>
<query>WITH (SELECT v FROM vecs_{element_type} limit 1) AS a SELECT sum(dist) FROM (SELECT cosineDistance(a, v) AS dist FROM vecs_{element_type})</query>
<drop_query>DROP TABLE vecs_{element_type}</drop_query>
<drop_query>DROP TABLE tuples_{element_type}</drop_query>
</test>