【 使用环境 】生产环境 or 测试环境
【 OB or 其他组件 】ob
【 使用版本 】4.3.4.1
【问题描述】
执行的sql
select
id
from image_search
order by cosine_distance(embedding,#{embedding})
limit 100
总共278w行数据。
表总大小574MB。
查询一次耗时接近18s
表结构:
CREATE TABLE image_search
(
id
int(11) NOT NULL AUTO_INCREMENT,
product_id
int(11) NOT NULL DEFAULT ‘0’ COMMENT ‘业务关联id’,
image_id
int(11) NOT NULL DEFAULT ‘0’ COMMENT ‘图片表id:image_info表id’,
original
int(11) NOT NULL DEFAULT ‘0’ COMMENT ‘图片业务来源代码’,
int_attr1
int(11) DEFAULT ‘0’ COMMENT ‘检索字段 - int类型1’,
int_attr2
int(11) DEFAULT ‘0’ COMMENT ‘检索字段 - int类型2’,
int_attr3
int(11) DEFAULT ‘0’ COMMENT ‘检索字段 - int类型3’,
str_attr1
varchar(20) DEFAULT ‘’ COMMENT ‘检索字段- str类型1’,
str_attr2
varchar(20) DEFAULT ‘’ COMMENT ‘检索字段- str类型2’,
str_attr3
varchar(20) DEFAULT ‘’ COMMENT ‘检索字段- str类型3’,
embedding
VECTOR(512) DEFAULT NULL,
create_time
timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
modify_time
timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
PRIMARY KEY (id
),
UNIQUE KEY uniq_product_id_image_id_original
(product_id
, image_id
, original
) BLOCK_SIZE 16384 LOCAL,
VECTOR KEY img_embedding_idx
(embedding
) WITH (DISTANCE=L2, TYPE=HNSW, LIB=VSAG, M=16, EF_CONSTRUCTION=200, EF_SEARCH=64) BLOCK_SIZE 16384
)