trieve_client/apis/
chunk_api.rs

1/*
2 * Trieve API
3 *
4 * Trieve OpenAPI Specification. This document describes all of the operations available through the Trieve API.
5 *
6 * The version of the OpenAPI document: 0.11.7
7 * Contact: developers@trieve.ai
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::{apis::ResponseContent, models};
15
16/// struct for typed errors of method [`autocomplete`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AutocompleteError {
20    Status400(models::ErrorResponseBody),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`count_chunks`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum CountChunksError {
28    Status404(models::ErrorResponseBody),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`create_chunk`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum CreateChunkError {
36    Status400(models::ErrorResponseBody),
37    Status413(models::ErrorResponseBody),
38    Status426(models::ErrorResponseBody),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`delete_chunk`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum DeleteChunkError {
46    Status400(models::ErrorResponseBody),
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`delete_chunk_by_tracking_id`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum DeleteChunkByTrackingIdError {
54    Status400(models::ErrorResponseBody),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`generate_off_chunks`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GenerateOffChunksError {
62    Status400(models::ErrorResponseBody),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_chunk_by_id`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetChunkByIdError {
70    Status400(models::ErrorResponseBody),
71    Status404(models::ErrorResponseBody),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`get_chunk_by_tracking_id`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum GetChunkByTrackingIdError {
79    Status400(models::ErrorResponseBody),
80    Status404(models::ErrorResponseBody),
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`get_chunks_by_ids`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum GetChunksByIdsError {
88    Status400(models::ErrorResponseBody),
89    Status404(models::ErrorResponseBody),
90    UnknownValue(serde_json::Value),
91}
92
93/// struct for typed errors of method [`get_chunks_by_tracking_ids`]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(untagged)]
96pub enum GetChunksByTrackingIdsError {
97    Status400(models::ErrorResponseBody),
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`get_recommended_chunks`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum GetRecommendedChunksError {
105    Status400(models::ErrorResponseBody),
106    UnknownValue(serde_json::Value),
107}
108
109/// struct for typed errors of method [`get_suggested_queries`]
110#[derive(Debug, Clone, Serialize, Deserialize)]
111#[serde(untagged)]
112pub enum GetSuggestedQueriesError {
113    Status400(models::ErrorResponseBody),
114    UnknownValue(serde_json::Value),
115}
116
117/// struct for typed errors of method [`scroll_dataset_chunks`]
118#[derive(Debug, Clone, Serialize, Deserialize)]
119#[serde(untagged)]
120pub enum ScrollDatasetChunksError {
121    Status400(models::ErrorResponseBody),
122    UnknownValue(serde_json::Value),
123}
124
125/// struct for typed errors of method [`search_chunks`]
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(untagged)]
128pub enum SearchChunksError {
129    Status400(models::ErrorResponseBody),
130    UnknownValue(serde_json::Value),
131}
132
133/// struct for typed errors of method [`update_chunk`]
134#[derive(Debug, Clone, Serialize, Deserialize)]
135#[serde(untagged)]
136pub enum UpdateChunkError {
137    Status400(models::ErrorResponseBody),
138    UnknownValue(serde_json::Value),
139}
140
141/// struct for typed errors of method [`update_chunk_by_tracking_id`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum UpdateChunkByTrackingIdError {
145    Status400(models::ErrorResponseBody),
146    UnknownValue(serde_json::Value),
147}
148
149/// This route provides the primary autocomplete functionality for the API. This prioritize prefix matching with semantic or full-text search.
150pub async fn autocomplete(
151    configuration: &configuration::Configuration,
152    tr_dataset: &str,
153    autocomplete_req_payload: models::AutocompleteReqPayload,
154    x_api_version: Option<models::ApiVersion>,
155) -> Result<models::SearchResponseTypes, Error<AutocompleteError>> {
156    let local_var_configuration = configuration;
157
158    let local_var_client = &local_var_configuration.client;
159
160    let local_var_uri_str = format!(
161        "{}/api/chunk/autocomplete",
162        local_var_configuration.base_path
163    );
164    let mut local_var_req_builder =
165        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
166
167    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
168        local_var_req_builder =
169            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
170    }
171    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
172    if let Some(local_var_param_value) = x_api_version {
173        local_var_req_builder =
174            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
175    }
176    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
177        let local_var_key = local_var_apikey.key.clone();
178        let local_var_value = match local_var_apikey.prefix {
179            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
180            None => local_var_key,
181        };
182        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
183    };
184    local_var_req_builder = local_var_req_builder.json(&autocomplete_req_payload);
185
186    let local_var_req = local_var_req_builder.build()?;
187    let local_var_resp = local_var_client.execute(local_var_req).await?;
188
189    let local_var_status = local_var_resp.status();
190    let local_var_content = local_var_resp.text().await?;
191
192    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
193        serde_json::from_str(&local_var_content).map_err(Error::from)
194    } else {
195        let local_var_entity: Option<AutocompleteError> =
196            serde_json::from_str(&local_var_content).ok();
197        let local_var_error = ResponseContent {
198            status: local_var_status,
199            content: local_var_content,
200            entity: local_var_entity,
201        };
202        Err(Error::ResponseError(local_var_error))
203    }
204}
205
206/// This route can be used to determine the number of chunk results that match a search query including score threshold and filters. It may be high latency for large limits. There is a dataset configuration imposed restriction on the maximum limit value (default 10,000) which is used to prevent DDOS attacks. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
207pub async fn count_chunks(
208    configuration: &configuration::Configuration,
209    tr_dataset: &str,
210    count_chunks_req_payload: models::CountChunksReqPayload,
211) -> Result<models::CountChunkQueryResponseBody, Error<CountChunksError>> {
212    let local_var_configuration = configuration;
213
214    let local_var_client = &local_var_configuration.client;
215
216    let local_var_uri_str = format!("{}/api/chunk/count", local_var_configuration.base_path);
217    let mut local_var_req_builder =
218        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
219
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder =
222            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
223    }
224    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
225    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
226        let local_var_key = local_var_apikey.key.clone();
227        let local_var_value = match local_var_apikey.prefix {
228            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
229            None => local_var_key,
230        };
231        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
232    };
233    local_var_req_builder = local_var_req_builder.json(&count_chunks_req_payload);
234
235    let local_var_req = local_var_req_builder.build()?;
236    let local_var_resp = local_var_client.execute(local_var_req).await?;
237
238    let local_var_status = local_var_resp.status();
239    let local_var_content = local_var_resp.text().await?;
240
241    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
242        serde_json::from_str(&local_var_content).map_err(Error::from)
243    } else {
244        let local_var_entity: Option<CountChunksError> =
245            serde_json::from_str(&local_var_content).ok();
246        let local_var_error = ResponseContent {
247            status: local_var_status,
248            content: local_var_content,
249            entity: local_var_entity,
250        };
251        Err(Error::ResponseError(local_var_error))
252    }
253}
254
255/// Create new chunk(s). If the chunk has the same tracking_id as an existing chunk, the request will fail. Once a chunk is created, it can be searched for using the search endpoint. If uploading in bulk, the maximum amount of chunks that can be uploaded at once is 120 chunks. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
256pub async fn create_chunk(
257    configuration: &configuration::Configuration,
258    tr_dataset: &str,
259    create_chunk_req_payload_enum: models::CreateChunkReqPayloadEnum,
260) -> Result<models::ReturnQueuedChunk, Error<CreateChunkError>> {
261    let local_var_configuration = configuration;
262
263    let local_var_client = &local_var_configuration.client;
264
265    let local_var_uri_str = format!("{}/api/chunk", local_var_configuration.base_path);
266    let mut local_var_req_builder =
267        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
268
269    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
270        local_var_req_builder =
271            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
272    }
273    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
274    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
275        let local_var_key = local_var_apikey.key.clone();
276        let local_var_value = match local_var_apikey.prefix {
277            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
278            None => local_var_key,
279        };
280        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
281    };
282    local_var_req_builder = local_var_req_builder.json(&create_chunk_req_payload_enum);
283
284    let local_var_req = local_var_req_builder.build()?;
285    let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287    let local_var_status = local_var_resp.status();
288    let local_var_content = local_var_resp.text().await?;
289
290    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291        serde_json::from_str(&local_var_content).map_err(Error::from)
292    } else {
293        let local_var_entity: Option<CreateChunkError> =
294            serde_json::from_str(&local_var_content).ok();
295        let local_var_error = ResponseContent {
296            status: local_var_status,
297            content: local_var_content,
298            entity: local_var_entity,
299        };
300        Err(Error::ResponseError(local_var_error))
301    }
302}
303
304/// Delete a chunk by its id. If deleting a root chunk which has a collision, the most recently created collision will become a new root chunk. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
305pub async fn delete_chunk(
306    configuration: &configuration::Configuration,
307    tr_dataset: &str,
308    chunk_id: &str,
309) -> Result<(), Error<DeleteChunkError>> {
310    let local_var_configuration = configuration;
311
312    let local_var_client = &local_var_configuration.client;
313
314    let local_var_uri_str = format!(
315        "{}/api/chunk/{chunk_id}",
316        local_var_configuration.base_path,
317        chunk_id = crate::apis::urlencode(chunk_id)
318    );
319    let mut local_var_req_builder =
320        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
321
322    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
323        local_var_req_builder =
324            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
325    }
326    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
327    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
328        let local_var_key = local_var_apikey.key.clone();
329        let local_var_value = match local_var_apikey.prefix {
330            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
331            None => local_var_key,
332        };
333        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
334    };
335
336    let local_var_req = local_var_req_builder.build()?;
337    let local_var_resp = local_var_client.execute(local_var_req).await?;
338
339    let local_var_status = local_var_resp.status();
340    let local_var_content = local_var_resp.text().await?;
341
342    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
343        Ok(())
344    } else {
345        let local_var_entity: Option<DeleteChunkError> =
346            serde_json::from_str(&local_var_content).ok();
347        let local_var_error = ResponseContent {
348            status: local_var_status,
349            content: local_var_content,
350            entity: local_var_entity,
351        };
352        Err(Error::ResponseError(local_var_error))
353    }
354}
355
356/// Delete a chunk by tracking_id. This is useful for when you are coordinating with an external system and want to use the tracking_id to identify the chunk. If deleting a root chunk which has a collision, the most recently created collision will become a new root chunk. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
357pub async fn delete_chunk_by_tracking_id(
358    configuration: &configuration::Configuration,
359    tr_dataset: &str,
360    tracking_id: &str,
361) -> Result<(), Error<DeleteChunkByTrackingIdError>> {
362    let local_var_configuration = configuration;
363
364    let local_var_client = &local_var_configuration.client;
365
366    let local_var_uri_str = format!(
367        "{}/api/chunk/tracking_id/{tracking_id}",
368        local_var_configuration.base_path,
369        tracking_id = crate::apis::urlencode(tracking_id)
370    );
371    let mut local_var_req_builder =
372        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
373
374    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
375        local_var_req_builder =
376            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
377    }
378    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
379    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
380        let local_var_key = local_var_apikey.key.clone();
381        let local_var_value = match local_var_apikey.prefix {
382            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
383            None => local_var_key,
384        };
385        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
386    };
387
388    let local_var_req = local_var_req_builder.build()?;
389    let local_var_resp = local_var_client.execute(local_var_req).await?;
390
391    let local_var_status = local_var_resp.status();
392    let local_var_content = local_var_resp.text().await?;
393
394    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
395        Ok(())
396    } else {
397        let local_var_entity: Option<DeleteChunkByTrackingIdError> =
398            serde_json::from_str(&local_var_content).ok();
399        let local_var_error = ResponseContent {
400            status: local_var_status,
401            content: local_var_content,
402            entity: local_var_entity,
403        };
404        Err(Error::ResponseError(local_var_error))
405    }
406}
407
408/// This endpoint exists as an alternative to the topic+message resource pattern where our Trieve handles chat memory. With this endpoint, the user is responsible for providing the context window and the prompt and the conversation is ephemeral.
409pub async fn generate_off_chunks(
410    configuration: &configuration::Configuration,
411    tr_dataset: &str,
412    generate_off_chunks_req_payload: models::GenerateOffChunksReqPayload,
413) -> Result<String, Error<GenerateOffChunksError>> {
414    let local_var_configuration = configuration;
415
416    let local_var_client = &local_var_configuration.client;
417
418    let local_var_uri_str = format!("{}/api/chunk/generate", local_var_configuration.base_path);
419    let mut local_var_req_builder =
420        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
421
422    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
423        local_var_req_builder =
424            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
425    }
426    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
427    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
428        let local_var_key = local_var_apikey.key.clone();
429        let local_var_value = match local_var_apikey.prefix {
430            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
431            None => local_var_key,
432        };
433        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
434    };
435    local_var_req_builder = local_var_req_builder.json(&generate_off_chunks_req_payload);
436
437    let local_var_req = local_var_req_builder.build()?;
438    let local_var_resp = local_var_client.execute(local_var_req).await?;
439
440    let local_var_status = local_var_resp.status();
441    let local_var_content = local_var_resp.text().await?;
442
443    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
444        serde_json::from_str(&local_var_content).map_err(Error::from)
445    } else {
446        let local_var_entity: Option<GenerateOffChunksError> =
447            serde_json::from_str(&local_var_content).ok();
448        let local_var_error = ResponseContent {
449            status: local_var_status,
450            content: local_var_content,
451            entity: local_var_entity,
452        };
453        Err(Error::ResponseError(local_var_error))
454    }
455}
456
457/// Get a singular chunk by id.
458pub async fn get_chunk_by_id(
459    configuration: &configuration::Configuration,
460    tr_dataset: &str,
461    chunk_id: &str,
462    x_api_version: Option<models::ApiVersion>,
463) -> Result<models::ChunkReturnTypes, Error<GetChunkByIdError>> {
464    let local_var_configuration = configuration;
465
466    let local_var_client = &local_var_configuration.client;
467
468    let local_var_uri_str = format!(
469        "{}/api/chunk/{chunk_id}",
470        local_var_configuration.base_path,
471        chunk_id = crate::apis::urlencode(chunk_id)
472    );
473    let mut local_var_req_builder =
474        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
475
476    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
477        local_var_req_builder =
478            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
479    }
480    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
481    if let Some(local_var_param_value) = x_api_version {
482        local_var_req_builder =
483            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
484    }
485    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
486        let local_var_key = local_var_apikey.key.clone();
487        let local_var_value = match local_var_apikey.prefix {
488            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
489            None => local_var_key,
490        };
491        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
492    };
493
494    let local_var_req = local_var_req_builder.build()?;
495    let local_var_resp = local_var_client.execute(local_var_req).await?;
496
497    let local_var_status = local_var_resp.status();
498    let local_var_content = local_var_resp.text().await?;
499
500    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
501        serde_json::from_str(&local_var_content).map_err(Error::from)
502    } else {
503        let local_var_entity: Option<GetChunkByIdError> =
504            serde_json::from_str(&local_var_content).ok();
505        let local_var_error = ResponseContent {
506            status: local_var_status,
507            content: local_var_content,
508            entity: local_var_entity,
509        };
510        Err(Error::ResponseError(local_var_error))
511    }
512}
513
514/// Get a singular chunk by tracking_id. This is useful for when you are coordinating with an external system and want to use your own id as the primary reference for a chunk.
515pub async fn get_chunk_by_tracking_id(
516    configuration: &configuration::Configuration,
517    tr_dataset: &str,
518    tracking_id: &str,
519    x_api_version: Option<models::ApiVersion>,
520) -> Result<models::ChunkReturnTypes, Error<GetChunkByTrackingIdError>> {
521    let local_var_configuration = configuration;
522
523    let local_var_client = &local_var_configuration.client;
524
525    let local_var_uri_str = format!(
526        "{}/api/chunk/tracking_id/{tracking_id}",
527        local_var_configuration.base_path,
528        tracking_id = crate::apis::urlencode(tracking_id)
529    );
530    let mut local_var_req_builder =
531        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
532
533    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
534        local_var_req_builder =
535            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
536    }
537    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
538    if let Some(local_var_param_value) = x_api_version {
539        local_var_req_builder =
540            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
541    }
542    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
543        let local_var_key = local_var_apikey.key.clone();
544        let local_var_value = match local_var_apikey.prefix {
545            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
546            None => local_var_key,
547        };
548        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
549    };
550
551    let local_var_req = local_var_req_builder.build()?;
552    let local_var_resp = local_var_client.execute(local_var_req).await?;
553
554    let local_var_status = local_var_resp.status();
555    let local_var_content = local_var_resp.text().await?;
556
557    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
558        serde_json::from_str(&local_var_content).map_err(Error::from)
559    } else {
560        let local_var_entity: Option<GetChunkByTrackingIdError> =
561            serde_json::from_str(&local_var_content).ok();
562        let local_var_error = ResponseContent {
563            status: local_var_status,
564            content: local_var_content,
565            entity: local_var_entity,
566        };
567        Err(Error::ResponseError(local_var_error))
568    }
569}
570
571/// Get multiple chunks by multiple ids.
572pub async fn get_chunks_by_ids(
573    configuration: &configuration::Configuration,
574    tr_dataset: &str,
575    get_chunks_data: models::GetChunksData,
576    x_api_version: Option<models::ApiVersion>,
577) -> Result<Vec<models::ChunkReturnTypes>, Error<GetChunksByIdsError>> {
578    let local_var_configuration = configuration;
579
580    let local_var_client = &local_var_configuration.client;
581
582    let local_var_uri_str = format!("{}/api/chunks", local_var_configuration.base_path);
583    let mut local_var_req_builder =
584        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
585
586    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
587        local_var_req_builder =
588            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
589    }
590    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
591    if let Some(local_var_param_value) = x_api_version {
592        local_var_req_builder =
593            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
594    }
595    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
596        let local_var_key = local_var_apikey.key.clone();
597        let local_var_value = match local_var_apikey.prefix {
598            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
599            None => local_var_key,
600        };
601        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
602    };
603    local_var_req_builder = local_var_req_builder.json(&get_chunks_data);
604
605    let local_var_req = local_var_req_builder.build()?;
606    let local_var_resp = local_var_client.execute(local_var_req).await?;
607
608    let local_var_status = local_var_resp.status();
609    let local_var_content = local_var_resp.text().await?;
610
611    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
612        serde_json::from_str(&local_var_content).map_err(Error::from)
613    } else {
614        let local_var_entity: Option<GetChunksByIdsError> =
615            serde_json::from_str(&local_var_content).ok();
616        let local_var_error = ResponseContent {
617            status: local_var_status,
618            content: local_var_content,
619            entity: local_var_entity,
620        };
621        Err(Error::ResponseError(local_var_error))
622    }
623}
624
625/// Get multiple chunks by ids.
626pub async fn get_chunks_by_tracking_ids(
627    configuration: &configuration::Configuration,
628    tr_dataset: &str,
629    get_tracking_chunks_data: models::GetTrackingChunksData,
630    x_api_version: Option<models::ApiVersion>,
631) -> Result<Vec<models::ChunkReturnTypes>, Error<GetChunksByTrackingIdsError>> {
632    let local_var_configuration = configuration;
633
634    let local_var_client = &local_var_configuration.client;
635
636    let local_var_uri_str = format!("{}/api/chunks/tracking", local_var_configuration.base_path);
637    let mut local_var_req_builder =
638        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
639
640    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
641        local_var_req_builder =
642            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
643    }
644    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
645    if let Some(local_var_param_value) = x_api_version {
646        local_var_req_builder =
647            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
648    }
649    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
650        let local_var_key = local_var_apikey.key.clone();
651        let local_var_value = match local_var_apikey.prefix {
652            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
653            None => local_var_key,
654        };
655        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
656    };
657    local_var_req_builder = local_var_req_builder.json(&get_tracking_chunks_data);
658
659    let local_var_req = local_var_req_builder.build()?;
660    let local_var_resp = local_var_client.execute(local_var_req).await?;
661
662    let local_var_status = local_var_resp.status();
663    let local_var_content = local_var_resp.text().await?;
664
665    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
666        serde_json::from_str(&local_var_content).map_err(Error::from)
667    } else {
668        let local_var_entity: Option<GetChunksByTrackingIdsError> =
669            serde_json::from_str(&local_var_content).ok();
670        let local_var_error = ResponseContent {
671            status: local_var_status,
672            content: local_var_content,
673            entity: local_var_entity,
674        };
675        Err(Error::ResponseError(local_var_error))
676    }
677}
678
679/// Get recommendations of chunks similar to the positive samples in the request and dissimilar to the negative.
680pub async fn get_recommended_chunks(
681    configuration: &configuration::Configuration,
682    tr_dataset: &str,
683    recommend_chunks_request: models::RecommendChunksRequest,
684    x_api_version: Option<models::ApiVersion>,
685) -> Result<models::RecommendResponseTypes, Error<GetRecommendedChunksError>> {
686    let local_var_configuration = configuration;
687
688    let local_var_client = &local_var_configuration.client;
689
690    let local_var_uri_str = format!("{}/api/chunk/recommend", local_var_configuration.base_path);
691    let mut local_var_req_builder =
692        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
693
694    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
695        local_var_req_builder =
696            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
697    }
698    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
699    if let Some(local_var_param_value) = x_api_version {
700        local_var_req_builder =
701            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
702    }
703    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
704        let local_var_key = local_var_apikey.key.clone();
705        let local_var_value = match local_var_apikey.prefix {
706            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
707            None => local_var_key,
708        };
709        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
710    };
711    local_var_req_builder = local_var_req_builder.json(&recommend_chunks_request);
712
713    let local_var_req = local_var_req_builder.build()?;
714    let local_var_resp = local_var_client.execute(local_var_req).await?;
715
716    let local_var_status = local_var_resp.status();
717    let local_var_content = local_var_resp.text().await?;
718
719    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
720        serde_json::from_str(&local_var_content).map_err(Error::from)
721    } else {
722        let local_var_entity: Option<GetRecommendedChunksError> =
723            serde_json::from_str(&local_var_content).ok();
724        let local_var_error = ResponseContent {
725            status: local_var_status,
726            content: local_var_content,
727            entity: local_var_entity,
728        };
729        Err(Error::ResponseError(local_var_error))
730    }
731}
732
733/// This endpoint will generate 3 suggested queries based off a hybrid search using RAG with the query provided in the request body and return them as a JSON object.
734pub async fn get_suggested_queries(
735    configuration: &configuration::Configuration,
736    tr_dataset: &str,
737    suggested_queries_req_payload: models::SuggestedQueriesReqPayload,
738) -> Result<models::SuggestedQueriesResponse, Error<GetSuggestedQueriesError>> {
739    let local_var_configuration = configuration;
740
741    let local_var_client = &local_var_configuration.client;
742
743    let local_var_uri_str = format!(
744        "{}/api/chunk/suggestions",
745        local_var_configuration.base_path
746    );
747    let mut local_var_req_builder =
748        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
749
750    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
751        local_var_req_builder =
752            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
753    }
754    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
755    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
756        let local_var_key = local_var_apikey.key.clone();
757        let local_var_value = match local_var_apikey.prefix {
758            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
759            None => local_var_key,
760        };
761        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
762    };
763    local_var_req_builder = local_var_req_builder.json(&suggested_queries_req_payload);
764
765    let local_var_req = local_var_req_builder.build()?;
766    let local_var_resp = local_var_client.execute(local_var_req).await?;
767
768    let local_var_status = local_var_resp.status();
769    let local_var_content = local_var_resp.text().await?;
770
771    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
772        serde_json::from_str(&local_var_content).map_err(Error::from)
773    } else {
774        let local_var_entity: Option<GetSuggestedQueriesError> =
775            serde_json::from_str(&local_var_content).ok();
776        let local_var_error = ResponseContent {
777            status: local_var_status,
778            content: local_var_content,
779            entity: local_var_entity,
780        };
781        Err(Error::ResponseError(local_var_error))
782    }
783}
784
785/// Get paginated chunks from your dataset with filters and custom sorting. If sort by is not specified, the results will sort by the id's of the chunks in ascending order. Sort by and offset_chunk_id cannot be used together; if you want to scroll with a sort by then you need to use a must_not filter with the ids you have already seen. There is a limit of 1000 id's in a must_not filter at a time.
786pub async fn scroll_dataset_chunks(
787    configuration: &configuration::Configuration,
788    tr_dataset: &str,
789    scroll_chunks_req_payload: models::ScrollChunksReqPayload,
790) -> Result<models::ScrollChunksResponseBody, Error<ScrollDatasetChunksError>> {
791    let local_var_configuration = configuration;
792
793    let local_var_client = &local_var_configuration.client;
794
795    let local_var_uri_str = format!("{}/api/chunks/scroll", local_var_configuration.base_path);
796    let mut local_var_req_builder =
797        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
798
799    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
800        local_var_req_builder =
801            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
802    }
803    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
804    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
805        let local_var_key = local_var_apikey.key.clone();
806        let local_var_value = match local_var_apikey.prefix {
807            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
808            None => local_var_key,
809        };
810        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
811    };
812    local_var_req_builder = local_var_req_builder.json(&scroll_chunks_req_payload);
813
814    let local_var_req = local_var_req_builder.build()?;
815    let local_var_resp = local_var_client.execute(local_var_req).await?;
816
817    let local_var_status = local_var_resp.status();
818    let local_var_content = local_var_resp.text().await?;
819
820    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
821        serde_json::from_str(&local_var_content).map_err(Error::from)
822    } else {
823        let local_var_entity: Option<ScrollDatasetChunksError> =
824            serde_json::from_str(&local_var_content).ok();
825        let local_var_error = ResponseContent {
826            status: local_var_status,
827            content: local_var_content,
828            entity: local_var_entity,
829        };
830        Err(Error::ResponseError(local_var_error))
831    }
832}
833
834/// This route provides the primary search functionality for the API. It can be used to search for chunks by semantic similarity, full-text similarity, or a combination of both. Results' `chunk_html` values will be modified with `<b><mark>` tags for sub-sentence highlighting.
835pub async fn search_chunks(
836    configuration: &configuration::Configuration,
837    tr_dataset: &str,
838    search_chunks_req_payload: models::SearchChunksReqPayload,
839    x_api_version: Option<models::ApiVersion>,
840) -> Result<models::SearchResponseTypes, Error<SearchChunksError>> {
841    let local_var_configuration = configuration;
842
843    let local_var_client = &local_var_configuration.client;
844
845    let local_var_uri_str = format!("{}/api/chunk/search", local_var_configuration.base_path);
846    let mut local_var_req_builder =
847        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
848
849    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
850        local_var_req_builder =
851            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
852    }
853    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
854    if let Some(local_var_param_value) = x_api_version {
855        local_var_req_builder =
856            local_var_req_builder.header("X-API-Version", local_var_param_value.to_string());
857    }
858    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
859        let local_var_key = local_var_apikey.key.clone();
860        let local_var_value = match local_var_apikey.prefix {
861            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
862            None => local_var_key,
863        };
864        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
865    };
866    local_var_req_builder = local_var_req_builder.json(&search_chunks_req_payload);
867
868    let local_var_req = local_var_req_builder.build()?;
869    let local_var_resp = local_var_client.execute(local_var_req).await?;
870
871    let local_var_status = local_var_resp.status();
872    let local_var_content = local_var_resp.text().await?;
873
874    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
875        serde_json::from_str(&local_var_content).map_err(Error::from)
876    } else {
877        let local_var_entity: Option<SearchChunksError> =
878            serde_json::from_str(&local_var_content).ok();
879        let local_var_error = ResponseContent {
880            status: local_var_status,
881            content: local_var_content,
882            entity: local_var_entity,
883        };
884        Err(Error::ResponseError(local_var_error))
885    }
886}
887
888/// Update a chunk. If you try to change the tracking_id of the chunk to have the same tracking_id as an existing chunk, the request will fail. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
889pub async fn update_chunk(
890    configuration: &configuration::Configuration,
891    tr_dataset: &str,
892    update_chunk_req_payload: models::UpdateChunkReqPayload,
893) -> Result<(), Error<UpdateChunkError>> {
894    let local_var_configuration = configuration;
895
896    let local_var_client = &local_var_configuration.client;
897
898    let local_var_uri_str = format!("{}/api/chunk", local_var_configuration.base_path);
899    let mut local_var_req_builder =
900        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
901
902    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
903        local_var_req_builder =
904            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
905    }
906    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
907    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
908        let local_var_key = local_var_apikey.key.clone();
909        let local_var_value = match local_var_apikey.prefix {
910            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
911            None => local_var_key,
912        };
913        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
914    };
915    local_var_req_builder = local_var_req_builder.json(&update_chunk_req_payload);
916
917    let local_var_req = local_var_req_builder.build()?;
918    let local_var_resp = local_var_client.execute(local_var_req).await?;
919
920    let local_var_status = local_var_resp.status();
921    let local_var_content = local_var_resp.text().await?;
922
923    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
924        Ok(())
925    } else {
926        let local_var_entity: Option<UpdateChunkError> =
927            serde_json::from_str(&local_var_content).ok();
928        let local_var_error = ResponseContent {
929            status: local_var_status,
930            content: local_var_content,
931            entity: local_var_entity,
932        };
933        Err(Error::ResponseError(local_var_error))
934    }
935}
936
937/// Update a chunk by tracking_id. This is useful for when you are coordinating with an external system and want to use the tracking_id to identify the chunk. Auth'ed user or api key must have an admin or owner role for the specified dataset's organization.
938pub async fn update_chunk_by_tracking_id(
939    configuration: &configuration::Configuration,
940    tr_dataset: &str,
941    update_chunk_by_tracking_id_data: models::UpdateChunkByTrackingIdData,
942) -> Result<(), Error<UpdateChunkByTrackingIdError>> {
943    let local_var_configuration = configuration;
944
945    let local_var_client = &local_var_configuration.client;
946
947    let local_var_uri_str = format!(
948        "{}/api/chunk/tracking_id/update",
949        local_var_configuration.base_path
950    );
951    let mut local_var_req_builder =
952        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
953
954    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
955        local_var_req_builder =
956            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
957    }
958    local_var_req_builder = local_var_req_builder.header("TR-Dataset", tr_dataset.to_string());
959    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
960        let local_var_key = local_var_apikey.key.clone();
961        let local_var_value = match local_var_apikey.prefix {
962            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
963            None => local_var_key,
964        };
965        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
966    };
967    local_var_req_builder = local_var_req_builder.json(&update_chunk_by_tracking_id_data);
968
969    let local_var_req = local_var_req_builder.build()?;
970    let local_var_resp = local_var_client.execute(local_var_req).await?;
971
972    let local_var_status = local_var_resp.status();
973    let local_var_content = local_var_resp.text().await?;
974
975    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
976        Ok(())
977    } else {
978        let local_var_entity: Option<UpdateChunkByTrackingIdError> =
979            serde_json::from_str(&local_var_content).ok();
980        let local_var_error = ResponseContent {
981            status: local_var_status,
982            content: local_var_content,
983            entity: local_var_entity,
984        };
985        Err(Error::ResponseError(local_var_error))
986    }
987}