pub struct SearchService<S, E>where
S: DatasetStore,
E: EmbeddingProvider,{ /* private fields */ }Expand description
Service for semantic search operations.
This service encapsulates the search business logic, coordinating between the embedding provider and the dataset store.
§Type Parameters
S- Dataset store implementation (e.g.,DatasetRepository)E- Embedding provider implementation (e.g.,GeminiClient)
§Example
ⓘ
use ceres_core::search::SearchService;
let search_service = SearchService::new(repo, gemini);
let results = search_service.search("climate data", 10).await?;
for result in results {
println!("{}: {:.2}", result.dataset.title, result.similarity_score);
}Implementations§
Source§impl<S, E> SearchService<S, E>where
S: DatasetStore,
E: EmbeddingProvider,
impl<S, E> SearchService<S, E>where
S: DatasetStore,
E: EmbeddingProvider,
Sourcepub fn new(store: S, embedding: E) -> Self
pub fn new(store: S, embedding: E) -> Self
Creates a new search service.
§Arguments
store- Dataset store for vector search queriesembedding- Embedding provider for generating query embeddings
Sourcepub async fn search(
&self,
query: &str,
limit: usize,
) -> Result<Vec<SearchResult>, AppError>
pub async fn search( &self, query: &str, limit: usize, ) -> Result<Vec<SearchResult>, AppError>
Performs semantic search and returns ranked results.
This method:
- Generates an embedding vector from the query text
- Searches the database using cosine similarity
- Returns results ordered by similarity (highest first)
§Arguments
query- The search query textlimit- Maximum number of results to return
§Returns
A vector of SearchResult, ordered by similarity score (highest first).
§Errors
Returns an error if:
- The embedding generation fails (API error, network error, etc.)
- The database query fails
Trait Implementations§
Source§impl<S, E> Clone for SearchService<S, E>
impl<S, E> Clone for SearchService<S, E>
Auto Trait Implementations§
impl<S, E> Freeze for SearchService<S, E>
impl<S, E> RefUnwindSafe for SearchService<S, E>where
S: RefUnwindSafe,
E: RefUnwindSafe,
impl<S, E> Send for SearchService<S, E>
impl<S, E> Sync for SearchService<S, E>
impl<S, E> Unpin for SearchService<S, E>
impl<S, E> UnwindSafe for SearchService<S, E>where
S: UnwindSafe,
E: UnwindSafe,
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