use feox_ann::{AnnConfig, AnnIndex, AnnQuery};

fn main() -> feox_ann::Result<()> {
    let mut index = AnnIndex::new(AnnConfig::for_dimensions(3))?;

    index.upsert("rust".to_string(), &[0.9, 0.1, 0.0])?;
    index.upsert("iron".to_string(), &[0.8, 0.2, 0.1])?;
    index.upsert("oxide".to_string(), &[0.7, 0.3, 0.2])?;
    index.upsert("feather".to_string(), &[0.0, 0.2, 0.9])?;

    let matches = index.query(AnnQuery {
        vector: &[1.0, 0.0, 0.0],
        top_k: 3,
        ef_search: None,
        filter: None,
    })?;
    println!("nearest to [1, 0, 0]:");
    for candidate in &matches {
        println!("  {} (score {:.4})", candidate.id, candidate.score);
    }

    let filter = |id: &str| id != "rust";
    let filtered = index.query(AnnQuery {
        vector: &[1.0, 0.0, 0.0],
        top_k: 3,
        ef_search: Some(16),
        filter: Some(&filter),
    })?;
    println!("same query, excluding \"rust\":");
    for candidate in &filtered {
        println!("  {} (score {:.4})", candidate.id, candidate.score);
    }

    index.delete("iron");
    let after_delete = index.query(AnnQuery {
        vector: &[1.0, 0.0, 0.0],
        top_k: 3,
        ef_search: None,
        filter: None,
    })?;
    println!("after deleting \"iron\": {} results", after_delete.len());

    Ok(())
}
