async_openai/vectorstores/
vector_stores.rs

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