Skip to main content

sie_sdk/
lib.rs

1//! Rust client for the [SIE](https://github.com/superlinked/sie) inference server.
2//!
3//! ```no_run
4//! use sie_sdk::{Client, Item, OutputType};
5//!
6//! # async fn example() -> sie_sdk::Result<()> {
7//! let client = Client::new("http://localhost:8080")?;
8//!
9//! let result = client
10//!     .encode("BAAI/bge-m3", [Item::text("Hello world")])
11//!     .output_types([OutputType::Dense, OutputType::Sparse])
12//!     .send_one()
13//!     .await?;
14//!
15//! println!("{:?}", result.dense);
16//! # Ok(())
17//! # }
18//! ```
19//!
20//! # Waiting for capacity
21//!
22//! SIE scales from zero and loads models on demand, so a request can legitimately be
23//! answered with "not yet". The client absorbs that: `PROVISIONING`, `MODEL_LOADING`,
24//! `LORA_LOADING` and `RESOURCE_EXHAUSTED` are retried inside a wall-clock budget
25//! (15 minutes by default) with bounded, jittered backoff. Endpoints that are not
26//! idempotent never replay a request that may already have reached a worker.
27//!
28//! Opt out per call when a failure is more useful than a wait:
29//!
30//! ```no_run
31//! # use sie_sdk::{Client, Item};
32//! # async fn example(client: Client) -> sie_sdk::Result<()> {
33//! let result = client
34//!     .encode("BAAI/bge-m3", [Item::text("Hello")])
35//!     .wait_for_capacity(false)
36//!     .max_oom_retries(0)
37//!     .send_one()
38//!     .await;
39//!
40//! if let Err(error) = &result
41//!     && error.is_capacity_error()
42//! {
43//!     // Fall back to a smaller model, or shed the request.
44//! }
45//! # Ok(())
46//! # }
47//! ```
48
49#![warn(missing_docs)]
50#![warn(clippy::pedantic)]
51#![allow(
52    // Fallibility is documented on the error type, not repeated on every method.
53    clippy::missing_errors_doc,
54    clippy::missing_panics_doc,
55    // Builder setters are the dominant shape here; annotating each one adds noise.
56    clippy::return_self_not_must_use,
57    clippy::must_use_candidate,
58    // Retry policy is a set of independent flags; a struct of bools is the point.
59    clippy::struct_excessive_bools,
60    clippy::module_name_repetitions,
61    // Numeric widths are chosen deliberately at each conversion site.
62    clippy::cast_possible_truncation,
63    clippy::cast_precision_loss,
64    clippy::cast_sign_loss,
65    clippy::cast_possible_wrap,
66    clippy::needless_pass_by_value
67)]
68
69#[cfg(feature = "blocking")]
70pub mod blocking;
71pub mod client;
72pub mod error;
73pub mod media;
74#[cfg(feature = "ndarray")]
75pub mod ndarray;
76pub mod redaction;
77pub mod retry;
78pub mod scoring;
79pub mod types;
80pub mod wire;
81
82mod http;
83
84#[cfg(feature = "watch")]
85pub use client::WatchMode;
86pub use client::jobs::{
87    connection_name, require_connection_name, require_connector_idempotency_key,
88};
89pub use client::{ChunkStream, Client, ClientBuilder};
90pub use error::{Error, ModelLoadErrorClass, Result, TransportErrorKind};
91pub use media::Samples;
92pub use retry::RequestOptions;
93pub use scoring::{maxsim, maxsim_batch};
94pub use types::{
95    AudioInput, BinaryInput, CapacityInfo, Classification, DType, DetectedObject, EncodeResult,
96    Entity, ExtractResult, HealthResponse, ImageInput, Item, ModelInfo, ModelState, Multivector,
97    OutputDType, OutputType, RequestMetadata, RequestUsage, ScoreResult, SparseVector, TimingInfo,
98};
99
100/// The version this SDK reports to the server.
101pub const VERSION: &str = env!("CARGO_PKG_VERSION");