# Knowledge Sea — Instructions for AI Assistants

> **Status:** CURRENT
> **Last verified:** 2026-11-28

Knowledge Sea is a public, read-only retrieval service for the Sri Lankan Efficiency Bar examination. It retrieves official source material from the current EB2026 corpus published at `https://eb2026.telegram365books.stream/kb/`.

The API is served by `sea-api.service` on Google `ebstudy-vm` at `127.0.0.1:8092`, exposed through Cloudflare at `https://api.telegram365books.stream`. It is not hosted on Oracle and is not the Eddy service. See `architecture.md` and `sites.md` for the verified topology.

## Source of truth and boundaries

When sources conflict, use this order:

1. **Live VM inspection** — read-only service, listener, and non-secret configuration evidence.
2. **Public HTTPS** — current reachability, published content, and observed API behavior.
3. **Local maintained source** — this branch's `tech/` tree and maintained service source.
4. **Project memory** — context only; never infrastructure truth.

For API behavior, observed live responses take precedence over a lagging
published schema, and every mismatch must be recorded rather than silently
normalized. For topology, use `architecture.md`, `sites.md`, and `state.md`;
for current access commands, use `ssh.md`. Do not infer current hosting from
project memory or from an old Oracle arrangement.

The public retrieval API requires no credentials. Do not request, invent, or
publish provider keys, Telegram tokens, or account secrets when using it.
Hermes is governed by the required/current owner-only policy; the effective
`TELEGRAM_ALLOWED_USERS` value and environment precedence over YAML were not
independently inspected. Future registered-user companions are **PLANNED — NOT
IMPLEMENTED** and remain separate from Hermes; see `hermes.md` and `security.md`.

## What Knowledge Sea provides

Knowledge Sea is a retrieval engine, not a model host. It does not generate answers or invoke an AI model. It exposes documented operations that an external AI assistant can call to look up official source material:

| Operation | Purpose |
|-----------|---------|
| `GET /v1/topics` | Discover current exam topics with weights, keywords, and clause counts |
| `GET /v1/topics/{id}` | Retrieve one topic's metadata (`label`, `exam_weight`, `keywords`, `clause_count`); the current response does not include clause IDs |
| `GET /v1/search?q=...` | Full-text search across clauses with snippets |
| `GET /v1/clause/{id}` | Retrieve an exact clause in full |
| `POST /v1/quote-check` | Verify that a quotation is verbatim inside a clause |
| `GET /v1/related/{id}` | List clauses a clause cites and clauses that cite it |
| `GET /v1/map/{book}` | Retrieve a route map |
| `POST /v1/tools/{name}` | Generic execution of a documented retrieval tool |
| `GET /health` | Service health |
| `GET /openapi.json` | Machine-readable API specification |

The live [OpenAPI document](https://api.telegram365books.stream/openapi.json) documents the public operations and intended schemas. Observed live responses establish current behavior when the document disagrees; for example, topic detail currently returns metadata without the `clause_ids` described by the specification. Do not rely on a hardcoded operation count or an old route spelling.

## API base URL

```text
https://api.telegram365books.stream
```

## No registration required

The public retrieval API requires no account, API key, cookies, or model-provider credentials. CORS is enabled for browser-based clients but is not authentication. This statement applies to the public API, not to account-gated Sea or Eddy model features.

## How an AI assistant should use this

### 1. Search before answering

When a user asks about EB2026 rules, do not answer corpus questions from memory. First call `GET /v1/search` with keywords from the question. Search the act, the duty, the sanction, and the procedure as separate queries if needed.

### 2. Use topics to choose search terms

Call `GET /v1/topics` to see the current topic router, then `GET /v1/topics/{id}` for a relevant topic's metadata. The path is plural: `/v1/topics/{id}`. The observed detail response contains `id`, `label`, `exam_weight`, `keywords`, and `clause_count`; it does **not** return clause IDs. Use the label and keywords to form searches instead of treating `clause_count` as a clause list or a total search-hit count.

### 3. Retrieve exact clauses

Once `GET /v1/search` returns a clause ID (for example `fr-156`, `ec1-c15`, or `pog-gp-0169`), call `GET /v1/clause/{id}` to get the full clause content, heading, part title, source URL, and canonical language. Search can return the same clause ID in more than one row when language or part variants exist, and `hits` counts returned rows; deduplicate IDs before retrieval.

### 4. Verify quotations

Before publishing any quotation from the corpus, call `POST /v1/quote-check` with the clause ID and exact quote. It returns `verified: true` only if the quote matches verbatim. If the clause is authoritative in Sinhala (Establishments Code Vol II), the result includes a caveat and the label `[English translation - not authoritative]`; include that label when using English text from such clauses. Quote-check reports the language of the record it checked; if that differs from a previously fetched clause record, re-fetch and report the discrepancy rather than combining the two variants.

### 5. Follow cross-references

Call `GET /v1/related/{id}` to see which clauses a clause cites and which clauses cite it.

### 6. Cite correctly

Cite clauses as `[fr-156]`, `[ec1-c15]`, `[pog-gp-0169]` — square brackets, lowercase, hyphen-separated. Never write "F.R. 156" or "(fr-156)". Include the book name and clause heading when quoting.

### 7. Do not invent provisions

If the current corpus does not cover a concept, say so. Do not fabricate clause IDs, text, or citations. Label general legal principles as general law, not as EB2026 corpus provisions.

### 8. Respect canonical-language metadata

Use each clause's `canonical_lang` and `authoritative` fields. Establishments Code Volume II is authoritative in Sinhala; its English text is a translation and must carry `[English translation - not authoritative]` when quoted.

## Current manifests

- API operations: https://api.telegram365books.stream/openapi.json
- Topic discovery: https://api.telegram365books.stream/v1/topics
- Corpus dump: https://eb2026.telegram365books.stream/kb/all.ndjson
- Human-readable source: https://eb2026.telegram365books.stream/kb/

Discover current content from these manifests instead of trusting book, clause, record, or tool counts copied into prose or memory.

## Rate limits

The API applies conservative per-IP rate limits. Search operations have stricter limits than clause retrieval. If you receive a 429, slow down and retry after the window resets.

## Errors

Errors are returned as JSON with an `error` field and optional `detail`. Do not expose credentials or stack traces to users.

## Examples

See `api-examples.md` for request and response examples, and `endpoints.md` for the full public route summary.
