当前位置: 首页 > news >正文

PostgreSQL 向量扩展插件pgvector安装和使用

文章目录

  • PostgreSQL 向量扩展插件pgvector安装和使用
    • 安装postgresql
    • pgvector下载和安装
    • 安装错误调试
      • 错误调试1
        • 尝试解决 AP1 :启动postgresql
      • 错误调试2
        • 尝试解决 AP2 : 使用apt-get install postgresql-server
      • 错误调试3
        • 尝试解决 AP3 :卸载apt-get 安装
      • 错误调试4
        • 设置环境变量PG_CONFIG
      • 编译成功
    • 使用pgvector
      • 测试例
      • 列出当前数据库中已安装的扩展(extensions)
  • 参考

PostgreSQL 向量扩展插件pgvector安装和使用

pgvector 是一个 PostgreSQL 扩展,能够让PostgreSQL 提供向量(vector)数据类型和相关操作功能。

参考:
https://github.com/pgvector/pgvector

安装postgresql

利用pgvector 前提是事先安装好postgresql,安装postgresql例可参考下文。

参考:
Linux(Ubuntu)源码安装postgresql16.3
https://editor.csdn.net/md/?articleId=142500497

pgvector下载和安装

安装命令如下:

cd 
git clone --branch v0.7.4 https://github.com/pgvector/pgvector.git
cd pgvector
make
make install # may need sudo

参考:
https://github.com/pgvector/pgvector

例:下载

root@autodl-container-616f40a3b3-41cb82d9:~#  su - postgres
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pwd
/var/lib/postgresql
postgres@autodl-container-616f40a3b3-41cb82d9:~$ ls
10  pgsql16  postgresql-16.3  postgresql-16.3.tar.gz
postgres@autodl-container-616f40a3b3-41cb82d9:~$ git clone --branch v0.7.4 https://github.com/pgvector/pgvector.git
Cloning into 'pgvector'...
remote: Enumerating objects: 10650, done.
remote: Counting objects: 100% (4165/4165), done.
remote: Compressing objects: 100% (954/954), done.
remote: Total 10650 (delta 3388), reused 3493 (delta 3193), pack-reused 6485 (from 1)
Receiving objects: 100% (10650/10650), 1.60 MiB | 544.00 KiB/s, done.
Resolving deltas: 100% (7952/7952), done.
Note: checking out '103ac50f1a90b47a72003e8e8628a55ec372f202'.You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:git checkout -b <new-branch-name>postgres@autodl-container-616f40a3b3-41cb82d9:~$

安装错误调试

错误调试1

尝试编译和安装
例:

postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
cp sql/vector.sql sql/vector--0.7.4.sql

编译时候汇报如上错误可能是由于postgresql没有启动。

postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: Connection refusedIs the server running locally and accepting connections on that socket?
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ 
postgres@autodl-container-616f40a3b3-41cb82d9:~$ ps -xf|grep postgres1504 pts/3    S+     0:00  \_ grep postgres
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pg_ctl -D /var/lib/postgresql/pgsql16/data status
pg_ctl: no server running
尝试解决 AP1 :启动postgresql
postgres@autodl-container-616f40a3b3-41cb82d9:~$ pg_ctl -D /var/lib/postgresql/pgsql16/data -l logfile start
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... done
server started
postgres@autodl-container-616f40a3b3-41cb82d9:~$  ps -xf|grep postgres1197 pts/0    S+     0:00  \_ grep postgres1188 ?        Ss     0:00 /var/lib/postgresql/pgsql16/bin/postgres -D /var/lib/postgresql/pgsql16/data1189 ?        Ss     0:00  \_ postgres: checkpointer 1190 ?        Ss     0:00  \_ postgres: background writer 1192 ?        Ss     0:00  \_ postgres: walwriter 1193 ?        Ss     0:00  \_ postgres: autovacuum launcher 1194 ?        Ss     0:00  \_ postgres: logical replication launcher 
postgres@autodl-container-616f40a3b3-41cb82d9:~$  psql
psql (16.3)
Type "help" for help.postgres=# help
You are using psql, the command-line interface to PostgreSQL.
Type:  \copyright for distribution terms\h for help with SQL commands\? for help with psql commands\g or terminate with semicolon to execute query\q to quit
postgres=# 

错误调试2

再次编译,出错。

postgres@autodl-container-616f40a3b3-41cb82d9:~$ pwd
/var/lib/postgresql
postgres@autodl-container-616f40a3b3-41cb82d9:~$ cd pgvector
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ 
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
make: Nothing to be done for 'all'.
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ postgres --version
postgres (PostgreSQL) 16.3
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ psql --version
psql (PostgreSQL) 16.3

无法识别postgresql-server-dev-X.Y 。

尝试解决 AP2 : 使用apt-get install postgresql-server
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ apt-get install postgresql-server*
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ exit
logout
root@autodl-container-616f40a3b3-41cb82d9:~# apt-get install postgresql-server*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'postgresql-server-dev-all' for glob 'postgresql-server*'
Note, selecting 'postgresql-server' for glob 'postgresql-server*'
Note, selecting 'postgresql-server-dev-10' for glob 'postgresql-server*'
The following additional packages will be installed:dctrl-tools iproute2 libatm1 libmnl0 libpq-dev libxtables12
Suggested packages:debtags iproute2-doc postgresql-doc-10
The following NEW packages will be installed:dctrl-tools iproute2 libatm1 libmnl0 libpq-dev libxtables12 postgresql-server-dev-10 postgresql-server-dev-all
0 upgraded, 8 newly installed, 0 to remove and 169 not upgraded.
Need to get 1983 kB of archives.
After this operation, 10.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://repo.huaweicloud.com/ubuntu bionic/main amd64 libmnl0 amd64 1.0.4-2 [12.3 kB]
Get:2 https://repo.huaweicloud.com/ubuntu bionic-updates/main amd64 iproute2 amd64 4.15.0-2ubuntu1.3 [721 kB]
Get:3 https://repo.huaweicloud.com/ubuntu bionic/main amd64 libatm1 amd64 1:2.5.1-2build1 [21.9 kB]
Get:4 https://repo.huaweicloud.com/ubuntu bionic-updates/main amd64 libxtables12 amd64 1.6.1-2ubuntu2.1 [28.1 kB]
Get:5 https://repo.huaweicloud.com/ubuntu bionic/main amd64 dctrl-tools amd64 2.24-2build1 [60.9 kB]
Get:6 https://repo.huaweicloud.com/ubuntu bionic-security/main amd64 libpq-dev amd64 10.23-0ubuntu0.18.04.2 [219 kB]
Get:7 https://repo.huaweicloud.com/ubuntu bionic-security/universe amd64 postgresql-server-dev-10 amd64 10.23-0ubuntu0.18.04.2 [905 kB]
Get:8 https://repo.huaweicloud.com/ubuntu bionic-security/universe amd64 postgresql-server-dev-all all 190ubuntu0.1 [14.1 kB]
Fetched 1983 kB in 1s (3436 kB/s)                     
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libmnl0:amd64.
(Reading database ... 44409 files and directories currently installed.)
Preparing to unpack .../0-libmnl0_1.0.4-2_amd64.deb ...
Unpacking libmnl0:amd64 (1.0.4-2) ...
Selecting previously unselected package iproute2.
Preparing to unpack .../1-iproute2_4.15.0-2ubuntu1.3_amd64.deb ...
Unpacking iproute2 (4.15.0-2ubuntu1.3) ...
Selecting previously unselected package libatm1:amd64.
Preparing to unpack .../2-libatm1_1%3a2.5.1-2build1_amd64.deb ...
Unpacking libatm1:amd64 (1:2.5.1-2build1) ...
Selecting previously unselected package libxtables12:amd64.
Preparing to unpack .../3-libxtables12_1.6.1-2ubuntu2.1_amd64.deb ...
Unpacking libxtables12:amd64 (1.6.1-2ubuntu2.1) ...
Selecting previously unselected package dctrl-tools.
Preparing to unpack .../4-dctrl-tools_2.24-2build1_amd64.deb ...
Unpacking dctrl-tools (2.24-2build1) ...
Selecting previously unselected package libpq-dev.
Preparing to unpack .../5-libpq-dev_10.23-0ubuntu0.18.04.2_amd64.deb ...
Unpacking libpq-dev (10.23-0ubuntu0.18.04.2) ...
Selecting previously unselected package postgresql-server-dev-10.
Preparing to unpack .../6-postgresql-server-dev-10_10.23-0ubuntu0.18.04.2_amd64.deb ...
Unpacking postgresql-server-dev-10 (10.23-0ubuntu0.18.04.2) ...
Selecting previously unselected package postgresql-server-dev-all.
Preparing to unpack .../7-postgresql-server-dev-all_190ubuntu0.1_all.deb ...
Unpacking postgresql-server-dev-all (190ubuntu0.1) ...
Setting up libpq-dev (10.23-0ubuntu0.18.04.2) ...
Setting up dctrl-tools (2.24-2build1) ...
Setting up postgresql-server-dev-10 (10.23-0ubuntu0.18.04.2) ...
Setting up libatm1:amd64 (1:2.5.1-2build1) ...
Setting up libxtables12:amd64 (1.6.1-2ubuntu2.1) ...
Setting up libmnl0:amd64 (1.0.4-2) ...
Setting up iproute2 (4.15.0-2ubuntu1.3) ...
Setting up postgresql-server-dev-all (190ubuntu0.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.2) ...
root@autodl-container-616f40a3b3-41cb82d9:~# 

安装的版本不是最新的版本而是10.23。

错误调试3

再次编译。


postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -g -g -O2 -fdebug-prefix-map=/build/postgresql-10-XHR5kl/postgresql-10-10.23=. -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -I. -I./ -I/usr/include/postgresql/10/server -I/usr/include/postgresql/internal  -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include/mit-krb5  -c -o src/bitutils.o src/bitutils.c
In file included from src/bitutils.c:3:0:
src/bitutils.h:8:2: error: #error "Requires PostgreSQL 12+"#error "Requires PostgreSQL 12+"^~~~~
src/bitutils.c:5:10: fatal error: port/pg_bitutils.h: No such file or directory#include "port/pg_bitutils.h"^~~~~~~~~~~~~~~~~~~~
compilation terminated.
<builtin>: recipe for target 'src/bitutils.o' failed
make: *** [src/bitutils.o] Error 1
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ 

make编译调用的postgresql不是之前安装的 16.3,而是apt-get 安装的10.23版本。

尝试解决 AP3 :卸载apt-get 安装

卸载apt-get 安装的10.23版本

参考:
卸载apt-get 安装的PostgreSQL版本
https://blog.csdn.net/lukeUnique/article/details/142610650

错误调试4

再次编译。

root@autodl-container-616f40a3b3-41cb82d9:~# su - postgres
postgres@autodl-container-616f40a3b3-41cb82d9:~$ cd /var/lib/postgresql/pgvector
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ ls
CHANGELOG.md  Dockerfile  LICENSE  META.json  Makefile  Makefile.win  README.md  logfile  sql  src  test  vector.control
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
Makefile:48: /usr/lib/postgresql/10/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory
make: *** No rule to make target '/usr/lib/postgresql/10/lib/pgxs/src/makefiles/pgxs.mk'.  Stop.
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ 

make编译pgvector时无法识别安装的postgresql。

设置环境变量PG_CONFIG

为了让make命令找到安装的postgresql 16.3版本。
重新修改.bash_profile,配置PG_CONFIG和LD_LIBRARY_PATH,指定安装的postgresql 16.3版本。

例:

$ vi .bash_profile

修改成如下内容。

# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi# User specific environment and startup programs
export PG_HOME=/var/lib/postgresql/pgsql16
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/var/lib/postgresql/pgsql16/lib
export PG_CONFIG=/var/lib/postgresql/pgsql16/bin/pg_config
export PGDATA=/var/lib/postgresql/pgsql16/data
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PG_HOME/bin
alias psql='/var/lib/postgresql/pgsql16/bin/psql'
export PATH

编译成功

根据上面的错误调试过程,我们可以看到在编译时候需要配置PG_CONFIG。

root@autodl-container-616f40a3b3-41cb82d9:~# su - postgres
postgres@autodl-container-616f40a3b3-41cb82d9:~$ ls
logfile  pgsql16  pgvector  postgresql-16.3  postgresql-16.3.tar.gz
postgres@autodl-container-616f40a3b3-41cb82d9:~$ cd pgvector
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ ls
CHANGELOG.md  Dockerfile  LICENSE  META.json  Makefile  Makefile.win  README.md  logfile  sql  src  test  vector.control
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/bitutils.o src/bitutils.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/bitvec.o src/bitvec.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/halfutils.o src/halfutils.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/halfvec.o src/halfvec.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/hnsw.o src/hnsw.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/hnswbuild.o src/hnswbuild.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/hnswinsert.o src/hnswinsert.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/hnswscan.o src/hnswscan.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/hnswutils.o src/hnswutils.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/hnswvacuum.o src/hnswvacuum.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfbuild.o src/ivfbuild.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfflat.o src/ivfflat.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfinsert.o src/ivfinsert.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfkmeans.o src/ivfkmeans.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfscan.o src/ivfscan.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfutils.o src/ivfutils.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/ivfvacuum.o src/ivfvacuum.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/sparsevec.o src/sparsevec.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -I. -I./ -I/var/lib/postgresql/pgsql16/include/server -I/var/lib/postgresql/pgsql16/include/internal  -D_GNU_SOURCE   -c -o src/vector.o src/vector.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -march=native -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math -fPIC -fvisibility=hidden -shared -o vector.so src/bitutils.o src/bitvec.o src/halfutils.o src/halfvec.o src/hnsw.o src/hnswbuild.o src/hnswinsert.o src/hnswscan.o src/hnswutils.o src/hnswvacuum.o src/ivfbuild.o src/ivfflat.o src/ivfinsert.o src/ivfkmeans.o src/ivfscan.o src/ivfutils.o src/ivfvacuum.o src/sparsevec.o src/vector.o -L/var/lib/postgresql/pgsql16/lib    -Wl,--as-needed -Wl,-rpath,'/var/lib/postgresql/pgsql16/lib',--enable-new-dtags  -fvisibility=hidden 
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ 

make install

postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$  make install
/bin/mkdir -p '/var/lib/postgresql/pgsql16/lib'
/bin/mkdir -p '/var/lib/postgresql/pgsql16/share/extension'
/bin/mkdir -p '/var/lib/postgresql/pgsql16/share/extension'
/usr/bin/install -c -m 755  vector.so '/var/lib/postgresql/pgsql16/lib/vector.so'
/usr/bin/install -c -m 644 .//vector.control '/var/lib/postgresql/pgsql16/share/extension/'
/usr/bin/install -c -m 644 .//sql/vector--0.5.0--0.5.1.sql .//sql/vector--0.1.3--0.1.4.sql .//sql/vector--0.1.1--0.1.3.sql .//sql/vector--0.4.3--0.4.4.sql .//sql/vector--0.1.7--0.1.8.sql .//sql/vector--0.2.0--0.2.1.sql .//sql/vector--0.1.5--0.1.6.sql .//sql/vector--0.5.1--0.6.0.sql .//sql/vector--0.3.1--0.3.2.sql .//sql/vector--0.1.8--0.2.0.sql .//sql/vector--0.2.6--0.2.7.sql .//sql/vector--0.3.0--0.3.1.sql .//sql/vector--0.4.2--0.4.3.sql .//sql/vector--0.6.2--0.7.0.sql .//sql/vector--0.1.4--0.1.5.sql .//sql/vector--0.2.7--0.3.0.sql .//sql/vector--0.6.0--0.6.1.sql .//sql/vector--0.4.1--0.4.2.sql .//sql/vector--0.7.3--0.7.4.sql .//sql/vector--0.4.0--0.4.1.sql .//sql/vector--0.7.1--0.7.2.sql .//sql/vector--0.1.0--0.1.1.sql .//sql/vector--0.2.3--0.2.4.sql .//sql/vector--0.1.6--0.1.7.sql .//sql/vector--0.3.2--0.4.0.sql .//sql/vector--0.2.5--0.2.6.sql .//sql/vector--0.4.4--0.5.0.sql .//sql/vector--0.2.1--0.2.2.sql .//sql/vector--0.7.2--0.7.3.sql .//sql/vector--0.7.0--0.7.1.sql .//sql/vector--0.2.2--0.2.3.sql .//sql/vector--0.6.1--0.6.2.sql .//sql/vector--0.2.4--0.2.5.sql sql/vector--0.7.4.sql '/var/lib/postgresql/pgsql16/share/extension/'
/bin/mkdir -p '/var/lib/postgresql/pgsql16/include/server/extension/vector/'
/usr/bin/install -c -m 644   .//src/halfvec.h .//src/sparsevec.h .//src/vector.h '/var/lib/postgresql/pgsql16/include/server/extension/vector/'
postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ 

pgvector的安装成功。

使用pgvector

使用参考https://github.com/pgvector/pgvector

Getting Started
Enable the extension (do this once in each database where you want to use it)CREATE EXTENSION vector;
Create a vector column with 3 dimensionsCREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
Insert vectorsINSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
Get the nearest neighbors by L2 distanceSELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;
Also supports inner product (<#>), cosine distance (<=>), and L1 distance (<+>, added in 0.7.0)Note: <#> returns the negative inner product since Postgres only supports ASC order index scans on operators

测试例

postgres@autodl-container-616f40a3b3-41cb82d9:~/pgvector$ psql
psql (16.3)
Type "help" for help.postgres=# CREATE EXTENSION vector;
CREATE EXTENSION
postgres=# CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
CREATE TABLE
postgres=# INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
INSERT 0 2
postgres=# SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;id | embedding 
----+-----------1 | [1,2,3]2 | [4,5,6]
(2 rows)

列出当前数据库中已安装的扩展(extensions)


postgres=# \dxList of installed extensionsName   | Version |   Schema   |                     Description                      
---------+---------+------------+------------------------------------------------------plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural languagevector  | 0.7.4   | public     | vector data type and ivfflat and hnsw access methods
(2 rows)postgres=# 

参考

实战PG vector 构建DBA 个人知识库之二: 向量数据库与 PG vector 介绍
https://pgfans.cn/a/3606

数据库技术核心:向量检索(pgvector)
https://blog.csdn.net/ChaoMing_H/article/details/141257149

PostgreSQL向量数据插件–pgvector安装(附PostgreSQL安装)
https://blog.csdn.net/m0_62627802/article/details/135027327

相关文章:

PostgreSQL 向量扩展插件pgvector安装和使用

文章目录 PostgreSQL 向量扩展插件pgvector安装和使用安装postgresqlpgvector下载和安装安装错误调试错误调试1尝试解决 AP1 &#xff1a;启动postgresql 错误调试2尝试解决 AP2 : 使用apt-get install postgresql-server 错误调试3尝试解决 AP3 &#xff1a;卸载apt-get 安装 …...

【论文阅读】基于真实数据感知的模型功能窃取攻击

摘要 目的 模型功能窃取攻击是人工智能安全领域的核心问题之一&#xff0c;目的是利用有限的与目标模型有关的信息训练出性能接近的克隆模型&#xff0c;从而实现模型的功能窃取。针对此类问题&#xff0c;一类经典的工作是基于生成模型的方法&#xff0c;这类方法利用生成器…...

线程池:线程池的实现 | 日志

&#x1f308;个人主页&#xff1a; 南桥几晴秋 &#x1f308;C专栏&#xff1a; 南桥谈C &#x1f308;C语言专栏&#xff1a; C语言学习系列 &#x1f308;Linux学习专栏&#xff1a; 南桥谈Linux &#x1f308;数据结构学习专栏&#xff1a; 数据结构杂谈 &#x1f308;数据…...

海信和TCL雷鸟智能电视的体验

买了型号为32E2F(9008)的海信智能的电视有一段时间了&#xff0c;要使用这个智能电视还真能考验你的智商。海信电视有很多优点&#xff0c;它的屏幕比较靓丽&#xff0c;色彩好看&#xff0c;遥控器不用对着屏幕就能操作。但也有不少缺点。 1. 海信智能电视会强迫自动更新操作…...

自动化学习3:日志记录及测试报告的生成--自动化框架搭建

一.日志记录 1.配置文件pytest.ini&#xff1a;将日志写入文件方便日后查询或查看执行信息。 需要将文件处理器&#xff08;文件存放位置/时间/格式等等&#xff09;添加到配置文件中的【日志记录器】 # pytest.ini [pytest] # ---------------日志文件&#xff0c;需要配合…...

【STM32单片机_(HAL库)】4-1【定时器TIM】定时器中断点灯实验

1.硬件 STM32单片机最小系统LED灯模块 2.软件 timer驱动文件添加定时器HAL驱动层文件添加GPIO常用函数定时器中断配置流程main.c程序 #include "sys.h" #include "delay.h" #include "led.h" #include "timer.h"int main(void) {H…...

Linux编译安装Mysql笔记

1.Mysql介绍 MySQL是一个广泛使用的开源关系型数据库管理系统&#xff08;RDBMS&#xff09;&#xff0c;它基于SQL&#xff08;Structured Query Language&#xff09;进行操作。MySQL是由瑞典MySQL AB公司开发的&#xff0c;后来被Sun Microsystems收购&#xff0c;最终成为…...

在java后端发送HTTPClient请求

简介 HttpClient遵循http协议的客户端编程工具包支持最新的http协议 部分依赖自动传递依赖了HttpClient的jar包 明明项目中没有引入 HttpClient 的Maven坐标&#xff0c;但是却可以直接使用HttpClient原因是&#xff1a;阿里云的sdk依赖中传递依赖了HttpClient的jar包 发送get请…...

【STM32单片机_(HAL库)】4-3-2【定时器TIM】测量按键按下时间1——编程实现捕获功能

测量按键按下时长思路 测量按键按下时间实验目的 使用定时器 2 通道 2 来捕获按键 &#xff08;按键接PA0&#xff09;按下时间&#xff0c;并通过串口打印。 计一个数的时间&#xff1a;1us&#xff0c;PSC71&#xff0c;ARR65535 下降沿捕获、输入通道 2 映射在 TI2 上、不分…...

MySQL:2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded

关于MySQL 客户端在尝试连接到 MySQL 服务器时报错&#xff1a;“2059 - Authentication plugin caching_sha2_password cannot be loaded”&#xff0c;具体是由于 MySQL 服务器默认使用的 caching_sha2_password 认证插件无法加载或不被当前客户端支持。 错误原因 MySQL 8.0…...

【JavaSE】反射、枚举、lambda表达式

目录 反射反射相关类获取类中属性相关方法常用获得类相关的方法示例常用获得类中属性相关的方法示例获得类中注解相关的方法 反射优缺点 枚举常用方法优缺点 枚举与反射lambda表达式语法函数式接口简化规则使用示例变量捕获集合中的应用优缺点 反射 Java的反射&#xff08;refl…...

P3227 [HNOI2013] 切糕

题意: n ∗ m n*m n∗m的矩阵,每个点可以选择一个值 a i , j k a_{i,j}k ai,j​k,然后你能获得 w ( i , j , k ) w(i,j,k) w(i,j,k)的得分&#xff0c;但是相邻两点之间的差值有限制&#xff0c;让你求最大得分。 考虑最小割。 每个点 ( i , j ) (i,j) (i,j)弄出一条长为 R…...

超分服务的分量保存

分量说明 分量的概念主要是对于显卡解码&#xff0c;编码和网络传输而言&#xff0c;显卡可以同时进行几个线程&#xff0c;多个显卡可以分布式计算&#xff0c;对分量进行AI识别&#xff0c;比如我们有cuda的显卡&#xff0c;cuda的核心量可以分给不同的分片视频&#xff0c;第…...

Windows11系统下SkyWalking环境搭建教程

目录 前言SkyWalking简介SkyWalking下载Agent监控实现启动配置SkyWalking启动Java应用程序启动Elasticsearch安装总结 前言 本文为博主在项目环境搭建时记录的SkyWalking安装流程&#xff0c;希望对大家能够有所帮助&#xff0c;不足之处欢迎批评指正&#x1f91d;&#x1f91…...

前端BOM常用操作

BOM操作常用命令详解及代码案例 BOM&#xff08;Browser Object Model&#xff09;是浏览器对象模型&#xff0c;是浏览器提供的JavaScript操作浏览器的API。BOM提供了与网页无关的浏览器的功能对象&#xff0c;虽然没有正式的标准&#xff0c;但现代浏览器已经几乎实现了Java…...

【Go】-viper库的使用

目录 viper简介 viper使用 通过viper.Set设置值 读取配置文件说明 读取配置文件 读取多个配置文件 读取配置项的值 读取命令行的值 io.Reader中读取值 写配置文件 WriteConfig() 和 SafeWriteConfig() 区别: viper简介 配置管理解析库&#xff0c;是由大神 Steve Fr…...

JavaWeb酒店管理系统(详细版)

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…...

C++ | 定长内存池 | 对象池

文章目录 C | 定长内存池 | 对象池一、内存池的引入二、代码中的内存池实现 - ObjectPool类&#xff08;一&#xff09;整体结构&#xff08;二&#xff09;内存分配 - New函数&#xff08;三&#xff09;内存回收 - Delete函数 三、内存池在TreeNode示例中的性能测试演示四、脱…...

python画图|自制渐变柱状图

在前述学习过程中&#xff0c;我们已经通过官网学习了如何绘制渐变的柱状图及其背景。 掌握一门技能的最佳检验方式就是通过实战&#xff0c;因此&#xff0c;本文尝试做一些渐变设计。 前述学习记录可查看链接&#xff1a; Python画图|渐变背景-CSDN博客 【1】柱状图渐变 …...

基于RPA+BERT的文档辅助“悦读”系统 | OPENAIGC开发者大赛高校组AI创作力奖

在第二届拯救者杯OPENAIGC开发者大赛中&#xff0c;涌现出一批技术突出、创意卓越的作品。为了让这些优秀项目被更多人看到&#xff0c;我们特意开设了优秀作品报道专栏&#xff0c;旨在展示其独特之处和开发者的精彩故事。 无论您是技术专家还是爱好者&#xff0c;希望能带给…...

K8S部署流程

一、war打包镜像(survey,analytics,trac系统) 代码打包成war准备tomcat的server.xml文件&#xff0c;修改connector中8080端口为项目的端口 修改前&#xff1a; <Connector port"8080" protocol"HTTP/1.1"connectionTimeout"20000"redirect…...

DevExpress WinForms中文教程:Data Grid - 如何添加或删除行?

本教程介绍DevExpress WinForm的Data Grid控件UI元素和API&#xff0c;它们使您和最终用户能够添加或删除数据行。您将首选学习如何启用内置的数据导航器&#xff0c;然后学习如何使用Microsoft Outlook启发的New Item行添加新记录。最后教程将向您展示基本的API&#xff0c;它…...

u盘格式化后数据能恢复吗?2024年Top4恢复神器来帮忙

在这个电脑和手机满天飞的时代&#xff0c;U盘是我们用来存东西和传文件的得力助手&#xff0c;特别重要。但是&#xff0c;有时候U盘可能会不小心被格式化了&#xff0c;里面的重要文件就不见了。那么&#xff0c;U盘格式化后的数据还能恢复吗&#xff1f;当然可以。今天会告诉…...

深度学习·Argparse

Argparse 命令行选项、参数和子命令解析器 ArgumentParser 命令行传参数->解析参数->获得对应参数 初始化&#xff1a;parser argparse.ArgumentParser(descriptionxxx)添加命令行参数&#xff1a; parser.add_argument("--training_filepath", typestr, he…...

制造企业为何需要PLM系统?PLM系统解决方案对制造业重要性分析

制造企业为何需要PLM系统&#xff1f;PLM系统解决方案对制造业重要性分析 新华社9月23日消息&#xff0c;据全国组织机构统一社会信用代码数据服务中心统计&#xff0c;我国制造业企业总量突破600万家。数据显示&#xff0c;2024年1至8月&#xff0c;我国制造业企业数量呈现稳…...

http协议中的header详细讲解

http协议中的header详细讲解 HTTP 协议和 TCP/IP 协议族内的其他众多的协议相同&#xff0c;用于客户端和服务器之间的通信。 请求访问文本或图像等资源的一端称为客户端&#xff0c;而提供资源响应的一端称为服务器端。 HTTP 协议规定&#xff0c;请求从客户端发出&#xf…...

探索后量子安全:基于格加密技术的未来密码学展望

在信息技术日新月异的今天&#xff0c;量子计算作为下一代计算技术的代表&#xff0c;正逐步从理论走向实践。量子计算的出现对现有的加密体系构成了严重威胁&#xff0c;尤其是基于大数分解和离散对数难题的传统密码学&#xff08;如RSA和Diffie-Hellman协议&#xff09;。为了…...

WPF之UI进阶--完整了解wpf的控件和布局容器及应用

前面三篇有关WPF的基础介绍&#xff0c;分别介绍了wpf与winform的异同&#xff0c;wpf的事件生成和使用以及数据绑定。但我们还缺乏一副好的“皮囊”&#xff0c;所以从这篇开始我们来开始学习wpf的UI相关的内容&#xff0c;首当其冲的就是布局容器。 其实我们知道&#xff0c;…...

unity一键注释日志和反注释日志

开发背景&#xff1a;游戏中日志也是很大的开销&#xff0c;虽然有些日志不打印但是毕竟有字符串的开销&#xff0c;甚至有字符串拼接的开销&#xff0c;有些还有装箱和拆箱的开销&#xff0c;比如Debug.Log(1) 这种 因此需要注释掉&#xff0c;当然还需要提供反注释的功能&am…...

VBA数据库解决方案第十五讲:Recordset集合中单个数据的精确处理

《VBA数据库解决方案》教程&#xff08;版权10090845&#xff09;是我推出的第二套教程&#xff0c;目前已经是第二版修订了。这套教程定位于中级&#xff0c;是学完字典后的另一个专题讲解。数据库是数据处理的利器&#xff0c;教程中详细介绍了利用ADO连接ACCDB和EXCEL的方法…...

5000多一年的网站建站/哪个公司的网站制作

环境&#xff1a;Navicat Premium 15、 win10 1909 一、创建表空间 二、创建用户并授权 三、建表&#xff0c;插入数据 四、其他命令 创建表空间 -- 创建表空间并设置表空间名 CREATE tablespace "表空间名" -- 设置文件名 建议和表空间名保持一致 datafile xxx 或…...

wordpress游戏插件下载/seo关键词有话要多少钱

使用EF实现多查询&#xff0c;暂未考虑性能问题 2015年10月6日22:26:51 正文 我在数据库有三个表&#xff0c;如下图&#xff1a; sysMenus与sysFunction有主外键关系&#xff0c;而sysUserInfo则与其他二表并无关联。 我现在使用这三个表针对多种情况使用EF实现多种查询手段 方…...

网站根目录在哪wordpress/seo项目经理

如题&#xff01;转载于:https://www.cnblogs.com/chenge/archive/2008/02/26/1082721.html...

做绿色软件的网站知乎/橙子建站官网

[url]http://yp.oss.org.cn/blog/show_resource.php?resource_id1069[/url] 一&#xff0e;准备安装CentOS 61&#xff0e;CentOS简介CentOS 是甚么&#xff1f; CentOS 是一个基于Red Hat 企业级 Linux 提供的可自由使用的源代码企业级的 Linux 发行版本。每个版本的 CentOS …...

网站开发三大元素/大型营销型网站制作

Servlet处理请求的流程: 1) 客户端在浏览器的地址栏中输入一个请求的URL,按回车后就向服务器端发起一个http request(由浏览器生成)。 2) 服务器端的Web Server首先接受到请求&#xff0c;并将请求转交给容器&#xff0c;容器会根据请求的URL去调用客户端要访问的Servlet。 3) …...

做公司网站成本/b2b推广网站

风险管理 风险管理是指如何在项目或者企业一个肯定有风险的环境里把风险可能造成的不良影响减至最低的管理过程。 风险管理当中包括了对风险的量度、评估和应变策略。理想的风险管理&#xff0c;是一连串排好优先次序的过程&#xff0c;使当中的可以引致最大损失及最可能发生的…...