iridium-db 0.2.0

A high-performance vector-graph hybrid storage and indexing engine
use super::types::{
    ExecutablePredicate, ExecuteParams, ExplainError, ExplainPlan, Result, Row, RowStream,
};

mod core;
mod rerank;
mod vector;

pub use core::{execute, execute_fanout, execute_with_request, FanoutShardExecution};
#[cfg(test)]
pub(crate) use vector::{cosine_scores_batch_for_test, cosine_similarity_scalar_for_test};

fn merge_rows_deterministic(mut rows: Vec<Row>, limit: usize) -> Vec<Row> {
    rows.sort_by(|a, b| match (a.score, b.score) {
        (Some(sa), Some(sb)) => sb.total_cmp(&sa).then_with(|| a.node_id.cmp(&b.node_id)),
        (Some(_), None) => std::cmp::Ordering::Less,
        (None, Some(_)) => std::cmp::Ordering::Greater,
        (None, None) => a.node_id.cmp(&b.node_id),
    });
    let mut seen = std::collections::HashSet::new();
    let mut out = Vec::new();
    for row in rows {
        if seen.insert(row.node_id) {
            out.push(row);
            if out.len() >= limit {
                break;
            }
        }
    }
    out
}