Hybrid search#
Hybrid search combines semantic (vector/embedding) search on knowledge base embeddings with one or more additional filter mechanisms:
Relational predicate filtering — Filter results by any column in the source table, for example
WHERE category = 'vegetarian'orWHERE published_date > '2024-01-01'.Full-text search — Rank results by keyword relevance using native PostgreSQL FTS, ensuring that specific words or phrases appear in the results.
These two approaches can be used independently or together alongside semantic search.
AI pipelines handle knowledge base construction, including embedding generation, as normal. Hybrid search is applied at query time by constructing custom SQL that combines the vector table with your source table. It is not a separately installed feature and no additional setup is required beyond the prerequisites below.
Prerequisites#
pgvector iterative index scans are required for all hybrid query patterns. Native FTS is only needed if your queries use the keyword leg.
pgvector iterative index scans#
Requires pgvector 0.8.0 or later. Enable iterative index scans before
running hybrid queries — they allow the vector index to keep producing
candidates until your LIMIT is satisfied, even after filtering. See
Writing hybrid search queries for the SET commands.
Native PostgreSQL FTS (no extension required)#
Standard PostgreSQL full-text search (FTS) (tsvector / ts_rank )
is available in every Postgres installation without additional
extensions. See Setting up native PostgreSQL FTS for setup steps.
Volume source limitation#
Hybrid search with relational predicate filtering or full-text search is not supported for volume-sourced knowledge bases. Volume sources have no backing Postgres table to join against, so there’s no source table to filter or index.
Volume sourced knowledge bases continue to support standard semantic
search via aidb.retrieve_text() and aidb.retrieve_key() .
Hybrid search#
Next steps#
Setting up native PostgreSQL FTS — Add a
tsvectorcolumn, GIN index, and trigger to your source table.Writing hybrid search queries — SQL patterns for every combination: relational filter, Reciprocal Rank Fusion (RRF), weighted linear fusion. Includes a worked example with sample data and expected output.
Handling embedding service outages — A three-tier fallback chain to keep queries returning results gracefully.
Pipelines API reference — Full reference for
aidb.kb_query_encode(),aidb.rerank_text(), and theaidb.knowledge_basesview.