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 FailedEmbedding {
76 pub entity: String,
78 pub error: String,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct BatchEmbeddingResponse {
85 pub embeddings: Vec<EmbeddingResponse>,
87 pub failed: Vec<FailedEmbedding>,
91 pub total_time_ms: f64,
93 pub cache_hits: usize,
95 pub cache_misses: usize,
97 pub model_id: Uuid,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct TextEmbeddingRequest {
104 pub text: String,
106 pub text_type: Option<String>,
108 pub model_id: Option<Uuid>,
110 pub language: Option<String>,
112 pub use_cache: Option<bool>,
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct TextEmbeddingResponse {
119 pub text: String,
121 pub embedding: Vector,
123 pub detected_language: Option<String>,
125 pub model_id: Uuid,
127 pub from_cache: bool,
129 pub generation_time_ms: f64,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize)]
135pub struct MultiModalRequest {
136 pub text: Option<String>,
138 pub entities: Option<Vec<String>>,
140 pub model_id: Option<Uuid>,
142 pub fusion_strategy: Option<String>,
144 pub use_cache: Option<bool>,
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct MultiModalResponse {
151 pub embedding: Vector,
153 pub component_embeddings: HashMap<String, Vector>,
155 pub fusion_strategy: String,
157 pub model_id: Uuid,
159 pub from_cache: bool,
161 pub generation_time_ms: f64,
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize)]
167pub struct StreamEmbeddingRequest {
168 pub items: Vec<StreamEmbeddingItem>,
170 pub model_id: Option<Uuid>,
172 pub options: Option<BatchOptions>,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct StreamEmbeddingItem {
179 pub id: String,
181 pub content: String,
183 pub content_type: String,
185}
186
187#[derive(Debug, Clone, Serialize, Deserialize)]
189pub struct TripleScoreRequest {
190 pub subject: String,
192 pub predicate: String,
194 pub object: String,
196 pub model_id: Option<Uuid>,
198 pub model_version: Option<String>,
200 pub use_cache: Option<bool>,
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize)]
206pub struct TripleScoreResponse {
207 pub subject: String,
209 pub predicate: String,
211 pub object: String,
213 pub triple: (String, String, String),
215 pub score: f64,
217 pub model_id: Uuid,
219 pub model_version: String,
221 pub from_cache: bool,
223 pub computation_time_ms: f64,
225 pub scoring_time_ms: f64,
227}
228
229#[derive(Debug, Clone, Serialize, Deserialize)]
231pub struct PredictionRequest {
232 pub entities: Vec<String>,
234 pub prediction_type: PredictionType,
236 pub top_k: Option<usize>,
238 pub model_id: Option<Uuid>,
240 pub use_cache: Option<bool>,
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize)]
246pub enum PredictionType {
247 Objects { subject: String, predicate: String },
249 Subjects { predicate: String, object: String },
251 Relations { subject: String, object: String },
253}
254
255#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct PredictionResponse {
258 pub input: Vec<String>,
260 pub prediction_type: String,
262 pub predictions: Vec<(String, f64)>,
264 pub model_version: String,
266 pub from_cache: bool,
268 pub prediction_time_ms: f64,
270}
271
272#[derive(Debug, Clone, Serialize, Deserialize)]
274pub struct ModelInfoRequest {
275 pub model_id: Option<Uuid>,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct ModelInfoResponse {
282 pub stats: ModelStats,
284 pub health: ModelHealth,
286 pub capabilities: Vec<String>,
288 pub last_training: Option<TrainingStats>,
290}
291
292#[derive(Debug, Clone, Serialize, Deserialize)]
294pub struct ModelHealth {
295 pub status: HealthStatus,
297 pub last_check: DateTime<Utc>,
299 pub metrics: HealthMetrics,
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize)]
305pub enum HealthStatus {
306 Healthy,
308 Degraded,
310 Unhealthy,
312}
313
314#[derive(Debug, Clone, Serialize, Deserialize)]
316pub struct HealthMetrics {
317 pub avg_response_time_ms: f64,
319 pub requests_last_hour: u64,
321 pub error_rate_percent: f64,
323 pub memory_usage_mb: f64,
325}
326
327#[derive(Debug, Clone, Serialize, Deserialize)]
329pub struct QueryParams {
330 pub limit: Option<usize>,
332 pub offset: Option<usize>,
334 pub model_id: Option<Uuid>,
336 pub format: Option<String>,
338 pub detailed: Option<bool>,
340}