1use crate::{ModelStats, TrainingStats, Vector};
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use std::collections::HashMap;
9use uuid::Uuid;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct EmbeddingRequest {
14 pub entity_id: String,
16 pub entity: String,
18 pub model_id: Option<Uuid>,
20 pub model_version: Option<String>,
22 pub use_cache: Option<bool>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct EmbeddingResponse {
29 pub entity_id: String,
31 pub entity: String,
33 pub embedding: Vector,
35 pub dimensions: usize,
37 pub model_id: Uuid,
39 pub model_version: String,
41 pub from_cache: bool,
43 pub generation_time_ms: f64,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct BatchEmbeddingRequest {
50 pub entity_ids: Vec<String>,
52 pub entities: Vec<String>,
54 pub model_id: Option<Uuid>,
56 pub model_version: Option<String>,
58 pub use_cache: Option<bool>,
60 pub options: Option<BatchOptions>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct BatchOptions {
67 pub use_cache: Option<bool>,
69 pub batch_size: Option<usize>,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct BatchEmbeddingResponse {
76 pub embeddings: Vec<EmbeddingResponse>,
78 pub total_time_ms: f64,
80 pub cache_hits: usize,
82 pub cache_misses: usize,
84 pub model_id: Uuid,
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct TextEmbeddingRequest {
91 pub text: String,
93 pub text_type: Option<String>,
95 pub model_id: Option<Uuid>,
97 pub language: Option<String>,
99 pub use_cache: Option<bool>,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
105pub struct TextEmbeddingResponse {
106 pub text: String,
108 pub embedding: Vector,
110 pub detected_language: Option<String>,
112 pub model_id: Uuid,
114 pub from_cache: bool,
116 pub generation_time_ms: f64,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct MultiModalRequest {
123 pub text: Option<String>,
125 pub entities: Option<Vec<String>>,
127 pub model_id: Option<Uuid>,
129 pub fusion_strategy: Option<String>,
131 pub use_cache: Option<bool>,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize)]
137pub struct MultiModalResponse {
138 pub embedding: Vector,
140 pub component_embeddings: HashMap<String, Vector>,
142 pub fusion_strategy: String,
144 pub model_id: Uuid,
146 pub from_cache: bool,
148 pub generation_time_ms: f64,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct StreamEmbeddingRequest {
155 pub items: Vec<StreamEmbeddingItem>,
157 pub model_id: Option<Uuid>,
159 pub options: Option<BatchOptions>,
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct StreamEmbeddingItem {
166 pub id: String,
168 pub content: String,
170 pub content_type: String,
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize)]
176pub struct TripleScoreRequest {
177 pub subject: String,
179 pub predicate: String,
181 pub object: String,
183 pub model_id: Option<Uuid>,
185 pub model_version: Option<String>,
187 pub use_cache: Option<bool>,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
193pub struct TripleScoreResponse {
194 pub subject: String,
196 pub predicate: String,
198 pub object: String,
200 pub triple: (String, String, String),
202 pub score: f64,
204 pub model_id: Uuid,
206 pub model_version: String,
208 pub from_cache: bool,
210 pub computation_time_ms: f64,
212 pub scoring_time_ms: f64,
214}
215
216#[derive(Debug, Clone, Serialize, Deserialize)]
218pub struct PredictionRequest {
219 pub entities: Vec<String>,
221 pub prediction_type: PredictionType,
223 pub top_k: Option<usize>,
225 pub model_id: Option<Uuid>,
227 pub use_cache: Option<bool>,
229}
230
231#[derive(Debug, Clone, Serialize, Deserialize)]
233pub enum PredictionType {
234 Objects { subject: String, predicate: String },
236 Subjects { predicate: String, object: String },
238 Relations { subject: String, object: String },
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize)]
244pub struct PredictionResponse {
245 pub input: Vec<String>,
247 pub prediction_type: String,
249 pub predictions: Vec<(String, f64)>,
251 pub model_version: String,
253 pub from_cache: bool,
255 pub prediction_time_ms: f64,
257}
258
259#[derive(Debug, Clone, Serialize, Deserialize)]
261pub struct ModelInfoRequest {
262 pub model_id: Option<Uuid>,
264}
265
266#[derive(Debug, Clone, Serialize, Deserialize)]
268pub struct ModelInfoResponse {
269 pub stats: ModelStats,
271 pub health: ModelHealth,
273 pub capabilities: Vec<String>,
275 pub last_training: Option<TrainingStats>,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct ModelHealth {
282 pub status: HealthStatus,
284 pub last_check: DateTime<Utc>,
286 pub metrics: HealthMetrics,
288}
289
290#[derive(Debug, Clone, Serialize, Deserialize)]
292pub enum HealthStatus {
293 Healthy,
295 Degraded,
297 Unhealthy,
299}
300
301#[derive(Debug, Clone, Serialize, Deserialize)]
303pub struct HealthMetrics {
304 pub avg_response_time_ms: f64,
306 pub requests_last_hour: u64,
308 pub error_rate_percent: f64,
310 pub memory_usage_mb: f64,
312}
313
314#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct QueryParams {
317 pub limit: Option<usize>,
319 pub offset: Option<usize>,
321 pub model_id: Option<Uuid>,
323 pub format: Option<String>,
325 pub detailed: Option<bool>,
327}