reddb_server/runtime/ai/
mod.rs1pub mod answer_cache_key;
16pub mod ask_response_envelope;
17pub mod audit_record_builder;
18pub mod batch_client;
19pub mod citation_parser;
20pub mod cost_guard;
21pub mod dedup_cache;
22pub mod determinism_decider;
23pub mod explain_plan_builder;
24pub mod grpc_ask_message;
25pub mod local_embedding;
26pub mod mcp_ask_tool;
27pub mod metrics;
28pub mod ner;
29pub mod pg_wire_ask_row_encoder;
30pub mod prompt_assembler;
31pub mod prompt_template;
32pub mod provider_capabilities;
33pub mod provider_failover;
34pub mod provider_gate;
35pub mod rrf_fuser;
36pub mod sources_fingerprint;
37pub mod sse_frame_encoder;
38pub mod strict_validator;
39pub mod text_chunker;
40pub mod transport;
41pub mod urn_codec;
42
43pub(crate) fn block_on_ai<F, T>(future: F) -> crate::RedDBResult<T>
44where
45 F: std::future::Future<Output = T> + Send + 'static,
46 T: Send + 'static,
47{
48 if let Ok(handle) = tokio::runtime::Handle::try_current() {
49 if matches!(
50 handle.runtime_flavor(),
51 tokio::runtime::RuntimeFlavor::MultiThread
52 ) {
53 return Ok(tokio::task::block_in_place(|| handle.block_on(future)));
54 }
55
56 return std::thread::Builder::new()
57 .name("reddb-ai-blocking".to_string())
58 .spawn(move || {
59 let runtime = tokio::runtime::Builder::new_current_thread()
60 .enable_all()
61 .build()
62 .map_err(|err| {
63 crate::RedDBError::Query(format!("failed to start AI runtime: {err}"))
64 })?;
65 Ok(runtime.block_on(future))
66 })
67 .map_err(|err| {
68 crate::RedDBError::Query(format!("failed to spawn AI runtime thread: {err}"))
69 })?
70 .join()
71 .map_err(|_| crate::RedDBError::Query("AI runtime thread panicked".to_string()))?;
72 }
73
74 let runtime = tokio::runtime::Builder::new_current_thread()
75 .enable_all()
76 .build()
77 .map_err(|err| crate::RedDBError::Query(format!("failed to start AI runtime: {err}")))?;
78 Ok(runtime.block_on(future))
79}