apply_zscore_fusion

Function apply_zscore_fusion 

Source
pub fn apply_zscore_fusion(
    bm25_candidates: Vec<Candidate>,
    vector_candidates: Vec<Candidate>,
    alpha: f64,
) -> Vec<Candidate>
Expand description

Process candidates using z-score fusion

This function demonstrates the core z-score fusion algorithm by:

  1. Converting raw scores to z-scores (mean=0, std=1)
  2. Combining using weighted fusion: α * z_bm25 + β * z_vector
  3. Returning unified candidates sorted by hybrid score

§Arguments

  • bm25_candidates - Candidates from BM25 lexical search
  • vector_candidates - Candidates from vector semantic search
  • alpha - Weight for BM25 z-scores (typically 0.5 for equal weighting)

§Returns

Vector of candidates with hybrid scores, sorted descending by relevance

§Examples

use lethe_core_rust::{apply_zscore_fusion, Candidate};
 
let bm25_candidates = vec![
    Candidate {
        doc_id: "doc1".to_string(),
        score: 0.8,
        text: Some("Programming tutorial".to_string()),
        kind: Some("bm25".to_string()),
    },
];
 
let vector_candidates = vec![
    Candidate {
        doc_id: "doc1".to_string(),
        score: 0.9,
        text: Some("Programming tutorial".to_string()),
        kind: Some("vector".to_string()),
    },
];
 
let results = apply_zscore_fusion(bm25_candidates, vector_candidates, 0.5);
assert!(!results.is_empty());
assert_eq!(results[0].kind, Some("hybrid".to_string()));