pub struct HybridSearchQuery {
pub table: String,
pub vector_column: String,
pub text_column: String,
pub query_vector: Option<Embedding>,
pub query_text: Option<String>,
pub metric: DistanceMetric,
pub vector_weight: f64,
pub text_weight: f64,
pub limit: usize,
pub language: String,
pub where_clauses: Vec<String>,
}Expand description
A hybrid search query combining vector similarity and full-text search.
Result shape: the SQL from to_sql returns two columns —
an anonymous composite named coalesce (the merged matched row) and
rrf_score. The composite’s fields cannot be expanded or selected in SQL;
see to_sql for how to consume it.
Fields§
§table: StringTable name.
vector_column: StringVector column.
text_column: StringText column.
query_vector: Option<Embedding>Query vector.
query_text: Option<String>Text query.
metric: DistanceMetricDistance metric.
vector_weight: f64Weight for vector similarity (0.0-1.0).
text_weight: f64Weight for text relevance (0.0-1.0).
limit: usizeResult limit.
language: StringText search language.
where_clauses: Vec<String>Additional WHERE conditions.
Implementations§
Source§impl HybridSearchQuery
impl HybridSearchQuery
Sourcepub fn to_sql(&self) -> String
pub fn to_sql(&self) -> String
Generate the SQL query using Reciprocal Rank Fusion (RRF).
RRF combines rankings from multiple retrieval methods:
score = sum(1 / (k + rank_i)) where k is a constant (typically 60).
The query vector should be $1 and the text query should be $2.
§Result shape
The final SELECT returns two columns: an anonymous composite named
coalesce — the whole matched row from vector_results (when both
sides match, the vector side wins) or text_results — plus rrf_score.
The composite’s record type is never registered, so PostgreSQL rejects
both (coalesce).* expansion and per-field access like (coalesce).id
with “record type has not been registered”. Consumers must either
decode the composite value client-side or wrap the query and project
row_to_json(coalesce) (or to_json(coalesce)). The composite also
carries the matching side’s rank column (vec_rank or text_rank) in
addition to the base table columns, so its shape is not fixed.
Trait Implementations§
Source§impl Clone for HybridSearchQuery
impl Clone for HybridSearchQuery
Source§fn clone(&self) -> HybridSearchQuery
fn clone(&self) -> HybridSearchQuery
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more