Skip to main content

quantum_sdk/
embeddings.rs

1use serde::{Deserialize, Serialize};
2
3use crate::client::Client;
4use crate::error::Result;
5
6/// Request body for text embeddings.
7#[derive(Debug, Clone, Serialize, Default)]
8pub struct EmbedRequest {
9    /// Embedding model (e.g. "text-embedding-3-small", "text-embedding-3-large").
10    pub model: String,
11
12    /// Texts to embed.
13    pub input: Vec<String>,
14}
15
16/// Response from text embedding.
17#[derive(Debug, Clone, Deserialize)]
18pub struct EmbedResponse {
19    /// Embedding vectors, one per input string.
20    pub embeddings: Vec<Vec<f64>>,
21
22    /// Model that generated the embeddings.
23    pub model: String,
24
25    /// Total cost in ticks.
26    #[serde(default)]
27    pub cost_ticks: i64,
28
29    /// Unique request identifier.
30    #[serde(default)]
31    pub request_id: String,
32}
33
34impl Client {
35    /// Generates text embeddings for the given inputs.
36    pub async fn embed(&self, req: &EmbedRequest) -> Result<EmbedResponse> {
37        let (mut resp, meta) = self
38            .post_json::<EmbedRequest, EmbedResponse>("/qai/v1/embeddings", req)
39            .await?;
40        if resp.cost_ticks == 0 {
41            resp.cost_ticks = meta.cost_ticks;
42        }
43        if resp.request_id.is_empty() {
44            resp.request_id = meta.request_id;
45        }
46        Ok(resp)
47    }
48}