Skip to main content

cortex_sdk/async_client/
ingest.rs

1use super::transport::decode_value;
2use super::AsyncCortexDbClient;
3use crate::http::path;
4use crate::{DeleteJobResponse, IngestResponse, IngestionJobResponse, SdkResult};
5
6impl AsyncCortexDbClient {
7    pub async fn ingest_text(
8        &self,
9        scope: &str,
10        source: &str,
11        text: &str,
12    ) -> SdkResult<serde_json::Value> {
13        self.post(
14            &path("/v1/ingest/text", &[("scope", scope), ("source", source)]),
15            text,
16        )
17        .await
18    }
19
20    pub async fn ingest_text_response(
21        &self,
22        scope: &str,
23        source: &str,
24        text: &str,
25    ) -> SdkResult<IngestResponse> {
26        decode_value(self.ingest_text(scope, source, text).await?)
27    }
28
29    pub async fn ingest_json(
30        &self,
31        scope: &str,
32        source: &str,
33        document: &str,
34    ) -> SdkResult<serde_json::Value> {
35        self.post(
36            &path("/v1/ingest/json", &[("scope", scope), ("source", source)]),
37            document,
38        )
39        .await
40    }
41
42    pub async fn ingest_json_response(
43        &self,
44        scope: &str,
45        source: &str,
46        document: &str,
47    ) -> SdkResult<IngestResponse> {
48        decode_value(self.ingest_json(scope, source, document).await?)
49    }
50
51    pub async fn ingest_csv(
52        &self,
53        scope: &str,
54        source: &str,
55        document: &str,
56    ) -> SdkResult<serde_json::Value> {
57        self.post(
58            &path("/v1/ingest/csv", &[("scope", scope), ("source", source)]),
59            document,
60        )
61        .await
62    }
63
64    pub async fn ingest_csv_response(
65        &self,
66        scope: &str,
67        source: &str,
68        document: &str,
69    ) -> SdkResult<IngestResponse> {
70        decode_value(self.ingest_csv(scope, source, document).await?)
71    }
72
73    pub async fn ingestion_job(&self, job_id: u64) -> SdkResult<serde_json::Value> {
74        self.get(&format!("/v1/ingest/jobs/{job_id}")).await
75    }
76
77    pub async fn ingestion_job_response(&self, job_id: u64) -> SdkResult<IngestionJobResponse> {
78        decode_value(self.ingestion_job(job_id).await?)
79    }
80
81    pub async fn delete_ingestion_job(&self, job_id: u64) -> SdkResult<DeleteJobResponse> {
82        decode_value(self.delete(&format!("/v1/ingest/jobs/{job_id}")).await?)
83    }
84
85    pub async fn retry_ingestion_job(&self, job_id: u64) -> SdkResult<IngestionJobResponse> {
86        decode_value(
87            self.post(&format!("/v1/ingest/jobs/{job_id}/retry"), "")
88                .await?,
89        )
90    }
91}