これはPGroonga 2.0.0以降用のドキュメントです。PGroonga 1.Xを使っているならPGroonga 1.Xのドキュメントを見てください。
&@*演算子(セマンティックサーチ)4.0.5で追加。
まだ実験的な機能です。
pgroonga_text_semantic_search_ops_v2演算子クラスにおいて、&@*演算子はセマンティックサーチを実行します。
類似文書検索を行う&@*演算子についてはこちらをご覧ください。
column &@* pgroonga_condition(query)
columnは検索対象のカラムです。型はtext型です。
queryはセマンティックサーチ用のクエリーです。型はtext型です。
pgroonga_condition関数を使います。
pgroonga_condition関数には引数がいくつかありますが、queryのみを指定してご利用ください。
この演算子を使うにはpgroonga_text_semantic_search_ops_v2演算子クラスを指定する必要があります。
例に使うサンプルスキーマとデータは次の通りです。
CREATE TABLE memos (
id integer,
content text
);
INSERT INTO memos VALUES (1, 'PostgreSQL is a RDBMS.');
INSERT INTO memos VALUES (2, 'Groonga is fast full text search engine.');
INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga.');
次のようにインデックスを作成します。インデックス作成についてはCREATE INDEX USING pgroongaをご覧ください。
CREATE INDEX pgroonga_index ON memos
USING pgroonga (content pgroonga_text_semantic_search_ops_v2)
WITH (plugins = 'language_model/knn',
model = 'hf:///groonga/all-MiniLM-L6-v2-Q4_K_M-GGUF');
&@*演算子を使うと指定したクエリを使ってセマンティックサーチができます。
SELECT id, content
FROM memos
WHERE content &@* pgroonga_condition('What is a MySQL alternative?');
-- id | content
-- ----+-------------------------------------------------------
-- 1 | PostgreSQL is a RDBMS.
-- 3 | PGroonga is a PostgreSQL extension that uses Groonga.
-- 2 | Groonga is fast full text search engine.
-- (3 rows)
<&@*>演算子: テキスト間の距離を計算
&@* operator: 類似文書検索