Top
Enterprise Postgres 18 Knowledge DataManagement FeatureUser's Guide

3.12.5 Tuning of Hybrid Search

Tune hybrid search based on calculated search accuracy.

To reduce application modifications due to changes in hybrid search parameters, it is useful to create search functions for each application as user-defined functions.

Below is an example of defining a SQL function that only takes the string you want to search as input. By defining such a function, you can change the topN parameter and score_weight parameter on the database server side.

rag_database=> CREATE OR REPLACE FUNCTION mysearch(in text, in text, out uuid, out text, out float8)
AS $$
SELECT context_id, chunk, score FROM pgx_vectorizer.pgx_hybrid_search(
jsonb_set(
  jsonb_set('{
    "target_view": "sample_embeddings",
    "search_fusion": "UNION",
    "topN": 20,
    "semantic": {
      "num_result": 10,
      "score_weight": 10
    },
    "fulltext": {
      "score_expression": "1"
    }}'::jsonb,
  '{semantic, search_text}', ('"' || $1 || '"')::jsonb),
'{fulltext, search_text}', ('"' || $2 || '"')::jsonb)
)
$$ LANGUAGE SQL