pub struct HybridSearchBuilder { /* private fields */ }Expand description
Builder for hybrid search queries that combine vector similarity with full-text search.
This generates queries that use both pgvector distance operators and PostgreSQL tsvector/tsquery for combined similarity scoring.
§Examples
use prax_pgvector::query::HybridSearchBuilder;
use prax_pgvector::{Embedding, DistanceMetric};
let query = HybridSearchBuilder::new("documents")
.vector_column("embedding")
.text_column("content")
.query_vector(Embedding::new(vec![0.1, 0.2, 0.3]))
.query_text("machine learning")
.metric(DistanceMetric::Cosine)
.vector_weight(0.7)
.text_weight(0.3)
.limit(10)
.build();
let sql = query.to_sql();Implementations§
Source§impl HybridSearchBuilder
impl HybridSearchBuilder
Sourcepub fn vector_column(self, column: impl Into<String>) -> Self
pub fn vector_column(self, column: impl Into<String>) -> Self
Set the vector column name.
Sourcepub fn text_column(self, column: impl Into<String>) -> Self
pub fn text_column(self, column: impl Into<String>) -> Self
Set the text column name.
Sourcepub fn query_vector(self, embedding: Embedding) -> Self
pub fn query_vector(self, embedding: Embedding) -> Self
Set the query vector.
Sourcepub fn query_text(self, text: impl Into<String>) -> Self
pub fn query_text(self, text: impl Into<String>) -> Self
Set the text query.
Sourcepub fn metric(self, metric: DistanceMetric) -> Self
pub fn metric(self, metric: DistanceMetric) -> Self
Set the vector distance metric.
Sourcepub fn vector_weight(self, weight: f64) -> Self
pub fn vector_weight(self, weight: f64) -> Self
Set the weight for the vector similarity component (0.0 to 1.0).
Sourcepub fn text_weight(self, weight: f64) -> Self
pub fn text_weight(self, weight: f64) -> Self
Set the weight for the text relevance component (0.0 to 1.0).
Sourcepub fn language(self, language: impl Into<String>) -> Self
pub fn language(self, language: impl Into<String>) -> Self
Set the text search language.
The language is interpolated into SQL string literals, so it must be a
valid PostgreSQL text search configuration name: a simple identifier
matching ^[A-Za-z_][A-Za-z0-9_]*$ (e.g. english, simple).
This is the panicking convenience for trusted, hardcoded values;
prefer try_language when the language comes
from untrusted (e.g. request-influenced) input.
§Panics
Panics if language is not a valid configuration name.
Sourcepub fn try_language(self, language: impl Into<String>) -> VectorResult<Self>
pub fn try_language(self, language: impl Into<String>) -> VectorResult<Self>
Set the text search language, returning an error for invalid names.
Fallible counterpart to language — use this when
the language is influenced by untrusted input so an invalid name is
a recoverable error instead of a panic.
Sourcepub fn where_clause(self, condition: impl Into<String>) -> Self
pub fn where_clause(self, condition: impl Into<String>) -> Self
Add a WHERE condition.
Sourcepub fn build(self) -> HybridSearchQuery
pub fn build(self) -> HybridSearchQuery
Build the hybrid search query.