mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Working first implementation
This commit is contained in:
parent
e74c3b692a
commit
e023ee4b6b
15 changed files with 298 additions and 103 deletions
|
@ -393,7 +393,8 @@ InvalidSettingsIndexChat , InvalidRequest , BAD_REQU
|
|||
InvalidExportUrl , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidExportApiKey , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidExportIndexesPatterns , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidExportSkipEmbeddings , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidExportIndexSkipEmbeddings , InvalidRequest , BAD_REQUEST ;
|
||||
InvalidExportIndexFilter , InvalidRequest , BAD_REQUEST ;
|
||||
// Experimental features - Chat Completions
|
||||
UnimplementedExternalFunctionCalling , InvalidRequest , NOT_IMPLEMENTED ;
|
||||
UnimplementedNonStreamingChatCompletions , InvalidRequest , NOT_IMPLEMENTED ;
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::index_uid::{IndexUid, IndexUidFormatError};
|
|||
|
||||
/// An index uid pattern is composed of only ascii alphanumeric characters, - and _, between 1 and 400
|
||||
/// bytes long and optionally ending with a *.
|
||||
#[derive(Serialize, Deserialize, Deserr, Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Serialize, Deserialize, Deserr, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[deserr(try_from(&String) = FromStr::from_str -> IndexUidPatternFormatError)]
|
||||
pub struct IndexUidPattern(String);
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ use utoipa::ToSchema;
|
|||
use crate::batches::BatchId;
|
||||
use crate::error::ResponseError;
|
||||
use crate::settings::{Settings, Unchecked};
|
||||
use crate::tasks::{serialize_duration, Details, IndexSwap, Kind, Status, Task, TaskId};
|
||||
use crate::tasks::{
|
||||
serialize_duration, Details, DetailsExportIndexSettings, IndexSwap, Kind, Status, Task, TaskId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
@ -126,9 +128,7 @@ pub struct DetailsView {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub api_key: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub exported_documents: Option<BTreeMap<String, u32>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub skip_embeddings: Option<bool>,
|
||||
pub indexes: Option<BTreeMap<String, DetailsExportIndexSettings>>,
|
||||
}
|
||||
|
||||
impl DetailsView {
|
||||
|
@ -263,19 +263,9 @@ impl DetailsView {
|
|||
// So we return the first one we encounter but that shouldn't be an issue anyway.
|
||||
(Some(left), Some(_right)) => Some(left),
|
||||
},
|
||||
exported_documents: match (
|
||||
self.exported_documents.clone(),
|
||||
other.exported_documents.clone(),
|
||||
) {
|
||||
indexes: match (self.indexes.clone(), other.indexes.clone()) {
|
||||
(None, None) => None,
|
||||
(None, Some(exp)) | (Some(exp), None) => Some(exp),
|
||||
// We should never be able to batch multiple exports at the same time.
|
||||
// So we return the first one we encounter but that shouldn't be an issue anyway.
|
||||
(Some(left), Some(_right)) => Some(left),
|
||||
},
|
||||
skip_embeddings: match (self.skip_embeddings, other.skip_embeddings) {
|
||||
(None, None) => None,
|
||||
(None, Some(skip)) | (Some(skip), None) => Some(skip),
|
||||
(None, Some(indexes)) | (Some(indexes), None) => Some(indexes),
|
||||
// We should never be able to batch multiple exports at the same time.
|
||||
// So we return the first one we encounter but that shouldn't be an issue anyway.
|
||||
(Some(left), Some(_right)) => Some(left),
|
||||
|
@ -369,9 +359,17 @@ impl From<Details> for DetailsView {
|
|||
Details::IndexSwap { swaps } => {
|
||||
DetailsView { swaps: Some(swaps), ..Default::default() }
|
||||
}
|
||||
Details::Export { url, api_key, exported_documents, skip_embeddings } => {
|
||||
DetailsView { exported_documents: Some(exported_documents), ..Default::default() }
|
||||
}
|
||||
Details::Export { url, api_key, indexes } => DetailsView {
|
||||
url: Some(url),
|
||||
api_key,
|
||||
indexes: Some(
|
||||
indexes
|
||||
.into_iter()
|
||||
.map(|(pattern, settings)| (pattern.to_string(), settings))
|
||||
.collect(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
Details::UpgradeDatabase { from, to } => DetailsView {
|
||||
upgrade_from: Some(format!("v{}.{}.{}", from.0, from.1, from.2)),
|
||||
upgrade_to: Some(format!("v{}.{}.{}", to.0, to.1, to.2)),
|
||||
|
|
|
@ -9,7 +9,7 @@ use milli::Object;
|
|||
use roaring::RoaringBitmap;
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use time::{Duration, OffsetDateTime};
|
||||
use utoipa::ToSchema;
|
||||
use utoipa::{schema, ToSchema};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::batches::BatchId;
|
||||
|
@ -158,8 +158,7 @@ pub enum KindWithContent {
|
|||
Export {
|
||||
url: String,
|
||||
api_key: Option<String>,
|
||||
indexes: Vec<IndexUidPattern>,
|
||||
skip_embeddings: bool,
|
||||
indexes: BTreeMap<IndexUidPattern, ExportIndexSettings>,
|
||||
},
|
||||
UpgradeDatabase {
|
||||
from: (u32, u32, u32),
|
||||
|
@ -172,6 +171,13 @@ pub struct IndexSwap {
|
|||
pub indexes: (String, String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExportIndexSettings {
|
||||
pub skip_embeddings: bool,
|
||||
pub filter: Option<String>,
|
||||
}
|
||||
|
||||
impl KindWithContent {
|
||||
pub fn as_kind(&self) -> Kind {
|
||||
match self {
|
||||
|
@ -280,14 +286,11 @@ impl KindWithContent {
|
|||
}),
|
||||
KindWithContent::DumpCreation { .. } => Some(Details::Dump { dump_uid: None }),
|
||||
KindWithContent::SnapshotCreation => None,
|
||||
KindWithContent::Export { url, api_key, indexes: _, skip_embeddings } => {
|
||||
Some(Details::Export {
|
||||
url: url.clone(),
|
||||
api_key: api_key.clone(),
|
||||
exported_documents: Default::default(),
|
||||
skip_embeddings: *skip_embeddings,
|
||||
})
|
||||
}
|
||||
KindWithContent::Export { url, api_key, indexes } => Some(Details::Export {
|
||||
url: url.clone(),
|
||||
api_key: api_key.clone(),
|
||||
indexes: indexes.into_iter().map(|(p, s)| (p.clone(), s.clone().into())).collect(),
|
||||
}),
|
||||
KindWithContent::UpgradeDatabase { from } => Some(Details::UpgradeDatabase {
|
||||
from: (from.0, from.1, from.2),
|
||||
to: (
|
||||
|
@ -354,14 +357,11 @@ impl KindWithContent {
|
|||
}),
|
||||
KindWithContent::DumpCreation { .. } => Some(Details::Dump { dump_uid: None }),
|
||||
KindWithContent::SnapshotCreation => None,
|
||||
KindWithContent::Export { url, api_key, indexes: _, skip_embeddings } => {
|
||||
Some(Details::Export {
|
||||
url: url.clone(),
|
||||
api_key: api_key.clone(),
|
||||
exported_documents: Default::default(),
|
||||
skip_embeddings: skip_embeddings.clone(),
|
||||
})
|
||||
}
|
||||
KindWithContent::Export { url, api_key, indexes } => Some(Details::Export {
|
||||
url: url.clone(),
|
||||
api_key: api_key.clone(),
|
||||
indexes: indexes.into_iter().map(|(p, s)| (p.clone(), s.clone().into())).collect(),
|
||||
}),
|
||||
KindWithContent::UpgradeDatabase { from } => Some(Details::UpgradeDatabase {
|
||||
from: *from,
|
||||
to: (
|
||||
|
@ -410,14 +410,11 @@ impl From<&KindWithContent> for Option<Details> {
|
|||
}),
|
||||
KindWithContent::DumpCreation { .. } => Some(Details::Dump { dump_uid: None }),
|
||||
KindWithContent::SnapshotCreation => None,
|
||||
KindWithContent::Export { url, api_key, indexes: _, skip_embeddings } => {
|
||||
Some(Details::Export {
|
||||
url: url.clone(),
|
||||
api_key: api_key.clone(),
|
||||
exported_documents: BTreeMap::default(),
|
||||
skip_embeddings: skip_embeddings.clone(),
|
||||
})
|
||||
}
|
||||
KindWithContent::Export { url, api_key, indexes } => Some(Details::Export {
|
||||
url: url.clone(),
|
||||
api_key: api_key.clone(),
|
||||
indexes: indexes.into_iter().map(|(p, s)| (p.clone(), s.clone().into())).collect(),
|
||||
}),
|
||||
KindWithContent::UpgradeDatabase { from } => Some(Details::UpgradeDatabase {
|
||||
from: *from,
|
||||
to: (
|
||||
|
@ -684,8 +681,7 @@ pub enum Details {
|
|||
Export {
|
||||
url: String,
|
||||
api_key: Option<String>,
|
||||
exported_documents: BTreeMap<String, u32>,
|
||||
skip_embeddings: bool,
|
||||
indexes: BTreeMap<IndexUidPattern, DetailsExportIndexSettings>,
|
||||
},
|
||||
UpgradeDatabase {
|
||||
from: (u32, u32, u32),
|
||||
|
@ -693,6 +689,23 @@ pub enum Details {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, ToSchema)]
|
||||
#[schema(rename_all = "camelCase")]
|
||||
pub struct DetailsExportIndexSettings {
|
||||
#[serde(flatten)]
|
||||
settings: ExportIndexSettings,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
matched_documents: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
exported_documents: Option<u64>,
|
||||
}
|
||||
|
||||
impl From<ExportIndexSettings> for DetailsExportIndexSettings {
|
||||
fn from(settings: ExportIndexSettings) -> Self {
|
||||
DetailsExportIndexSettings { settings, matched_documents: None, exported_documents: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl Details {
|
||||
pub fn to_failed(&self) -> Self {
|
||||
let mut details = self.clone();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue