-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a198f1
commit fb12a17
Showing
3 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters