Skip to main content

openai_interface/vector_stores/
mod.rs

1//! The Vector Stores API: manage vector stores via `/vector_stores`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5//!
6//! Vector stores hold parsed, chunked and embedded file contents for
7//! use with the `file_search` tool of the Responses API. See
8//! [the OpenAI Vector Stores guide](https://platform.openai.com/docs/guides/retrieval#vector-stores).
9//!
10//! Submodules: [`create`], [`retrieve`], [`update`], [`delete`],
11//! [`list`], [`files`] (per-store file management) and [`search`]
12//! (semantic search over a store).
13
14pub mod create;
15pub mod delete;
16pub mod files;
17pub mod list;
18pub mod retrieve;
19pub mod search;
20pub mod update;
21
22/// The chunking strategy applied to a file inside a vector store.
23#[derive(Debug, Clone, serde::Deserialize)]
24#[serde(tag = "type", rename_all = "snake_case")]
25pub enum ChunkingStrategy {
26    /// The default strategy with configurable sizes.
27    Static {
28        /// The maximum number of tokens per chunk.
29        #[serde(default)]
30        max_chunk_size_tokens: Option<u64>,
31        /// The number of tokens overlapping between chunks.
32        #[serde(default)]
33        chunk_overlap_tokens: Option<u64>,
34    },
35    /// The automatic strategy (server decides chunk sizes).
36    #[serde(other)]
37    Auto,
38}
39
40/// The file counts of a vector store.
41#[derive(Debug, Clone, serde::Deserialize)]
42pub struct VectorStoreFileCounts {
43    /// The number of files currently being processed.
44    #[serde(default)]
45    pub in_progress: u64,
46    /// The number of files that failed to process.
47    #[serde(default)]
48    pub failed: u64,
49    /// The number of files that were cancelled.
50    #[serde(default)]
51    pub cancelled: u64,
52    /// The number of files that were processed successfully.
53    #[serde(default)]
54    pub completed: u64,
55    /// The total number of files.
56    #[serde(default)]
57    pub total: u64,
58}
59
60/// The status of a file inside a vector store.
61#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Deserialize)]
62#[serde(rename_all = "snake_case")]
63pub enum VectorStoreFileStatus {
64    /// The file is currently being processed.
65    InProgress,
66    /// The file was processed successfully.
67    Completed,
68    /// Processing failed; see `last_error`.
69    Failed,
70    /// Processing was cancelled.
71    Cancelled,
72}
73
74/// The last error of a vector store file.
75#[derive(Debug, Clone, serde::Deserialize)]
76pub struct VectorStoreFileError {
77    /// An error code identifying the failure mode.
78    #[serde(default)]
79    pub code: Option<String>,
80    /// A human-readable error message.
81    #[serde(default)]
82    pub message: Option<String>,
83}
84
85/// A vector store.
86#[derive(Debug, Clone, serde::Deserialize)]
87pub struct VectorStore {
88    /// The vector store ID, e.g. `vs_...`.
89    pub id: String,
90    /// The object type, always `vector_store`.
91    #[serde(default)]
92    pub object: Option<String>,
93    /// Unix timestamp (seconds) of when the store was created.
94    #[serde(default)]
95    pub created_at: Option<u64>,
96    /// Unix timestamp (seconds) of when the store was last active.
97    #[serde(default)]
98    pub last_active_at: Option<u64>,
99    /// The name of the store.
100    #[serde(default)]
101    pub name: Option<String>,
102    /// The number of bytes of storage used by the store.
103    #[serde(default)]
104    pub usage_bytes: Option<u64>,
105    /// The expiration policy of the store, as raw JSON
106    /// (`{"anchor": "last_active_at", "days": N}`).
107    #[serde(default)]
108    pub expires_after: Option<serde_json::Value>,
109    /// Unix timestamp (seconds) of when the store expires.
110    #[serde(default)]
111    pub expires_at: Option<u64>,
112    /// The file counts of the store.
113    #[serde(default)]
114    pub file_counts: Option<VectorStoreFileCounts>,
115    /// Arbitrary key-value metadata attached to the store.
116    #[serde(default)]
117    pub metadata: Option<std::collections::HashMap<String, String>>,
118    /// The status of the store (`completed`, `expired`, `in_progress`).
119    #[serde(default)]
120    pub status: Option<String>,
121}
122
123crate::impl_from_str!(VectorStore);
124
125/// A file inside a vector store.
126#[derive(Debug, Clone, serde::Deserialize)]
127pub struct VectorStoreFile {
128    /// The association ID, e.g. `vsf_...`.
129    pub id: String,
130    /// The object type, always `vector_store.file`.
131    #[serde(default)]
132    pub object: Option<String>,
133    /// The ID of the vector store this file belongs to.
134    #[serde(default)]
135    pub vector_store_id: Option<String>,
136    /// Unix timestamp (seconds) of when the file was added.
137    #[serde(default)]
138    pub created_at: Option<u64>,
139    /// The size of the file in bytes.
140    #[serde(default)]
141    pub size: Option<u64>,
142    /// The processing status of the file.
143    #[serde(default)]
144    pub status: Option<VectorStoreFileStatus>,
145    /// The last error of the file, when processing failed.
146    #[serde(default)]
147    pub last_error: Option<VectorStoreFileError>,
148    /// The chunking strategy applied to the file.
149    #[serde(default)]
150    pub chunking_strategy: Option<ChunkingStrategy>,
151    /// The attributes attached to the file (filterable at search
152    /// time), as raw JSON.
153    #[serde(default)]
154    pub attributes: Option<serde_json::Value>,
155}
156
157crate::impl_from_str!(VectorStoreFile);