From fb12a17f1bb66ede396d0cc92dc58e05ad1e0893 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Mon, 30 Sep 2024 16:29:11 +0800 Subject: [PATCH] Enable vector search tests --- tests/fullstack-test2/vector/distance.test | 3 +- .../vector/vector-index-on-create.test | 69 +++++++++++++++++++ .../fullstack-test2/vector/vector-index.test | 3 +- 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 tests/fullstack-test2/vector/vector-index-on-create.test diff --git a/tests/fullstack-test2/vector/distance.test b/tests/fullstack-test2/vector/distance.test index e838281cee2..e655c472249 100644 --- a/tests/fullstack-test2/vector/distance.test +++ b/tests/fullstack-test2/vector/distance.test @@ -11,8 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -#TODO: enable vector-index fullstack test -#RETURN + # Preparation. mysql> drop table if exists test.t; diff --git a/tests/fullstack-test2/vector/vector-index-on-create.test b/tests/fullstack-test2/vector/vector-index-on-create.test new file mode 100644 index 00000000000..5909157bcb5 --- /dev/null +++ b/tests/fullstack-test2/vector/vector-index-on-create.test @@ -0,0 +1,69 @@ +# Copyright 2024 PingCAP, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Preparation. +mysql> drop table if exists test.t; + +# Build vector index on create, it should automatically add tiflash replica and return quickly +mysql> CREATE TABLE test.t (`v` vector(5) DEFAULT NULL, VECTOR INDEX idx_v_l2 USING HNSW ((VEC_L2_DISTANCE(data))), VECTOR INDEX idx_v_cos USING HNSW ((VEC_COSINE_DISTANCE(data))) ); +func> wait_table test t +mysql> drop table if exists test.t; + +# Build vector index on table with data on the stable layer +mysql> CREATE TABLE test.t (`v` vector(5) DEFAULT NULL, VECTOR INDEX idx_v_l2 USING HNSW ((VEC_L2_DISTANCE(data))), VECTOR INDEX idx_v_cos USING HNSW ((VEC_COSINE_DISTANCE(data))) ); +#TODO: support "negative inner product" and "L1" +# mysql> CREATE TABLE test.t (`v` vector(5) DEFAULT NULL, VECTOR INDEX idx_v_l2 USING HNSW ((VEC_L2_DISTANCE(data))), VECTOR INDEX idx_v_cos USING HNSW ((VEC_COSINE_DISTANCE(data))), VECTOR INDEX idx_v_nip USING HNSW ((VEC_NEGATIVE_INNER_PRODUCT(data))), VECTOR INDEX idx_v_l1 USING HNSW ((VEC_L1_DISTANCE(data))) ); +mysql> INSERT INTO test.t VALUES ('[8.7, 5.7, 7.7, 9.8, 1.5]'),('[3.6, 9.7, 2.4, 6.6, 4.9]'),('[4.7, 4.9, 2.6, 5.2, 7.4]'),('[7.7, 6.7, 8.3, 7.8, 5.7]'),('[1.4, 4.5, 8.5, 7.7, 6.2]'); +func> wait_table test t + +mysql> set tidb_isolation_read_engines='tiflash';SELECT * FROM test.t ORDER BY VEC_L2_DISTANCE(v, '[1.0,4.0,8.0,7.0,6.0]') LIMIT 3; ++-----------------------+ +| v | ++-----------------------+ +| [1.4,4.5,8.5,7.7,6.2] | +| [4.7,4.9,2.6,5.2,7.4] | +| [7.7,6.7,8.3,7.8,5.7] | ++-----------------------+ + +mysql> set tidb_isolation_read_engines='tiflash';SELECT * FROM test.t ORDER BY VEC_COSINE_DISTANCE(v, '[1.0,4.0,8.0,7.0,6.0]') LIMIT 3; ++-----------------------+ +| v | ++-----------------------+ +| [1.4,4.5,8.5,7.7,6.2] | +| [7.7,6.7,8.3,7.8,5.7] | +| [4.7,4.9,2.6,5.2,7.4] | ++-----------------------+ + +#RETURN + +mysql> set tidb_isolation_read_engines='tiflash';SELECT * FROM test.t ORDER BY VEC_NEGATIVE_INNER_PRODUCT(v, '[1.0,4.0,8.0,7.0,6.0]') LIMIT 3; ++-----------------------+ +| v | ++-----------------------+ +| [7.7,6.7,8.3,7.8,5.7] | +| [1.4,4.5,8.5,7.7,6.2] | +| [8.7,5.7,7.7,9.8,1.5] | ++-----------------------+ + +mysql> set tidb_isolation_read_engines='tiflash';SELECT * FROM test.t ORDER BY VEC_L1_DISTANCE(v, '[1.0,4.0,8.0,7.0,6.0]') LIMIT 3; ++-----------------------+ +| v | ++-----------------------+ +| [1.4,4.5,8.5,7.7,6.2] | +| [7.7,6.7,8.3,7.8,5.7] | +| [4.7,4.9,2.6,5.2,7.4] | ++-----------------------+ + +# Cleanup +mysql> drop table if exists test.t diff --git a/tests/fullstack-test2/vector/vector-index.test b/tests/fullstack-test2/vector/vector-index.test index 77fd1431cbc..2114b6ab6be 100644 --- a/tests/fullstack-test2/vector/vector-index.test +++ b/tests/fullstack-test2/vector/vector-index.test @@ -11,8 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -#TODO: enable vector-index fullstack test -#RETURN + # Preparation. mysql> drop table if exists test.t;