Repository navigation
feat(sdk): Phase M SDK simplification — ordinary-document SDKs, async, quickstarts, self-hosted bootstrap - #638
Conversation
NativeNamespace._call and AsyncNamespace._call join the action onto
ns_path(ns, action) = /v1/namespaces/{ns}/{action}, so _call("POST",
"search", ...) is not a legacy unversioned route, same as client.py's
_request.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---kosha-bench---
microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory)
corpus: 8 segments × 4000 docs (32000 total), vocab ~20000
runner: Darwin 25.5.0 arm64 | rustc 1.97.1 (8bab26f4f 2026-07-14) | 2026-11-29T04:52:41Z
latency (v2 = current lazy format, median of inner samples):
cold broad ("the") 5.3 ms
warm broad ("the") 0.37 ms
warm 2-term AND 0.41 ms
warm phrase 0.39 ms
warm wildcard w1* 126.18 ms
---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[email protected]> # Conflicts: # clients/python/README.md
Co-Authored-By: Ravi Decover AI <[email protected]>
…ures (Phase M) Co-Authored-By: Ravi Decover AI <[email protected]>
…ase checks (Phase M) Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:42:32Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 4.1 ms warm broad ("the") 0.27 ms warm 2-term AND 0.27 ms warm phrase 0.27 ms warm wildcard w1* 102.16 ms ---end kosha-bench---
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
…e-m-sdk
---kosha-bench---
microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory)
corpus: 8 segments × 4000 docs (32000 total), vocab ~20000
runner: Linux 6.6.141 x86_64 | rustc 1.100.1 (20ddd0171 2026-11-25) | 2026-11-29T06:44:09Z
latency (v2 = current lazy format, median of inner samples):
cold broad ("the") 2.8 ms
warm broad ("the") 0.10 ms
warm 2-term AND 0.14 ms
warm phrase 0.09 ms
warm wildcard w1* 44.59 ms
---end kosha-bench---
e2f2ed7 to
00c3df7
Compare
Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:44:12Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 4.1 ms warm broad ("the") 0.26 ms warm 2-term AND 0.27 ms warm phrase 0.26 ms warm wildcard w1* 97.16 ms ---end kosha-bench---
kNN microbench — main vs this PR (
|
| metric | before | after | Δ | limit | |
|---|---|---|---|---|---|
| warm kNN p50 | 0.36 ms | 0.33 ms | -7.7% | +25% | |
| p90 (not gated) | 0.43 ms | 0.39 ms | -7.8% | ||
| p99 (not gated) | 0.63 ms | 0.61 ms | -3.0% | ||
| warm hybrid p50 | 0.46 ms | 0.40 ms | -13.3% | +25% | |
| p90 (not gated) | 0.52 ms | 0.49 ms | -6.6% | ||
| p99 (not gated) | 0.58 ms | 0.58 ms | +0.7% | ||
| cold kNN p50 | 2.40 ms | 2.21 ms | -8.1% | +40% | |
| p90 (not gated) | 2.74 ms | 2.74 ms | +0.0% | ||
| p99 (not gated) | 3.53 ms | 3.19 ms | -9.8% | ||
| open all segments p50 | 1.13 ms | 1.13 ms | -0.3% | +40% | |
| p90 (not gated) | 1.25 ms | 1.21 ms | -3.2% | ||
| p99 (not gated) | 1.41 ms | 1.33 ms | -5.7% | ||
| postings probed / query | 100.0 | 100.0 | +0.0% | +10% |
corpus 8 segs × 4000 docs, dim 256, 64 clusters · latency fails only past both the % limit and an absolute floor · postings/query is deterministic · label perf-regression-accepted to accept an intended cost
⏱ Microbench — main vs this PR (
|
| metric | pctl | before (main) | after (PR) | Δ |
|---|---|---|---|---|
| cold broad ("the") | p50 | 2.83 ms | 3.21 ms | +13.7% |
| p90 | 3.84 ms | 4.36 ms | +13.6% |
|
| p99 | 4.14 ms | 4.55 ms | +9.9% | |
| warm broad ("the") | p50 | 0.093 ms | 0.095 ms | +2.3% |
| p90 | 0.098 ms | 0.116 ms | +17.8% |
|
| p99 | 0.110 ms | 0.137 ms | +24.5% |
|
| warm 2-term AND | p50 | 0.108 ms | 0.123 ms | +13.6% |
| p90 | 0.114 ms | 0.198 ms | +74.1% |
|
| p99 | 0.134 ms | 0.360 ms | +168.9% |
|
| warm 3-term AND broad | p50 | 0.122 ms | 0.154 ms | +26.8% |
| p90 | 0.158 ms | 0.159 ms | +1.2% | |
| p99 | 0.169 ms | 0.167 ms | -1.3% | |
| warm phrase | p50 | 0.083 ms | 0.082 ms | -0.9% |
| p90 | 0.086 ms | 0.086 ms | -0.1% | |
| p99 | 0.099 ms | 0.102 ms | +2.9% | |
| warm wildcard w1* | p50 | 43.1 ms | 43.1 ms | +0.1% |
| p90 | 48.3 ms | 50.0 ms | +3.4% | |
| p99 | 56.0 ms | 61.6 ms | +10.1% |
|
| resident while open | — | 13.1 MiB | 13.1 MiB | +0.0% |
corpus 8 segs × 4000 docs · cold n=25, warm n=200 · nearest-rank percentiles · deltas within ±10% are usually runner noise
Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:53:48Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 4.2 ms warm broad ("the") 0.27 ms warm 2-term AND 0.27 ms warm phrase 0.26 ms warm wildcard w1* 107.80 ms ---end kosha-bench---
…e SDK from a clean copy Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:53:58Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.0 ms warm broad ("the") 0.32 ms warm 2-term AND 0.31 ms warm phrase 0.26 ms warm wildcard w1* 97.20 ms ---end kosha-bench---
…filters Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:08Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.1 ms warm broad ("the") 0.37 ms warm 2-term AND 0.31 ms warm phrase 0.28 ms warm wildcard w1* 101.83 ms ---end kosha-bench---
…oolean Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:17Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.1 ms warm broad ("the") 0.33 ms warm 2-term AND 0.30 ms warm phrase 0.28 ms warm wildcard w1* 104.59 ms ---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:27Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.0 ms warm broad ("the") 0.31 ms warm 2-term AND 0.30 ms warm phrase 0.28 ms warm wildcard w1* 111.02 ms ---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:37Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 4.0 ms warm broad ("the") 0.27 ms warm 2-term AND 0.26 ms warm phrase 0.31 ms warm wildcard w1* 98.34 ms ---end kosha-bench---
…cknowledged false Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:47Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.3 ms warm broad ("the") 0.34 ms warm 2-term AND 0.34 ms warm phrase 0.28 ms warm wildcard w1* 111.50 ms ---end kosha-bench---
Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:54:57Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.5 ms warm broad ("the") 0.34 ms warm 2-term AND 0.37 ms warm phrase 0.32 ms warm wildcard w1* 110.13 ms ---end kosha-bench---
… before the stack starts Co-Authored-By: Ravi Decover AI <[email protected]> ---kosha-bench--- microbenchmark: segment_memory (cargo bench -p kosha-query --bench segment_memory) corpus: 8 segments × 4000 docs (32000 total), vocab ~20000 runner: Linux 6.8.0-1060-aws x86_64 | rustc 1.99.1 (58cf8f9c3 2026-10-13) | 2026-11-29T06:58:12Z latency (v2 = current lazy format, median of inner samples): cold broad ("the") 6.1 ms warm broad ("the") 0.37 ms warm 2-term AND 0.31 ms warm phrase 0.28 ms warm wildcard w1* 107.62 ms ---end kosha-bench---
There was a problem hiding this comment.
Devin Review found 9 findings. Devin fixed 8 findings; 1 finding is left for you to triage below.
Fixed by Devin (8)
- Bootstrap rejects valid key configurations — The check now rejects only the real failure, an unquoted ';' in the KOSHA_API_KEYS line of .env. Entries without scopes, or with spaces, are accepted. The check now runs before the stack starts, not after.
- Durability smoke test deletes live data — The smoke test now refuses to start, before setting the cleanup trap, when deploy/selfhost/.env exists, so it can't delete a live deployment's volumes or credentials.
- Go rounds stored 64-bit integers — Added integerText: declared integers and filters now format int/uint/json.Number exactly, and DecodeValue returns int64 beyond 2^53. Covered by a new test using 9007199254740993.
- Async HTTPS proxy connections time out — A 2xx response to CONNECT is now treated as bodyless, so the tunnel starts TLS without waiting for EOF.
- Go search fails on consistency fallback — consistency_fallback is now a string reason in Go (*string), TypeScript (string), the shared fixture and the docs, matching the server.
- Quickstarts require namespace admin access — The self-host app key now has tenant-scoped namespace admin explicitly, so the create/delete calls in the quickstarts succeed. Verified live: the Python, TypeScript and Go checkout quickstarts pass against the bootstrapped stack.
- Async writes continue after client closure — After _open_connection returns, _exchange_once checks _closed. If the transport was closed, it closes the new connection and raises before writing any bytes.
- Self-hosted app keys gain admin access — Fixed the root cause: the key entry in .env is now single-quoted so
;scopes=survives sourcing, and bootstrap fails if the scopes are lost. The generated app key now explicitly has read+write+admin for tenantdefaultonly (no /v1/admin/*, no other tenants), so quickstarts can manage namespaces. The README documents this and shows how to add narrower keys.
| except _TRANSPORT_ERRORS as e: | ||
| conn = state.get("conn") | ||
| if conn is not None: | ||
| self._pool.discard_active(conn, abort=True) | ||
| is_timeout = isinstance(e, _TIMEOUT_ERRORS) | ||
| stale = bool(state.get("reused")) and not is_timeout | ||
| if stale: | ||
| self._pool.clear_idle(pool_key) | ||
| if resend_stale and not self._closed: | ||
| resend_stale = False | ||
| continue | ||
| before_write = (not state.get("sent")) or stale | ||
| e._kosha_before_write = before_write # type: ignore[attr-defined] |
There was a problem hiding this comment.
🟡 Async retries replay unconfirmed writes
When a reused socket loses a write response, _send marks the failure as pre-write even after sending bytes. The retry policy then replays non-idempotent operations without opt-in.
Devin left this for you to triage: The async transport matches the sync transport already on main (transport.py: if stale or not sent): a non-timeout failure on a reused keep-alive socket counts as pre-write, so a write the server already applied could be replayed. Fixing this changes the RETRY.md policy for both transports, so I recommend a separate follow-up that marks stale write failures as post-write in both, rather than diverging only in async here.
Learn more
The async SDK marks a request as sent before queueing it on the socket. A connection reset or truncated HTTP body can happen after the server has already committed a write. The retry path nevertheless treats any non-timeout failure on a reused connection as proof the request was not sent. That bypasses the ordinary restriction on replaying namespace or branch creation.
Example: The server commits a branch on a reused connection but disconnects while sending its response. The SDK automatically sends the branch request again. The caller receives an already-exists error for the branch it just created.
Recommended fix: Do not infer before_write from connection reuse. Keep the read-only stale-connection resend, but use the recorded send state or positive evidence of a pre-write failure when deciding whether to replay writes.
Was this helpful? React with 👍 or 👎 to provide feedback.
What and why
Implements the open Phase M – SDK simplification milestone in one PR. Adding Kosha to an app is now: install the SDK, set
KOSHA_HOST/KOSHA_API_KEY, pick a namespace, write ordinary documents. The same code runs against managed and self-hosted Kosha.Closes #590, closes #591, closes #592, closes #593, closes #594, closes #595, closes #596, closes #597, closes #598. Includes the async Python client from #611 (merged in here), so #611 can be closed when this merges.
clients/SDK.mdcovers config precedence, immutable namespace handles, the ordinary-document type mapping (string→Text, number→Float, bool, date, numeric list of 8+→Vector, other lists and objects→Keyword JSON, explicittypesoverrides), normalized hits/results,total_exact, diagnostics, errors, the native escape hatch, and a compatibility matrix plus migration notes. Shared fixtures inclients/conformance/sdk/run in all three SDKs.Kosha/AsyncKosha/Namespace, TypeScriptkosha.namespace(), Goc.Namespace(). They providecreate,upsert(replace),update(merge),bulk_upsert,get,delete,delete_where,search,semantic_search,hybrid_search,count,aggregate,iterate,search_many, and the branch helpers, plus filter/aggregation builders (F.eq,F.range, ...). Wire-level APIs still exist under their own names: PythonNativeNamespace, TSNativeNamespace/ns.native, GoNativeNamespace/ns.Native().consistency_fallback, kNN/rerank degradation,rank_detailsand timings. Agtetotal relation is reported as a lower bound. Unknown options and unstorable values raise errors instead of being dropped. The OpenSearch adapter warns onput_mapping,put_settingsandindices.closeand returnsacknowledged: false(they raise whenKOSHA_COMPAT_STRICT=1). Unstorable_sourcevalues also warn.indices.flushnow calls the server.AsyncKoshaClientfrom feat(python): add AsyncKoshaClient with cancellation and lifecycle management #611 (non-blocking transport, cancellation, lifecycle) and the async ordinary facadeAsyncKosha.search_manyruns independent queries with bounded concurrency (max 32), keeps input order and returns errors per query. It is a client-side fan-out, not a server batch. Cursor iteration rejects sort, kNN, hybrid and rerank with a clear error.clients/examples/quickstart/run.sh {published|checkout}builds clean Python, Node and Go projects that need onlyKOSHA_HOSTandKOSHA_API_KEY: no checkout, no Rust, no flush. The new.github/workflows/sdk-onboarding.ymlruns them against a bootstrapped self-hosted server on PRs, after releases (it waits for the registries), and nightly.deploy/selfhost/has a pinned, pull-only Compose file (Postgres, RustFS, S3 WAL, named volumes, auth on).bootstrap.shgenerates the app and admin keys once (.env, mode 600), runs readiness and auth checks, and writeskosha.envfor the SDKs. The README covers durability guarantees, backup/restore and upgrades.scripts/smoke/selfhost_restart.shchecks that documents, deletes, updates, schema and branches survive a restart, adown/up, and loss of the cache volume.docs/quickstart.md, all three clients) now lead with the ordinary-document API.How it was tested
pytest clients/python/tests scripts/tests: 441 passed, 35 skipped. New:test_sdk.py,test_compat_594.py, and the async tests from feat(python): add AsyncKoshaClient with cancellation and lifecycle management #611.tsc --noEmit(src and tests), andvitest: 60 passed. New:test/sdk.test.ts.go vet ./...andgo test -race ./...pass. New:sdk_test.go.deploy/selfhost/bootstrap.sh(decoverai/kosha:0.2.0):selfhost_restart.shpassed all three restart scenarios.quickstart/run.sh checkoutpassed for Python, TypeScript and Go.semantic_search,hybrid_search,aggregateandlist_branchesreturned the expected results.Compatibility
/v1wire contract (proto/kosha/v1/kosha.proto, request/response JSON)There are no server changes. Breaking SDK changes, covered in the SDK.md migration notes:
kosha.namespace()and Goc.Namespace()now return the ordinary-document facade. The old wire handle isNativeNamespace(ns.native/ns.Native()).put_mapping,put_settingsandindices.closenow warn and returnacknowledged: falseinstead of a fake success.Checklist
cargo fmt --all -- --check(no Rust changes)cargo clippy --all-targets --all-features -- -D warnings(no Rust changes)cargo test --all-features(no Rust changes)make client-python-test(ifclients/pythonchanged)docker build -t kosha:ci .(if the Dockerfile or build configuration changed) (n/a)KOSHA_*variables have a row indocs/configuration.md(none on the server;KOSHA_COMPAT_STRICTis client-side and documented in SDK.md)Link to Devin session: https://app.devin.ai/sessions/de1fc62167094befaf572158d8ca85e6
Open in Devin Desktop: https://app.devin.ai/desktop/session/de1fc62167094befaf572158d8ca85e6?variant=devin
Requested by: @ravi-decoverai
👀 Devin fixed 8 findings · 1 finding for you to triage · Follow Devin's work