Top
Enterprise Postgres 18 Knowledge DataManagement FeatureUser's Guide

3.12.2 Recording and Deleting Traces of Hybrid Search

To record trace for evaluation queries, a user with trace recording privileges enables the trace and executes a hybrid search using the evaluation queries. As a result, the trace information is recorded in the table. Trace recording can only be done on the primary server. Even if a hybrid search with trace enabled is performed on a hot standby server, the trace will not be recorded. The trace privileges are granted to the database user performing the search by the extension owner using the pgx_grant_access_on_hybrid_search_trace function. To enable the trace, the database user performing the hybrid search sets the enable_hybrid_search_trace parameter to on in their session. Regarding the enable_hybrid_search_trace parameter, refer to "3.13.5 Parameters".

Example) Privilege granted by the owner of the extension

rag_databse=# SELECT pgx_vectorizer.pgx_grant_access_on_hybrid_search_trace('app_user');

Example) Setting session parameters by users performing searches and executing hybrid searches

rag_database=> SET pgx_vectorizer.enable_hybrid_search_trace = 'on';
rag_database=> SELECT * FROM pgx_vectorizer.pgx_hybrid_search(...);

When a trace is recorded, a query ID that identifies the search request required for subsequent operations is issued. The query ID is returned as a result of a hybrid search, and can also be confirmed by referring to the table where trace information is recorded (pgx_trace_query table). This table records the database user who executed the hybrid search, the time, and the application name, allowing you to identify the query ID using these details.

Example) The database user who executes the command refers to the query ID of the hybrid search executed within an hour

rag_database=> SELECT queryid FROM pgx_vectorizer.pgx_trace_query WHERE retrieval_time >= (current_timestamp - interval '1 hour') ORDER BY retrieval_time;
queryid
---------
   10001
(1 row)

After completing the evaluation and tuning, trace information and evaluation values will be deleted. By deleting records with the target query ID from the pgx_trace_query table, all related information will be removed.

Example) Delete trace information by specifying the query ID

rag_database=> DELETE FROM pgx_vectorizer.pgx_trace_query WHERE queryid = 10001;

Example) The administrator deletes all trace information older than 30 days

rag_databse=# DELETE FROM pgx_vectorizer.pgx_trace_query WHERE retrieval_time <= (current_timestamp - interval '30 days') ;

Information

The trace information includes the search conditions and the knowledge data itself as search results, and is recorded in a common table within the database. Privileges are set so that only the database users and administrators who executed the search process can refer to, update, and delete that trace information.