下载
GitHub - pgvector/pgvector: Open-source vector similarity search for Postgres
源码编译
##文件解压缩
unzip pgvector-0.6.2.zip
##编译
make && make install
功能验证
#安装扩展CREATE EXTENSION vector;#创建测试表CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));#创建分布式表SELECT create_distributed_table('items', 'id');#插入测试数据INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]'), ('[2,2,4]'), ('[3,1,4]'), ('[4,2,5]');#按与给定向量相似度(L2 distance)排序,显示前5条SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;SELECT embedding <-> '[1,2,3]' AS distance FROM items;