1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! Use ClickHouse Loom's memory, knowledge and context operations from Rust.
//!
//! Loom is a self-hosted server for shared long-term AI agent memory, document
//! search and code indexing. [`Client`] provides typed async methods for every
//! registered operation. Method names replace dots with underscores.
//! [`Client::call`] accepts a serializable request and a typed response,
//! including `serde_json::Value`.
//!
//! Identity is bound once on [`Client`]. Calls return typed responses, and
//! [`Error::Api`] preserves the server's error classification.
//! Search defaults to all agents with no user or session filter. Set filters on
//! [`SearchRequest`] explicitly. Builder identity values apply to declared identity
//! fields; optional reader filters keep the values in the request.
//! The default timeout covers each complete HTTP attempt for 60 seconds.
//! Search hits preserve chunk parent keys and provenance. Check [`SearchResponse`]
//! abstention, degradation and pending extraction before answering from the hits.
//! Calls use the application's Tokio runtime. Cloned clients share a connection pool.
//! [`RetryPolicy`] defaults to three attempts on connection failures, HTTP 408 and
//! 5xx, with exponential backoff. Writes reuse an idempotency key and can retry
//! incomplete responses; reads do not retry those failures by default.
//! 429 pacing has a separate 15 second sleep budget. Use
//! [`ClientBuilder::pacing`] and [`ClientBuilder::retry`] to configure both.
//! [`Client::with_retry`] creates a policy override sharing connections and rate state.
//! Dropping a call future cancels its retries and waits, but cannot undo a write.
//! Logs use the `log` facade without installing a logger or recording payloads.
//! Retries after dispatch require a known, declared idempotent operation.
//! Unknown operations receive bound org and namespace and retry only connection
//! failures. Operation names must be dotted identifiers.
//!
//! Enable the `blocking` feature for a synchronous client in the `blocking` module.
//! It runs the async transport on a dedicated thread and rejects calls on Tokio
//! runtime threads; use the async client there or call from a separate OS thread.
//!
//! # Capability probe
//!
//! [`Client::probe`] fetches fresh capabilities and reports missing operations
//! and request fields. A mismatch returns [`ProbeReport`] with `ok = false`;
//! HTTP and transport failures return [`Error`].
//!
//! ```
//! use clickhouse_loom::{Client, Error, ProbeRequest};
//!
//! # async fn example(client: Client) -> Result<(), Error> {
//! let report = client.probe(
//! ProbeRequest::new()
//! .ops(["memory.set", "memory.search"])
//! .fields("memory.set", ["tags"]),
//! ).await?;
//! println!("{}: {:?}", report.ok, report.missing_ops);
//! # Ok(())
//! # }
//! ```
//!
//! # Per-call options and metadata
//!
//! [`CallOptions`] overrides timeout, retry policy and request identifiers for
//! one call. The `*_with_options` methods return [`CallResult`] or [`CallFailure`].
//! Both carry final-attempt metadata; validation failures have no attempt metadata.
//! The original methods return their typed response and [`Error`].
//!
//! ```
//! use clickhouse_loom::{CallFailure, CallOptions, Client, RetryPolicy};
//! use std::time::Duration;
//!
//! # async fn example(client: Client) -> Result<(), CallFailure> {
//! let options = CallOptions::default()
//! .timeout(Duration::from_secs(5))
//! .retry(RetryPolicy::disabled())
//! .request_id("recall-1");
//! let result = client.get_with_options("preference", options).await?;
//! assert_eq!(result.metadata.sent_request_id, "recall-1");
//! println!("{} attempts={}", result.metadata.request_id, result.metadata.attempts);
//! # Ok(())
//! # }
//! ```
//!
//! # Using public types
//!
//! Request, response and API error structs are non-exhaustive.
//! Construct requests with `new`, then set their public options. Destructure responses
//! with `..`. Match errors with a fallback arm and [`Error::Protocol`] with `..`.
//!
//! Response decoding ignores unknown JSON fields. Missing required fields produce
//! [`Error::Protocol`].
//! The memory facade preserves its public types and decoding defaults.
//! Generated methods use full wire contracts such as [`MemorySetInput`] and
//! [`MemoryGetOutput`], without changing [`SetRequest`] or [`GetResponse`].
//!
//! ```
//! use clickhouse_loom::{ApiError, Error, GetResponse, SearchRequest, SetRequest};
//!
//! let mut write = SetRequest::new("preference", "Concise answers");
//! write.tags = Some(vec!["style".into()]);
//! let mut search = SearchRequest::new("answer style");
//! search.top_k = Some(10);
//!
//! fn found(response: GetResponse) -> bool {
//! let GetResponse { found, .. } = response;
//! found
//! }
//!
//! fn describe(error: Error) -> String {
//! match error {
//! Error::Api(api) => {
//! let ApiError { code, message, .. } = *api;
//! format!("{code}: {message}")
//! }
//! Error::Protocol { status, .. } => format!("Invalid response: {status}"),
//! other => other.to_string(),
//! }
//! }
//! ```
//!
//! Request structs cannot be constructed with a struct literal outside this crate:
//!
//! ```compile_fail,E0639
//! use clickhouse_loom::SearchRequest;
//!
//! let request = SearchRequest {
//! query: "answer style".into(),
//! top_k: None,
//! tags: None,
//! memory_type: None,
//! search_mode: None,
//! agent_id: None,
//! namespace_scope: None,
//! user_id: None,
//! session_id: None,
//! };
//! ```
//!
//! Match [`Error`] with a fallback arm:
//!
//! ```compile_fail,E0004
//! use clickhouse_loom::Error;
//!
//! fn describe(error: Error) -> String {
//! match error {
//! Error::Configuration(message) | Error::Input(message) => message,
//! Error::Transport(source) => source.to_string(),
//! Error::Protocol { source, .. } => source.to_string(),
//! Error::Api(api) => api.to_string(),
//! }
//! }
//! ```
//!
//! Destructure [`Error::Protocol`] with `..`:
//!
//! ```compile_fail,E0638
//! use clickhouse_loom::Error;
//!
//! fn describe(error: Error) -> String {
//! match error {
//! Error::Protocol { status, source } => format!("{status}: {source}"),
//! other => other.to_string(),
//! }
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use *;
pub use ;
pub use *;