openai-interface 0.13.0

A low-level Rust interface for the OpenAI API
Documentation
//! The Vector Stores API: manage vector stores via `/vector_stores`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.
//!
//! Vector stores hold parsed, chunked and embedded file contents for
//! use with the `file_search` tool of the Responses API. See
//! [the OpenAI Vector Stores guide](https://platform.openai.com/docs/guides/retrieval#vector-stores).
//!
//! Submodules: [`create`], [`retrieve`], [`update`], [`delete`],
//! [`list`], [`files`] (per-store file management) and [`search`]
//! (semantic search over a store).

pub mod create;
pub mod delete;
pub mod files;
pub mod list;
pub mod retrieve;
pub mod search;
pub mod update;

/// The chunking strategy applied to a file inside a vector store.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ChunkingStrategy {
    /// The default strategy with configurable sizes.
    Static {
        /// The maximum number of tokens per chunk.
        #[serde(default)]
        max_chunk_size_tokens: Option<u64>,
        /// The number of tokens overlapping between chunks.
        #[serde(default)]
        chunk_overlap_tokens: Option<u64>,
    },
    /// The automatic strategy (server decides chunk sizes).
    #[serde(other)]
    Auto,
}

/// The file counts of a vector store.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct VectorStoreFileCounts {
    /// The number of files currently being processed.
    #[serde(default)]
    pub in_progress: u64,
    /// The number of files that failed to process.
    #[serde(default)]
    pub failed: u64,
    /// The number of files that were cancelled.
    #[serde(default)]
    pub cancelled: u64,
    /// The number of files that were processed successfully.
    #[serde(default)]
    pub completed: u64,
    /// The total number of files.
    #[serde(default)]
    pub total: u64,
}

/// The status of a file inside a vector store.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VectorStoreFileStatus {
    /// The file is currently being processed.
    InProgress,
    /// The file was processed successfully.
    Completed,
    /// Processing failed; see `last_error`.
    Failed,
    /// Processing was cancelled.
    Cancelled,
}

/// The last error of a vector store file.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct VectorStoreFileError {
    /// An error code identifying the failure mode.
    #[serde(default)]
    pub code: Option<String>,
    /// A human-readable error message.
    #[serde(default)]
    pub message: Option<String>,
}

/// A vector store.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct VectorStore {
    /// The vector store ID, e.g. `vs_...`.
    pub id: String,
    /// The object type, always `vector_store`.
    #[serde(default)]
    pub object: Option<String>,
    /// Unix timestamp (seconds) of when the store was created.
    #[serde(default)]
    pub created_at: Option<u64>,
    /// Unix timestamp (seconds) of when the store was last active.
    #[serde(default)]
    pub last_active_at: Option<u64>,
    /// The name of the store.
    #[serde(default)]
    pub name: Option<String>,
    /// The number of bytes of storage used by the store.
    #[serde(default)]
    pub usage_bytes: Option<u64>,
    /// The expiration policy of the store, as raw JSON
    /// (`{"anchor": "last_active_at", "days": N}`).
    #[serde(default)]
    pub expires_after: Option<serde_json::Value>,
    /// Unix timestamp (seconds) of when the store expires.
    #[serde(default)]
    pub expires_at: Option<u64>,
    /// The file counts of the store.
    #[serde(default)]
    pub file_counts: Option<VectorStoreFileCounts>,
    /// Arbitrary key-value metadata attached to the store.
    #[serde(default)]
    pub metadata: Option<std::collections::HashMap<String, String>>,
    /// The status of the store (`completed`, `expired`, `in_progress`).
    #[serde(default)]
    pub status: Option<String>,
}

crate::impl_from_str!(VectorStore);

/// A file inside a vector store.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct VectorStoreFile {
    /// The association ID, e.g. `vsf_...`.
    pub id: String,
    /// The object type, always `vector_store.file`.
    #[serde(default)]
    pub object: Option<String>,
    /// The ID of the vector store this file belongs to.
    #[serde(default)]
    pub vector_store_id: Option<String>,
    /// Unix timestamp (seconds) of when the file was added.
    #[serde(default)]
    pub created_at: Option<u64>,
    /// The size of the file in bytes.
    #[serde(default)]
    pub size: Option<u64>,
    /// The processing status of the file.
    #[serde(default)]
    pub status: Option<VectorStoreFileStatus>,
    /// The last error of the file, when processing failed.
    #[serde(default)]
    pub last_error: Option<VectorStoreFileError>,
    /// The chunking strategy applied to the file.
    #[serde(default)]
    pub chunking_strategy: Option<ChunkingStrategy>,
    /// The attributes attached to the file (filterable at search
    /// time), as raw JSON.
    #[serde(default)]
    pub attributes: Option<serde_json::Value>,
}

crate::impl_from_str!(VectorStoreFile);