Skip to main content

brainwires_rag/rag/types/
ensemble.rs

1use serde::{Deserialize, Serialize};
2
3use super::query::{SearchResult, default_limit, default_min_score};
4
5/// Search strategies available for the ensemble query.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, schemars::JsonSchema)]
7#[serde(rename_all = "snake_case")]
8pub enum SearchStrategy {
9    /// Semantic (vector) search — finds conceptually similar code.
10    Semantic,
11    /// Keyword (BM25) search — finds exact term matches.
12    Keyword,
13    /// Git history search — finds matching commits, messages, and diffs.
14    GitHistory,
15    /// Code navigation search — finds definitions/references via AST relations.
16    /// Only available when the `code-analysis` feature is enabled.
17    CodeNavigation,
18}
19
20/// Request for the parallel multi-strategy ensemble query.
21#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
22pub struct EnsembleRequest {
23    /// The search query.
24    pub query: String,
25    /// Optional path to filter by specific indexed codebase.
26    #[serde(default)]
27    pub path: Option<String>,
28    /// Optional project name to filter results.
29    #[serde(default)]
30    pub project: Option<String>,
31    /// Maximum results to return after fusion.
32    #[serde(default = "default_limit")]
33    pub limit: usize,
34    /// Minimum similarity score per strategy (default: 0.7).
35    #[serde(default = "default_min_score")]
36    pub min_score: f32,
37    /// Strategies to fan out across.  An empty list means "all available".
38    #[serde(default)]
39    pub strategies: Vec<SearchStrategy>,
40    /// File extensions to restrict results to (e.g., `["rs", "toml"]`).
41    #[serde(default)]
42    pub file_extensions: Vec<String>,
43    /// Programming languages to restrict results to.
44    #[serde(default)]
45    pub languages: Vec<String>,
46    /// If `true` and the `spectral` feature is enabled, apply spectral
47    /// diversity reranking as a final pass on the fused result set.
48    #[serde(default)]
49    pub spectral_rerank: bool,
50}
51
52/// Response from the ensemble multi-strategy query.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct EnsembleResponse {
55    /// Merged, deduplicated, and RRF-fused results.
56    pub results: Vec<SearchResult>,
57    /// Total wall-clock time in milliseconds.
58    pub duration_ms: u64,
59    /// Names of the strategies that ran (and didn't error).
60    pub strategies_used: Vec<String>,
61    /// Number of raw results returned by each strategy before fusion.
62    pub per_strategy_counts: std::collections::HashMap<String, usize>,
63}