#![cfg_attr(
all(feature = "nightly", target_arch = "x86_64"),
feature(stdarch_x86_avx512)
)]
use std::{any::Any, sync::Arc};
use async_trait::async_trait;
use lance_core::Result;
use roaring::RoaringBitmap;
use serde::{Deserialize, Serialize};
pub mod optimize;
pub mod scalar;
pub mod traits;
pub mod vector;
pub use crate::traits::*;
pub const INDEX_FILE_NAME: &str = "index.idx";
pub const INDEX_AUXILIARY_FILE_NAME: &str = "auxiliary.idx";
pub const INDEX_METADATA_SCHEMA_KEY: &str = "lance:index";
pub mod pb {
#![allow(clippy::use_self)]
include!(concat!(env!("OUT_DIR"), "/lance.index.pb.rs"));
}
#[async_trait]
pub trait Index: Send + Sync {
fn as_any(&self) -> &dyn Any;
fn as_index(self: Arc<Self>) -> Arc<dyn Index>;
fn statistics(&self) -> Result<serde_json::Value>;
fn index_type(&self) -> IndexType;
async fn calculate_included_frags(&self) -> Result<RoaringBitmap>;
}
#[derive(Debug, PartialEq, Eq, Copy, Hash, Clone)]
pub enum IndexType {
Scalar = 0,
Vector = 100,
}
impl std::fmt::Display for IndexType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Scalar => write!(f, "Scalar"),
Self::Vector => write!(f, "Vector"),
}
}
}
pub trait IndexParams: Send + Sync {
fn as_any(&self) -> &dyn Any;
fn index_type(&self) -> IndexType;
fn index_name(&self) -> &str;
}
#[derive(Serialize, Deserialize, Debug)]
pub struct IndexMetadata {
#[serde(rename = "type")]
pub index_type: String,
pub distance_type: String,
}