pub struct CustomStrategy<Q> { /* private fields */ }
Expand description
CustomStrategy
provides a flexible way to generate retriever-specific search queries.
This struct implements a strategy pattern for vector similarity search, allowing different retrieval backends to provide their own query generation logic. Configuration is managed through the query generation closure, promoting a more flexible and composable design.
§Type Parameters
Q
- The retriever-specific query type (e.g.,sqlx::QueryBuilder
forPostgreSQL
)
§Examples
// Define search configuration
const MAX_SEARCH_RESULTS: i64 = 5;
// Create a custom search strategy
let strategy = CustomStrategy::from_query(|query_node| {
let mut builder = QueryBuilder::new();
// Configure search parameters within the closure
builder.push(" LIMIT ");
builder.push_bind(MAX_SEARCH_RESULTS);
Ok(builder)
});
§Implementation Notes
- Search configuration (like result limits and vector fields) should be defined in the closure’s scope
- Implementers are responsible for validating configuration values
- The query generator has access to the full query state for maximum flexibility
Implementations§
Source§impl<Q: Send + Sync + 'static> CustomStrategy<Q>
impl<Q: Send + Sync + 'static> CustomStrategy<Q>
Sourcepub fn from_query(
query: impl Fn(&Query<Pending>) -> Result<Q> + Send + Sync + 'static,
) -> Self
pub fn from_query( query: impl Fn(&Query<Pending>) -> Result<Q> + Send + Sync + 'static, ) -> Self
Creates a new CustomStrategy
with a query generation function.
The provided closure should contain all necessary configuration for query generation. This design allows for more flexible configuration management compared to struct-level fields.
§Parameters
query
- A closure that generates retriever-specific queries
Sourcepub fn build_query(&self, query_node: &Query<Pending>) -> Result<Q>
pub fn build_query(&self, query_node: &Query<Pending>) -> Result<Q>
Gets the query builder, which can then be used to build the actual query
§Errors
This function will return an error if:
- No query function has been set (use
from_query
to set a query function). - The query function fails while processing the provided
query_node
.
Trait Implementations§
Source§impl<Q> Clone for CustomStrategy<Q>
impl<Q> Clone for CustomStrategy<Q>
Source§impl<Q> Default for CustomStrategy<Q>
impl<Q> Default for CustomStrategy<Q>
impl<Q: Send + Sync + 'static> SearchStrategy for CustomStrategy<Q>
Auto Trait Implementations§
impl<Q> Freeze for CustomStrategy<Q>
impl<Q> !RefUnwindSafe for CustomStrategy<Q>
impl<Q> Send for CustomStrategy<Q>where
Q: Send,
impl<Q> Sync for CustomStrategy<Q>where
Q: Sync,
impl<Q> Unpin for CustomStrategy<Q>where
Q: Unpin,
impl<Q> !UnwindSafe for CustomStrategy<Q>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more