Skip to main content

openai_interface/vector_stores/
update.rs

1//! Update a vector store via `POST /vector_stores/{vector_store_id}`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5
6use serde::Serialize;
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    rest::post::{Post, PostNoStream},
12    vector_stores::VectorStore,
13};
14
15/// Updates a vector store.
16#[derive(Debug, Clone, Serialize, Default)]
17pub struct UpdateVectorStoreRequest<'a> {
18    /// The ID of the vector store to update, e.g. `vs_...`.
19    #[serde(skip)]
20    pub vector_store_id: &'a str,
21    /// The new name of the vector store.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub name: Option<String>,
24    /// The new expiration policy of the store, as raw JSON
25    /// (`{"anchor": "last_active_at", "days": N}`).
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub expires_after: Option<serde_json::Value>,
28    /// The new metadata of the store. Passing `null` (i.e. `None` at
29    /// the JSON level, injectable through `extra_body`) clears it.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub metadata: Option<std::collections::HashMap<String, String>>,
32    /// Additional JSON properties flattened into the request body, for
33    /// fields not covered by the typed struct.
34    #[serde(flatten, skip_serializing_if = "Option::is_none")]
35    pub extra_body: Option<serde_json::Map<String, serde_json::Value>>,
36}
37
38impl Post for UpdateVectorStoreRequest<'_> {
39    fn is_streaming(&self) -> bool {
40        false
41    }
42
43    /// Builds the URL for the request.
44    ///
45    /// `base_url` should be like <https://api.openai.com/v1>
46    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
47        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
48        url.path_segments_mut()
49            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
50            .push("vector_stores")
51            .push(self.vector_store_id);
52        Ok(url.to_string())
53    }
54}
55
56impl PostNoStream for UpdateVectorStoreRequest<'_> {
57    type Response = VectorStore;
58}