Skip to content

Commit

Permalink
Enable vector search tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Sep 30, 2024
1 parent 2a198f1 commit fb12a17
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
3 changes: 1 addition & 2 deletions tests/fullstack-test2/vector/distance.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
69 changes: 69 additions & 0 deletions tests/fullstack-test2/vector/vector-index-on-create.test
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions tests/fullstack-test2/vector/vector-index.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fb12a17

Please sign in to comment.