async_openai/
vector_stores.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::vectorstores::{
5 CreateVectorStoreRequest, DeleteVectorStoreResponse, ListVectorStoresResponse,
6 UpdateVectorStoreRequest, VectorStoreObject, VectorStoreSearchRequest,
7 VectorStoreSearchResultsPage,
8 },
9 vector_store_file_batches::VectorStoreFileBatches,
10 Client, RequestOptions, VectorStoreFiles,
11};
12
13pub struct VectorStores<'c, C: Config> {
14 client: &'c Client<C>,
15 pub(crate) request_options: RequestOptions,
16}
17
18impl<'c, C: Config> VectorStores<'c, C> {
19 pub fn new(client: &'c Client<C>) -> Self {
20 Self {
21 client,
22 request_options: RequestOptions::new(),
23 }
24 }
25
26 pub fn files(&self, vector_store_id: &str) -> VectorStoreFiles<'_, C> {
28 VectorStoreFiles::new(self.client, vector_store_id)
29 }
30
31 pub fn file_batches(&self, vector_store_id: &str) -> VectorStoreFileBatches<'_, C> {
33 VectorStoreFileBatches::new(self.client, vector_store_id)
34 }
35
36 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
38 pub async fn create(
39 &self,
40 request: CreateVectorStoreRequest,
41 ) -> Result<VectorStoreObject, OpenAIError> {
42 self.client
43 .post("/vector_stores", request, &self.request_options)
44 .await
45 }
46
47 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
49 pub async fn retrieve(&self, vector_store_id: &str) -> Result<VectorStoreObject, OpenAIError> {
50 self.client
51 .get(
52 &format!("/vector_stores/{vector_store_id}"),
53 &self.request_options,
54 )
55 .await
56 }
57
58 #[crate::byot(R = serde::de::DeserializeOwned)]
60 pub async fn list(&self) -> Result<ListVectorStoresResponse, OpenAIError> {
61 self.client
62 .get("/vector_stores", &self.request_options)
63 .await
64 }
65
66 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
68 pub async fn delete(
69 &self,
70 vector_store_id: &str,
71 ) -> Result<DeleteVectorStoreResponse, OpenAIError> {
72 self.client
73 .delete(
74 &format!("/vector_stores/{vector_store_id}"),
75 &self.request_options,
76 )
77 .await
78 }
79
80 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
82 pub async fn update(
83 &self,
84 vector_store_id: &str,
85 request: UpdateVectorStoreRequest,
86 ) -> Result<VectorStoreObject, OpenAIError> {
87 self.client
88 .post(
89 &format!("/vector_stores/{vector_store_id}"),
90 request,
91 &self.request_options,
92 )
93 .await
94 }
95
96 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
98 pub async fn search(
99 &self,
100 vector_store_id: &str,
101 request: VectorStoreSearchRequest,
102 ) -> Result<VectorStoreSearchResultsPage, OpenAIError> {
103 self.client
104 .post(
105 &format!("/vector_stores/{vector_store_id}/search"),
106 request,
107 &self.request_options,
108 )
109 .await
110 }
111}