khive_runtime/embedding_warning.rs
1//! Response advisory for embedding inputs the service had to truncate.
2
3use crate::retrieval::{EmbeddingTruncationReport, EMBEDDING_INPUT_TRUNCATED_WARNING};
4
5/// Add the embedding-input advisory when the report records truncation.
6///
7/// An object response receives the existing one-element warnings array, replacing
8/// any previous warnings. Other response values and untruncated reports are unchanged.
9pub fn add_embedding_truncation_warning(
10 response: &mut serde_json::Value,
11 report: &EmbeddingTruncationReport,
12) {
13 if !report.any_truncated() {
14 return;
15 }
16 if let Some(object) = response.as_object_mut() {
17 object.insert(
18 "warnings".to_string(),
19 serde_json::json!([EMBEDDING_INPUT_TRUNCATED_WARNING]),
20 );
21 }
22}