Top
Enterprise Postgres 17 SP1 Knowledge DataManagement FeatureUser's Guide

3.10 Performance Tuning of Semantic Text Search

A text semantic search internally performs a similarity search on vector data. If an index is not specified for the vector data, all vector data is scanned for each text semantic search. You can check whether an index is being used in a text semantic search by running pgx_similarity_search_checking_index.

Example) Check if an index is used in a semantic text search

rag_database=> SELECT * FROM pgx_similarity_search_checking_index('sample_embeddings'::regclass, 'text for search', 5, '<=>');
ERROR: opclass of index is vector_ip_ops, but the distance_operator is <+>

If search results are output when you execute pgx_similarity_search_checking_index, the index is being used. If the search ends with an error as shown above, the distance operator specified in the index definition may differ from the distance type specified in the semantic search. If the distance type specified in the semantic search is incorrect, correct the distance specified. If the distance operator specified in the index definition is incorrect, delete the index and re-create the correct index.

Indexes for vectors explicitly define for the table that stores vectors that are created internally when vectorization is defined.

Example) Changing the vector table index

-- Check and delete the old index name 
rag_database=> SELECT indexname FROM pg_indexes where tablename = 'sample_embeddings_store';
                indexname                 
------------------------------------------
 sample_embeddings_store_pkey
 sample_embeddings_store_id_chunk_seq_key
 sample_embeddings_store_embedding_idx - It is created for a column called embedding.
(3 rows)
rag_database=> DROP INDEX sample_embeddings_store_embedding_idx
-- Add the correct index
rag_database=> CREATE INDEX ON sample_embeddings_store USING hnsw (embedding vector_l1_ops);