sqlite_graphrag/embedding_api/mod.rs
1//! HTTP client for the OpenRouter embeddings API.
2//!
3//! Sends embedding requests to the OpenAI-compatible endpoint at
4//! `openrouter.ai/api/v1/embeddings` and returns dense `Vec<f32>`
5//! vectors. Handles retry with exponential backoff + jitter for
6//! transient failures (429, 5xx) and immediate abort for permanent
7//! errors (401, 400).
8
9use secrecy::SecretBox;
10
11// Default lives in constants; production clients resolve via runtime_config.
12
13const DEFAULT_TIMEOUT_SECS: u64 = crate::constants::DEFAULT_EMBEDDING_HTTP_TIMEOUT_SECS;
14const DEFAULT_CONNECT_TIMEOUT_SECS: u64 = 10;
15// Factory default for OpenRouter embed batching; runtime uses XDG
16// `embedding.batch_size` via [`crate::runtime_config::embedding_batch_size`].
17const DEFAULT_EMBED_HTTP_BATCH_SIZE: usize = crate::constants::FASTEMBED_BATCH_SIZE;
18
19mod client;
20mod error;
21mod mrl;
22#[cfg(test)]
23mod tests;
24mod transport;
25mod wire;
26
27// GAP-SG-146: split by responsibility. Every public item is re-exported here,
28// so `crate::embedding_api::OpenRouterClient` and `EmbedError` keep resolving
29// exactly as before for every caller inside and outside this module.
30pub use error::EmbedError;
31
32/// Open router client.
33pub struct OpenRouterClient {
34 client: reqwest::Client,
35 api_key: SecretBox<String>,
36 model: String,
37 dim: usize,
38 default_input_type: Option<&'static str>,
39 /// Endpoint each request is POSTed to. Resolved from XDG/config at
40 /// construction (default: [`DEFAULT_OPENROUTER_EMBEDDINGS_URL`]).
41 base_url: String,
42}