Top
Enterprise Postgres 18 Knowledge DataManagement FeatureUser's Guide

3.11 Hybrid Search

In hybrid search, results from both semantic text search and full-text search are combined, ranked based on scores considering both results, and the specified number of results are returned in order of highest score.

Hybrid search flow

Hybrid search uses the SQL function pgx_vectorizer.pgx_hybrid_search function. For pgx_vectorizer.pgx_hybrid_search function, refer to "3.13.3.2 Hybrid Search".

In the following example, a search is performed on the embedded view sample_embeddings created by the vectorization definition. The union of the top 10 results of full-text search and semantic text search of text is taken, and the top 20 results based on the final score are returned. In this example, partial match search using the LIKE operator is performed as a full-text search.

Example) Hybrid search

rag_database=> SELECT context_id, chunk, score FROM pgx_vectorizer.pgx_hybrid_search('
{
  "target_view": "sample_embeddings",
  "search_fusion": "UNION",
  "topN": 20,
  "semantic": {
    "search_text": "text for search",
    "num_result": 10,
    "score_weight": 10
  },
  "fulltext": {
  "search_condition": "chunk LIKE ''%text%''",
  "score_expression": "CASE WHEN chunk LIKE ''%text%'' THEN 1 ELSE 0 END"
  }
}'::JSONB
);

For the return results of the hybrid search, refer to "Hybrid search results".

Information

Combined search results are ordered using a method called weighted RRF (Reciprocal Rank Fusion). For more details, refer to "Score calculation".