Hybrid search reference v7

AIDB provides helper functions and a metadata view for constructing hybrid search queries. Use these to encode queries against a specific knowledge base, rerank retrieved results, and inspect knowledge base configuration without hardcoding model names or table paths.

aidb.kb_query_encode()

Encodes a text query using the embedding model configured for a specific knowledge base, without needing to look up the model name:

SELECT aidb.kb_query_encode('public.my_kb_vector', 'test query');

Use this in place of aidb.encode_text_query('<model>', '<query>') when constructing custom vector queries.

aidb.rerank_text()

After retrieving candidates, pass them to a reranking model for a final relevance-ordered result:

SELECT aidb.rerank_text('my_reranking_model', 'query text', ARRAY['result1', 'result2', ...]);

Reranking models such as nim_reranking and hf_tei_reranking are supported as a separate post-processing step after retrieval.

aidb.knowledge_bases view

The aidb.knowledge_bases view (also accessible as aidb.kbs) exposes all the metadata needed to construct hybrid queries:

ColumnTypeDescription
idintegerInternal identifier
nametextKnowledge base name
vector_schematextSchema of the embeddings table
vector_tabletextEmbeddings storage table
model_nametextEmbedding model used by this KB
distance_operatoraidb.distanceoperatorDistance metric enum value
distance_operator_sqltextThe distance operator in SQL-operator syntax
vector_data_columntextColumn storing the embeddings
vector_key_columntextColumn linking embeddings to source rows
vector_indexjsonbVector index configuration
pipeline_idsinteger[]IDs of all pipelines attached to this knowledge base
pipeline_namestext[]Names of all pipelines attached to this knowledge base
SELECT name, vector_schema, vector_table, distance_operator_sql
FROM aidb.knowledge_bases;