Principle:1broseidon Ketch Provider Registry Pattern
| Knowledge Sources | |
|---|---|
| Domains | Architecture, Provider_Registry |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
A design pattern in which each search surface (web, code, docs) keeps its backends in an explicitly-ordered, package-level registry of descriptors, so a new backend flows through config discovery, CLI/MCP descriptions, doctor, and auto/multi eligibility by appending one descriptor call.
Theoretical Basis
The provider registry decouples what a backend can do (described statically by a descriptor) from how it is selected (driven by the operator's config and the caller's mode). Each registry is an ordered list of `Provider` descriptors with: an `ID` and `Name` for display; `Usable` (a no-network precondition predicate); `New` (construction that accepts empty credentials and never contacts the service); `Probe` (the doctor health check); `Settings` (the config fields it owns); and surface-specific fields (`AutoRank`/`AutoEligible` for search, `Regexp`/`Qualifiers`/`PartialIndex` for code, `LibraryResolver` for docs).
Construction is gated by `Build`, which calls `Usable` before `New`, so an unconfigured backend fails with its `Setup` message rather than at query time. Registration is explicit, without `init()`, so the order is the stable presentation order and a missing registration is a visible diff. Every shared consumer derives from the slice, so a single append propagates everywhere.
Why three separate registries? Web search, code search, and docs search have different result types, query dialects, and capability sets. Sharing one interface would force the least-common-denominator and lose the per-surface fields (e.g. `Regexp`, `LibraryResolver`). The three `Searcher` interfaces are deliberately independent.
Usage
Use this pattern when a system has multiple interchangeable backends with different capabilities and config requirements, and you want adding a backend to be a one-file change that flows through every consumer. The descriptor-driven approach keeps provider-specific branches out of shared code: a new backend declares what it can do, and the shared consumers read that declaration.
Practical Guide
- Implement the backend in one Go file under `search/`, `code/`, or `docs/`: the `Searcher` interface, `New`, `Usable`, `Probe`.
- Declare settings on the descriptor (`config.KeyPool` for secrets, `config.Scalar` for URLs).
- Set `AutoRank`/`AutoEligible` to join the `auto` chain (search only).
- Add code/docs-specific descriptor fields as needed (`Regexp`, `Qualifiers`, `PartialIndex`, `LibraryResolver`).
- Append the descriptor call to the `providers` slice — no `init()`.
- Write tests; regenerate golden fixtures with `UPDATE_REGISTRY_GOLDENS=1 go test ./cmd/ ./doctor/`.
Related Pages
Implemented By
- Implementation:1broseidon_Ketch_search_Provider
- Implementation:1broseidon_Ketch_search_Searcher
- Implementation:1broseidon_Ketch_search_NewFromConfig
- Implementation:1broseidon_Ketch_code_Provider
- Implementation:1broseidon_Ketch_code_Searcher
- Implementation:1broseidon_Ketch_docs_Provider
- Implementation:1broseidon_Ketch_docs_Searcher
- Implementation:1broseidon_Ketch_configbase_Setting
- Implementation:1broseidon_Ketch_providers_slice