use std::collections::HashMap;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Distance {
Cosine,
Euclid,
Dot,
Manhattan,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum PrecisionTier {
Low,
Medium,
High,
Full,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum Tokenizer {
Prefix,
Whitespace,
Word,
Multilingual,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DenseVectorConfig {
pub size: u64,
pub distance: Distance,
pub multivector: bool,
pub precision_tier: Option<PrecisionTier>,
}
impl DenseVectorConfig {
pub fn new(size: u64, distance: Distance) -> Self {
Self {
size,
distance,
multivector: false,
precision_tier: None,
}
}
pub fn multivector(mut self, multivector: bool) -> Self {
self.multivector = multivector;
self
}
pub fn precision_tier(mut self, tier: PrecisionTier) -> Self {
self.precision_tier = Some(tier);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SparseVectorConfig {
pub use_idf: bool,
pub precision_tier: Option<PrecisionTier>,
}
impl SparseVectorConfig {
pub fn new() -> Self {
Self::default()
}
pub fn use_idf(mut self, use_idf: bool) -> Self {
self.use_idf = use_idf;
self
}
pub fn precision_tier(mut self, tier: PrecisionTier) -> Self {
self.precision_tier = Some(tier);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct KeywordPrefixParams;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct KeywordIndex {
pub prefix: Option<KeywordPrefixParams>,
}
impl KeywordIndex {
pub fn new() -> Self {
Self::default()
}
pub fn with_prefix(mut self) -> Self {
self.prefix = Some(KeywordPrefixParams);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IntegerIndex {
pub lookup: Option<bool>,
pub range: Option<bool>,
}
impl IntegerIndex {
pub fn new() -> Self {
Self::default()
}
pub fn lookup(mut self, lookup: bool) -> Self {
self.lookup = Some(lookup);
self
}
pub fn range(mut self, range: bool) -> Self {
self.range = Some(range);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FloatIndex;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UuidIndex;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DatetimeIndex;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StopwordsSet {
pub languages: Vec<String>,
pub custom: Vec<String>,
}
impl StopwordsSet {
pub fn new() -> Self {
Self::default()
}
pub fn languages(mut self, languages: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.languages = languages.into_iter().map(Into::into).collect();
self
}
pub fn custom(mut self, custom: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.custom = custom.into_iter().map(Into::into).collect();
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SnowballParams {
pub language: String,
}
impl SnowballParams {
pub fn new(language: impl Into<String>) -> Self {
Self {
language: language.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum StemmingAlgorithm {
Snowball(SnowballParams),
Disabled,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextIndex {
pub tokenizer: Option<Tokenizer>,
pub lowercase: Option<bool>,
pub phrase_matching: Option<bool>,
pub min_token_len: Option<u64>,
pub max_token_len: Option<u64>,
pub ascii_folding: Option<bool>,
pub stopwords: Option<StopwordsSet>,
pub stemmer: Option<StemmingAlgorithm>,
}
impl TextIndex {
pub fn new() -> Self {
Self::default()
}
pub fn tokenizer(mut self, tokenizer: Tokenizer) -> Self {
self.tokenizer = Some(tokenizer);
self
}
pub fn lowercase(mut self, lowercase: bool) -> Self {
self.lowercase = Some(lowercase);
self
}
pub fn phrase_matching(mut self, phrase_matching: bool) -> Self {
self.phrase_matching = Some(phrase_matching);
self
}
pub fn min_token_len(mut self, min_token_len: u64) -> Self {
self.min_token_len = Some(min_token_len);
self
}
pub fn max_token_len(mut self, max_token_len: u64) -> Self {
self.max_token_len = Some(max_token_len);
self
}
pub fn ascii_folding(mut self, ascii_folding: bool) -> Self {
self.ascii_folding = Some(ascii_folding);
self
}
pub fn stopwords(mut self, stopwords: StopwordsSet) -> Self {
self.stopwords = Some(stopwords);
self
}
pub fn stemmer(mut self, stemmer: StemmingAlgorithm) -> Self {
self.stemmer = Some(stemmer);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct GeoIndex;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BoolIndex;
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type", rename_all = "snake_case"))]
pub enum PayloadIndex {
Keyword(KeywordIndex),
Integer(IntegerIndex),
Float(FloatIndex),
Uuid(UuidIndex),
Datetime(DatetimeIndex),
Text(TextIndex),
Geo(GeoIndex),
Bool(BoolIndex),
}
impl From<KeywordIndex> for PayloadIndex {
fn from(value: KeywordIndex) -> Self {
Self::Keyword(value)
}
}
impl From<IntegerIndex> for PayloadIndex {
fn from(value: IntegerIndex) -> Self {
Self::Integer(value)
}
}
impl From<FloatIndex> for PayloadIndex {
fn from(value: FloatIndex) -> Self {
Self::Float(value)
}
}
impl From<UuidIndex> for PayloadIndex {
fn from(value: UuidIndex) -> Self {
Self::Uuid(value)
}
}
impl From<DatetimeIndex> for PayloadIndex {
fn from(value: DatetimeIndex) -> Self {
Self::Datetime(value)
}
}
impl From<TextIndex> for PayloadIndex {
fn from(value: TextIndex) -> Self {
Self::Text(value)
}
}
impl From<GeoIndex> for PayloadIndex {
fn from(value: GeoIndex) -> Self {
Self::Geo(value)
}
}
impl From<BoolIndex> for PayloadIndex {
fn from(value: BoolIndex) -> Self {
Self::Bool(value)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectionConfig {
pub dense_vectors: HashMap<String, DenseVectorConfig>,
pub sparse_vectors: HashMap<String, SparseVectorConfig>,
pub payload_indexes: HashMap<String, PayloadIndex>,
}
impl CollectionConfig {
pub fn new() -> Self {
Self::default()
}
pub fn dense_vector(mut self, config: DenseVectorConfig) -> Self {
self.dense_vectors.insert(String::new(), config);
self
}
pub fn named_dense_vector(
mut self,
name: impl Into<String>,
config: DenseVectorConfig,
) -> Self {
self.dense_vectors.insert(name.into(), config);
self
}
pub fn sparse_vector(mut self, config: SparseVectorConfig) -> Self {
self.sparse_vectors.insert(String::new(), config);
self
}
pub fn named_sparse_vector(
mut self,
name: impl Into<String>,
config: SparseVectorConfig,
) -> Self {
self.sparse_vectors.insert(name.into(), config);
self
}
pub fn payload_index(
mut self,
field: impl Into<String>,
index: impl Into<PayloadIndex>,
) -> Self {
self.payload_indexes.insert(field.into(), index.into());
self
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateCollectionResult {
pub collection_name: String,
pub result: String,
pub time: f64,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DeleteCollectionResult {
pub deleted: bool,
pub time: f64,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectionInfo {
pub exists: bool,
pub config: Option<CollectionConfig>,
pub point_count: Option<u64>,
pub time: f64,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ListCollections {
pub limit: Option<u32>,
pub offset_token: Option<String>,
}
impl ListCollections {
pub fn new() -> Self {
Self::default()
}
}
#[must_use]
#[derive(Clone, Default)]
pub struct ListCollectionsBuilder {
limit: Option<u32>,
offset_token: Option<String>,
}
impl ListCollectionsBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn offset_token(mut self, offset_token: impl Into<String>) -> Self {
self.offset_token = Some(offset_token.into());
self
}
pub fn build(self) -> ListCollections {
self.into()
}
}
impl From<ListCollectionsBuilder> for ListCollections {
fn from(builder: ListCollectionsBuilder) -> Self {
ListCollections {
limit: builder.limit,
offset_token: builder.offset_token,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectionSummary {
pub collection_name: String,
pub point_count: Option<u64>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CollectionsList {
pub collections: Vec<CollectionSummary>,
pub next_offset_token: Option<String>,
pub time: f64,
}