From 22cde78a8b96020179b6bd119a3d41138e16aa4a Mon Sep 17 00:00:00 2001 From: "zhangxiaoyu.york" Date: Fri, 4 Dec 2026 14:56:54 +0800 Subject: [PATCH 1/2] Rust SDK documentation matches the published crate Describe stored credential discovery and renewal, document shipped route APIs, and point introductory pages to the Rust reference. Signed-off-by: zhangxiaoyu.york --- README.md | 2 +- docs/development/repository-guide.md | 1 + docs/getting-started/overview.md | 5 +- docs/getting-started/quickstart.md | 4 +- docs/getting-started/whats-included.md | 2 +- docs/reference/index.md | 2 +- docs/reference/rust-sdk.md | 72 +++++++++++++++++++------- sdk/rust/README.md | 16 +++--- 8 files changed, 68 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 8c5ec3f13c9..cbf6d6ba898 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,7 @@ SDK](./docs/getting-started/first-agent.md), are covered there too. | Integration | What it connects | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | | [Claude Code](./docs/features/integrations/claude-code.md), [Codex](./docs/features/integrations/codex.md), [Cursor](./docs/features/integrations/cursor.md) and [other MCP clients](./docs/features/integrations/mcp-clients.md) ([all integrations](./docs/features/integrations/index.md)) | Memory and code intelligence in your existing agent workflow. | -| [Python](./docs/reference/python-sdk.md), [TypeScript](./docs/reference/typescript-sdk.md), [Rust](./sdk/rust/README.md), [Go](./sdk/go/README.md), [.NET](./sdk/dotnet/README.md) and [HTTP](./docs/reference/operations.md) | Your own agents and applications. | +| [Python](./docs/reference/python-sdk.md), [TypeScript](./docs/reference/typescript-sdk.md), [Rust](./docs/reference/rust-sdk.md), [Go](./sdk/go/README.md), [.NET](./sdk/dotnet/README.md) and [HTTP](./docs/reference/operations.md) | Your own agents and applications. | | [Langfuse](./docs/features/integrations/langfuse.md) | Request traces, model costs, retrieval scores and prompt-version attribution. | | [ClickStack / HyperDX](./docs/features/integrations/clickstack.md) | OpenTelemetry traces, logs and metrics in ClickHouse. | diff --git a/docs/development/repository-guide.md b/docs/development/repository-guide.md index 951b09de68d..ce464d66875 100644 --- a/docs/development/repository-guide.md +++ b/docs/development/repository-guide.md @@ -9,6 +9,7 @@ What every top-level directory holds, where a concern lives inside `server/`, th | `server/` | the FastAPI server: domain packages (memory, code, tracker, …), the operation registry, workers, transports, CLI, settings | | `extractor/` | the reference extractor service (`loom_extractor/`): format detection and the document parsers, run outside the server; its image (`Dockerfile`, released as `ghcr.io/clickhouse/loom-extractor`) and lock (`uv.lock`); see [document extraction](../architecture/document-extraction.md) | | `sdk/python/` | the Python SDK, published as `clickhouse-loom` (`sdk/python/loom/`) | +| `sdk/rust/` | the Rust SDK, published as `clickhouse-loom` on crates.io with an independent version; async and optional blocking clients, generated contracts and examples | | `sdk/typescript/` | the TypeScript SDK, published as `@clickhouse/loom` (`sdk/typescript/src/`) | | `frontend/` | the React dashboard served at `/` (Vite + Tailwind); `src/`, Playwright specs in `e2e/`, `scripts/bundle_budget.mjs` | | `schemas/` | `migrations/` (numbered SQL), `schema.sql` (generated current shape), `otel/` (ClickStack OTel tables), `ops/` (hand-run SQL); see [`schemas/README.md`](../../schemas/README.md) | diff --git a/docs/getting-started/overview.md b/docs/getting-started/overview.md index e87ac9dc47e..0eaa86027fc 100644 --- a/docs/getting-started/overview.md +++ b/docs/getting-started/overview.md @@ -7,9 +7,8 @@ description: See how Loom stores searchable memory, documents, and code for agen Loom is a server that stores memory, documents, conversations, an entity graph and a code index for AI agents, as rows in ClickHouse, with [Postgres](../operations/postgres.md) as an option for live memory and knowledge state. -Agents and people reach it over MCP, HTTP, the Python and TypeScript SDKs, the -[Rust SDK](https://github.com/ClickHouse/loom/blob/main/sdk/rust/README.md), and the -dashboard. It is Apache-2.0. This page helps you decide whether it fits. +Agents and people reach it over MCP, HTTP, the Python, TypeScript and Rust SDKs, +and the dashboard. It is Apache-2.0. This page helps you decide whether it fits. ## What it does diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 045eebc4a21..273f4c837b4 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -484,11 +484,11 @@ cargo add clickhouse-loom To install from source, clone this repository and run `cargo add clickhouse-loom --path ../loom/sdk/rust`, adjusting the path to your clone. Installation and client configuration are in the -[Rust SDK installation](https://github.com/ClickHouse/loom/blob/main/sdk/rust/README.md#install). +[Rust SDK installation](../reference/rust-sdk.md#install). The client surfaces are in the [Python SDK](../reference/python-sdk.md) and [TypeScript SDK](../reference/typescript-sdk.md) references, and the -[Rust SDK usage](https://github.com/ClickHouse/loom/blob/main/sdk/rust/README.md#use). +[Rust SDK](../reference/rust-sdk.md) reference. ## 6. First memory from a coding agent diff --git a/docs/getting-started/whats-included.md b/docs/getting-started/whats-included.md index 0905bfe0895..2a4bab727af 100644 --- a/docs/getting-started/whats-included.md +++ b/docs/getting-started/whats-included.md @@ -71,4 +71,4 @@ Python, TypeScript and Rust SDKs, and the `loom` CLI: [Frameworks](../features/integrations/frameworks.md) · [HTTP API](../reference/http-api.md) · [Python SDK](../reference/python-sdk.md) · [TypeScript SDK](../reference/typescript-sdk.md) · -[Rust SDK](https://github.com/ClickHouse/loom/blob/main/sdk/rust/README.md) · [CLI](../reference/cli.md). +[Rust SDK](../reference/rust-sdk.md) · [CLI](../reference/cli.md). diff --git a/docs/reference/index.md b/docs/reference/index.md index a79762f6521..2af9d9ecc4b 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -42,7 +42,7 @@ Contributors can read how to update these pages in [Code generation](../developm | [Python SDK](./python-sdk.md) | Install, construction, calling ops, typed shapes, sessions and tools, framework adapters, errors, retries. | | [TypeScript SDK](./typescript-sdk.md) | Install, clients and options, typed ops, sessions and tools, pagination, the Strands adapter, errors, retries. | | [Go SDK](./go-sdk.md) | Install, save and recall agent memory, configure a team connection, and handle timeouts and errors. | -| [Rust SDK](./rust-sdk.md) | Install, async and blocking clients, generated contracts, identity, call options, errors and retries. | +| [Rust SDK](./rust-sdk.md) | Install, async and blocking clients, stored login renewal, generated contracts, routes, identity, call options, errors and retries. | | [Environment variables](./environment.md) | Variables read outside the settings model: provider keys, the image, compose files, the CLI, the SDKs and the operator scripts. | | [SQL surface](./sql-surface.md) | The read-only `sql_v1_*` views over a tenant's data: columns, compatibility rule, what they withhold, freshness, `loom sql-access`. | | [Extractor contract](./extractor-contract.md) | Version 1 of the HTTP contract an extractor service serves: capabilities, extraction, error codes, the artifact's fields and rules. | diff --git a/docs/reference/rust-sdk.md b/docs/reference/rust-sdk.md index 7b2a63f8a95..73fd7d51824 100644 --- a/docs/reference/rust-sdk.md +++ b/docs/reference/rust-sdk.md @@ -18,7 +18,6 @@ crates.io installation. The SDK source supports Rust 1.85+, but resolved dependencies can require a newer toolchain. The library leaves dependency locking to the application; commit your application's `Cargo.lock`. -The `0.1.2` crate provides `request` and `request_json` in both clients. HTTPS connections negotiate HTTP/2 over ALPN, with a fallback to HTTP/1.1. Plain HTTP uses HTTP/1.1. The SDK has its own version in the @@ -27,9 +26,10 @@ See the [operation reference](operations.md) for the server's current contracts. ## Save and read memory -For the local single-user server, org `dev`, namespace `local` and an empty token -match the quickstart. This async example uses the application's existing Tokio -runtime with `macros` and `rt-multi-thread` enabled: +For the local single-user server, org `dev` and namespace `local` match the +quickstart. For unauthenticated requests, no environment token, matching stored +login or legacy token may be present. This async example uses the application's +existing Tokio runtime with `macros` and `rt-multi-thread` enabled: ```rust use clickhouse_loom::{Client, SearchRequest, SetRequest}; @@ -38,7 +38,6 @@ use clickhouse_loom::{Client, SearchRequest, SetRequest}; async fn main() -> Result<(), Box> { let client = Client::builder("dev", "local", "rust-agent") .base_url("http://localhost:7777") - .api_key("") .build()?; let saved = client.set( SetRequest::new("deploy_window", "Deploy Tue/Thu") @@ -70,7 +69,8 @@ before using results as evidence. ## Configure a team connection Obtain a writer token for your org and namespace through **Settings → Tokens** -or your operator. The builder reads `LOOM_BASE_URL` and `LOOM_API_KEY`: +or your operator. The builder reads `LOOM_BASE_URL` and `LOOM_API_KEY` when no +explicit server or credential source takes precedence: ```rust use clickhouse_loom::Client; @@ -82,11 +82,46 @@ let client = Client::builder("my-org", "my-namespace", "rust-agent") ``` Set those environment variables in the process that runs your application. -Explicit `.base_url(...)` and `.api_key(...)` override them; `.api_key("")` -disables authorization. Empty environment values are unset. Without a server -address the default is `http://localhost:7777`; without a token the SDK sends -no Authorization header. `LOOM_ORG` and `LOOM_NAMESPACE` are example conventions, -not variables read by the client builder. +A nonempty `.api_key(...)` overrides `LOOM_API_KEY`. You can also use a stored +login: + +```bash +loom login --profile team +``` + +```rust +use clickhouse_loom::Client; + +let client = Client::builder("my-org", "my-namespace", "rust-agent") + .profile("team") + .build()?; +let memory = client.get("preference").await?; +println!("found={}", memory.found); +``` + +The profile supplies its server and rotating tokens. `.credential_provider(...)` +accepts application-owned credentials. Configure only one explicit credential +source. + +Without an explicit source or a nonempty `LOOM_API_KEY`, the SDK looks for the +`LOOM_PROFILE` profile (default `default`) matching the selected server, then +the legacy token file. `.api_key("")` and empty environment values do not turn +off this discovery. No resolved credential means no Authorization header. +An explicit `.base_url(...)` wins over a profile or provider's server, but must +match its binding. Otherwise that server takes precedence over `LOOM_BASE_URL`; +the default remains `http://localhost:7777`. + +Stored login renews an access token when it has at most 60 seconds left. If +renewal is temporarily unavailable, an unexpired token that has not been rejected +can still be used; otherwise, the call returns retryable `Error::Credentials`. +A revoked refresh token requires `loom login` again. On HTTP 401, the SDK asks +the provider to replace the rejected token and resends once only if it changed. +Fixed API keys are not refreshed. These rules apply to both clients and to routes +outside the op registry. See the +[authentication contract](https://github.com/ClickHouse/loom/blob/main/sdk/rust/README.md#authentication) +for credential precedence and renewal failures. +`LOOM_ORG` and `LOOM_NAMESPACE` are example conventions, not variables read by +the client builder. Org and the addressed namespace remain bound to the client. Bound identity fills declared caller and authorship fields. Reads with explicit row selectors @@ -128,15 +163,15 @@ preserve omitted fields as `None`. The SDK also provides `Client::call` for dotted operation names and JSON objects. Known operations retain generated identity and retry policies. -Unknown operations receive bound org and namespace, and retry only connection -failures before dispatch. The server authorizes every call. +Unknown operations receive bound org and namespace. The retry policy can resend +them after connection failures before dispatch or responses proving the handler +never ran, such as HTTP 408 or `AUTH_UNAVAILABLE`. The server authorizes every call. ## Routes outside the op registry -The SDK from this repository provides `request` and `request_json` for routes +Both clients provide `request` and `request_json` for routes outside the operation registry, such as `/v1/whoami` and `/v1/knowledge.upload`. -For a crates.io install, check the `Client` API for your version on -[docs.rs](https://docs.rs/clickhouse-loom). A `RouteRequest` carries the method, +A `RouteRequest` carries the method, a path on the server the client is bound to, query parameters and a JSON or raw body, all sent as given: @@ -227,7 +262,6 @@ use clickhouse_loom::blocking::Client; fn main() -> Result<(), Box> { let client = Client::builder("dev", "local", "rust-agent") .base_url("http://localhost:7777") - .api_key("") .build()?; println!("found={}", client.get("deploy_window")?.found); Ok(()) @@ -235,8 +269,8 @@ fn main() -> Result<(), Box> { ``` The blocking client owns a runtime thread and offers the same generated -operations and call options. When built from this repository, it also offers -routes outside the operation registry. Call it from an ordinary OS thread. +operations, call options and routes outside the operation registry. +Call it from an ordinary OS thread. Calling from a thread entered into Tokio returns `Error::Configuration`. ## Capabilities and examples diff --git a/sdk/rust/README.md b/sdk/rust/README.md index 81790778992..5128c7e5e50 100644 --- a/sdk/rust/README.md +++ b/sdk/rust/README.md @@ -321,8 +321,6 @@ when recall credit was not disclosed. An omitted risk label is empty in `SearchHit.governed` and `SearchResponse.term_leg`; `retrieval_risk` describes the other hits. -The typed error methods and retry behavior below are available in `0.1.2`. - ```rust use clickhouse_loom::Error; @@ -487,8 +485,8 @@ and a cumulative `X-Loom-Retry-Count` starting at 0. A final transport failure may follow a committed write. An independent call generates a different idempotency key; read the result before submitting it again. `Client` is `Clone`, `Send` and `Sync`. Clones share the HTTP connection pool -and rate state and can make concurrent calls. When built from this repository, -the SDK negotiates HTTP/2 over ALPN for `https` connections and falls back to +and rate state and can make concurrent calls. The SDK negotiates HTTP/2 over +ALPN for `https` connections and falls back to HTTP/1.1. Plain `http` uses HTTP/1.1. Dropping a call future or applying an external timeout stops requests, retry sleeps and pacing sleeps in that future. There are no detached retry tasks. Cancellation does not roll back a write or @@ -533,7 +531,7 @@ The server validates fields and authorizes every operation. ## Routes outside the op registry -The SDK built from this repository provides `request` and `request_json` for +The SDK provides `request` and `request_json` for routes outside the registry, such as `/v1/whoami`, `/v1/me/service_accounts.create` and `/v1/knowledge.upload`: @@ -616,11 +614,10 @@ methods without `.await`. ## Blocking calls -Enable the feature in the consuming application's `Cargo.toml`: +Enable the feature in the consuming application: -```toml -[dependencies] -clickhouse-loom = { path = "/path/to/loom/sdk/rust", features = ["blocking"] } +```bash +cargo add clickhouse-loom --features blocking ``` ```rust @@ -652,6 +649,7 @@ the call sequence, output and cleanup for each program: | [memory.rs](examples/memory.rs) | Save → read → lexical search → delete → confirm absence | | [operations.rs](examples/operations.rs) | Async memory, knowledge and context calls, per-call options, metadata and request `send` | | [blocking.rs](examples/blocking.rs) | The memory, knowledge and context flow with the blocking client | +| [renew_login.rs](examples/renew_login.rs) | Read memory using a stored login profile and its renewal credentials | | [agent_memory.rs](examples/agent_memory.rs) | Travel recall and grounded answers | | [document_search.rs](examples/document_search.rs) | Document citations and off-topic abstention | | [code_lookup.rs](examples/code_lookup.rs) | Selected code lookup with bounded evidence | From 555f428dd2e60bfaa56552f291bc1240c5548417 Mon Sep 17 00:00:00 2001 From: "zhangxiaoyu.york" Date: Fri, 4 Dec 2026 20:11:48 +0800 Subject: [PATCH 2/2] Rust SDK layout preserves translated table positions Keep the SDK description outside the existing layout table so committed translations retain their protected cell positions. Signed-off-by: zhangxiaoyu.york --- docs/development/repository-guide.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/development/repository-guide.md b/docs/development/repository-guide.md index ce464d66875..fc6128fe839 100644 --- a/docs/development/repository-guide.md +++ b/docs/development/repository-guide.md @@ -9,7 +9,6 @@ What every top-level directory holds, where a concern lives inside `server/`, th | `server/` | the FastAPI server: domain packages (memory, code, tracker, …), the operation registry, workers, transports, CLI, settings | | `extractor/` | the reference extractor service (`loom_extractor/`): format detection and the document parsers, run outside the server; its image (`Dockerfile`, released as `ghcr.io/clickhouse/loom-extractor`) and lock (`uv.lock`); see [document extraction](../architecture/document-extraction.md) | | `sdk/python/` | the Python SDK, published as `clickhouse-loom` (`sdk/python/loom/`) | -| `sdk/rust/` | the Rust SDK, published as `clickhouse-loom` on crates.io with an independent version; async and optional blocking clients, generated contracts and examples | | `sdk/typescript/` | the TypeScript SDK, published as `@clickhouse/loom` (`sdk/typescript/src/`) | | `frontend/` | the React dashboard served at `/` (Vite + Tailwind); `src/`, Playwright specs in `e2e/`, `scripts/bundle_budget.mjs` | | `schemas/` | `migrations/` (numbered SQL), `schema.sql` (generated current shape), `otel/` (ClickStack OTel tables), `ops/` (hand-run SQL); see [`schemas/README.md`](../../schemas/README.md) | @@ -31,6 +30,10 @@ What every top-level directory holds, where a concern lives inside `server/`, th | `AGENTS.md`, `CLAUDE.md` | the instructions every coding agent reads; `CLAUDE.md` imports `AGENTS.md` | | `.claude/`, `.agents/skills/` | the agents' skills, path-scoped rules, the read-only reviewer subagent and its hook, and project permission settings; `.agents/skills/` links each skill for Codex | +`sdk/rust/` holds the Rust SDK, published as `clickhouse-loom` on crates.io with an +independent version: async and optional blocking clients, generated contracts and +examples. + ## Inside server/ `server/` is organised by domain. A request enters through a transport, is dispatched by