ベクトル検索

 

(8.4.0)
https://techfeed.io/entries/6685c497fc9a9f708a14791f


未対応の模様
9.0でVECTOR型は使用可能

 

CREATE TABLE tab1 (col1 VECTOR(5000));

 

(23ai)
https://qiita.com/ryotayamanaka/items/156932a48e65d3ddc5ac


drop table tab1 purge;
CREATE TABLE tab1 ( col1 int generated always as identity primary key, col2 VECTOR(4) );


INSERT INTO tab1(col2)
SELECT
  '[' || dbms_random.value(1, 1000) || ',' || dbms_random.value(1, 1000) || ',' || dbms_random.value(1, 1000) || ',' || dbms_random.value(1, 1000) || ']' 
from dual connect by level <= 10000;
COMMIT;


SELECT * FROM tab1 fetch first 5 rows only;

SELECT * FROM tab1 ORDER BY col2 <=> '[10.0, 2, 0.3, 0.3]' fetch first 3 rows only;

 

 

(16)


https://www.sraoss.co.jp/tech-blog/pgsql/pgvector-intro/
https://github.com/pgvector/pgvector

 

sudo dnf install https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-9-x86_64/pgvector_16-0.5.0-1PGDG.rhel9.x86_64.rpm

 


CREATE EXTENSION vector;

drop table tab1;
CREATE TABLE tab1 (col1 bigserial PRIMARY KEY, col2 vector(4));

INSERT INTO tab1(col2)
SELECT
  ARRAY[
  random() * 1000, 
  random() * 1000, 
  random() * 1000, 
  random() * 1000  
]
FROM generate_series(1 , 10000);


SELECT * FROM tab1 LIMIT 5;

SELECT * FROM tab1 ORDER BY col2 <=> '[10.0, 2, 0.3, 0.3]' LIMIT 3;

 

(2022)

未対応の模様