zai_rs/knowledge/
document_reembedding.rs1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use validator::Validate;
5
6use crate::ZaiResult;
7use crate::client::ZaiClient;
8
9#[derive(Debug, Clone, Serialize, Deserialize, Validate, Default)]
11pub struct DocumentReembeddingBody {
12 #[serde(skip_serializing_if = "Option::is_none")]
14 #[validate(url)]
15 pub callback_url: Option<String>,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 pub callback_header: Option<BTreeMap<String, String>>,
19}
20
21pub struct DocumentReembeddingRequest {
26 document_id: String,
27 body: DocumentReembeddingBody,
28}
29
30impl DocumentReembeddingRequest {
31 pub fn new(document_id: impl Into<String>) -> Self {
33 Self {
34 document_id: document_id.into(),
35 body: DocumentReembeddingBody::default(),
36 }
37 }
38
39 pub fn with_callback_url(mut self, url: impl Into<String>) -> Self {
41 self.body.callback_url = Some(url.into());
42 self
43 }
44
45 pub fn with_callback_header(mut self, hdr: BTreeMap<String, String>) -> Self {
47 self.body.callback_header = Some(hdr);
48 self
49 }
50
51 pub async fn send_via(&self, client: &ZaiClient) -> ZaiResult<DocumentReembeddingResponse> {
53 self.body.validate()?;
54 let route = crate::client::routes::DOCUMENTS_REEMBED;
55 let url = client
56 .endpoints()
57 .resolve_route(route, &[&self.document_id])?;
58 client
59 .send_json::<_, DocumentReembeddingResponse>(route.method(), url, &self.body)
60 .await
61 }
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
66pub struct DocumentReembeddingResponse {
67 #[serde(skip_serializing_if = "Option::is_none")]
69 pub code: Option<i64>,
70 #[serde(skip_serializing_if = "Option::is_none")]
72 pub message: Option<String>,
73 #[serde(skip_serializing_if = "Option::is_none")]
75 pub timestamp: Option<u64>,
76}