openai_interface/vector_stores/
search.rs1use serde::Serialize;
7use url::Url;
8
9use crate::{
10 errors::OapiError,
11 rest::post::{Post, PostNoStream},
12};
13
14#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
16pub struct VectorStoreSearchResult {
17 #[serde(default)]
19 pub file_id: Option<String>,
20 #[serde(default)]
22 pub filename: Option<String>,
23 #[serde(default)]
25 pub score: Option<f64>,
26 #[serde(default)]
28 pub text: Option<Vec<String>>,
29 #[serde(default)]
31 pub attributes: Option<serde_json::Value>,
32}
33
34#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
36pub struct VectorStoreSearchResponse {
37 #[serde(default)]
39 pub object: Option<String>,
40 #[serde(default)]
42 pub search_query: Option<Vec<String>>,
43 #[serde(default)]
45 pub data: Vec<VectorStoreSearchResult>,
46 #[serde(default)]
48 pub has_more: Option<bool>,
49 #[serde(default)]
51 pub next_page: Option<String>,
52}
53
54crate::impl_from_str!(VectorStoreSearchResponse);
55
56#[derive(Debug, Clone, Serialize)]
58pub struct SearchVectorStoreRequest<'a> {
59 #[serde(skip)]
61 pub vector_store_id: &'a str,
62 pub query: Vec<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
67 pub rewrite_query: Option<bool>,
68 #[serde(skip_serializing_if = "Option::is_none")]
70 pub max_num_results: Option<u32>,
71 #[serde(skip_serializing_if = "Option::is_none")]
73 pub filters: Option<serde_json::Value>,
74 #[serde(skip_serializing_if = "Option::is_none")]
76 pub ranking_options: Option<serde_json::Value>,
77 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
80 pub extra_body_map: Option<serde_json::Map<String, serde_json::Value>>,
81}
82
83impl Post for SearchVectorStoreRequest<'_> {
84 fn is_streaming(&self) -> bool {
85 false
86 }
87
88 fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
92 let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
93 url.path_segments_mut()
94 .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
95 .push("vector_stores")
96 .push(self.vector_store_id)
97 .push("search");
98 Ok(url.to_string())
99 }
100}
101
102impl PostNoStream for SearchVectorStoreRequest<'_> {
103 type Response = VectorStoreSearchResponse;
104}