diqiu50 commented on code in PR #15067:
URL: https://github.com/apache/gravitino/pull/15067#discussion_r4640559426


##########
design-docs/gravitino-kb-article-design.md:
##########
@@ -0,0 +1,1055 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+# Design: Knowledge Base Articles
+
+## Background
+
+Gravitino manages data assets and their metadata. A [Glossary 
Term](glossary-design.md) gives a
+short definition of a business concept. Teams also need longer explanations: 
how revenue is
+calculated, why it differs from GMV, and which tables feed it. Today these 
explanations live in
+wikis and documents, apart from the terms and data they describe. Users and 
agents cannot find
+them through the same metadata APIs or follow managed links from an 
explanation to its data.
+
+A Knowledge Base (KB) Article is a text document managed under a metalake. It 
has a title, a
+Markdown or HTML body, an owner and a status. It can belong to several
+[Domains](domain-design.md) and link to terms and data assets across catalogs. 
Users and agents
+can search for an article, read it, and follow its bindings under their 
existing privileges.
+
+---
+
+## Goals
+
+1. **Article object**: add `KnowledgeBaseArticle` as metalake-scoped metadata 
with an immutable
+   name and stable numeric ID. A title can change without breaking references 
to the article.
+2. **Content and version storage**: store Markdown or HTML. Keep an internal 
snapshot of the
+   title, body, Domains and bindings for each effective content change, and 
expose the current
+   content only. Historical version reads are deferred.
+3. **Bindings**: link an article to terms and metadata objects. Support 
reverse lookup from
+   either target. A binding never grants access to data.
+4. **Domains**: organize and filter articles by zero or more Domains. 
Membership does not change
+   article privileges in this design.
+5. **Status and privileges**: support `DRAFT`, `APPROVED` and `DEPRECATED`, 
with immediate edits
+   and definition privileges granted on the metalake. `APPROVED` means 
available to agents;
+   it does not record a reviewer's decision.
+6. **Discovery**: search titles, synonyms and bodies, with Domain, status and 
owner filters.
+   Read-only MCP tools return readable `APPROVED` articles.
+7. **APIs and governance**: provide REST, Java and Python APIs, ownership, 
events and audit.
+   Concurrent writes must not leave content, snapshots and effective relations 
out of sync.
+
+---
+
+## Non-Goals
+
+1. **Review and publication approval**: content and status changes take effect 
immediately;
+   approval workflows and review APIs are outside the scope.
+2. **Domain-scoped or article-scoped definition grants**: definition 
privileges are granted on
+   the metalake. Domains group articles; they do not authorize access to an 
article.
+3. **Web UI and agent writes**: the design provides REST APIs and read-only 
MCP tools.
+   A web editor and agent write operations are outside the scope.
+4. **File ingestion, attachments and image upload**: the body is text. It may 
contain ordinary
+   external links, but Gravitino does not host files, extract text or fetch 
linked content.
+5. **Ranked, fuzzy or semantic search and RAG**: substring search is 
sufficient for this scope.
+   There is no embedding index or answer-generation service.
+6. **Inferred or transitive bindings**: words and links in the body do not 
create bindings.
+   Binding an article to a term does not bind it to that term's assets; 
binding a table does not
+   bind its columns.
+7. **Metric bindings and version pinning**: bind a Semantic Model as an 
object, not an individual
+   metric. A binding points to the target's identity and resolves its current 
state.
+8. **Historical version reads, article hierarchy, comparison and rollback**: 
public APIs and
+   Java/Python clients read current content only. Historical reads, comparison 
and rollback
+   are deferred. Articles form a flat list without parent-child relationships.
+
+---
+
+## Scope and Dependencies
+
+The design covers the following capabilities. The task references link each 
capability to its
+implementation work in [Task Breakdown](#task-breakdown).
+
+| Capability                                      | Scope                      
                       | Tasks   |
+| ----------------------------------------------- | 
------------------------------------------------- | ------- |
+| Article API, entity and four storage tables     | New first-class metadata 
and retained snapshots   | T1–T3   |
+| Definition privileges and ownership             | Metalake grants; 
current-owner checks             | T4      |
+| Domain membership                               | Explicit Article 
relations; filter and drop guard | T5      |
+| Term and asset bindings                         | Stable IDs, reverse lookup 
and lifecycle cleanup  | T6      |
+| REST, conditional editing and search            | DTOs, errors, summaries 
and OpenAPI               | T7–T8   |
+| Events and audit                                | Existing listener and 
audit mechanisms            | T9      |
+| Java, Python and read-only MCP                  | Same contracts and 
visibility as REST             | T10–T12 |
+| Integration, upgrade, performance and user docs | Release checks and 
documented operating limits    | T13–T14 |
+
+Domain integration requires stable Domain IDs, hierarchy lookup, access checks 
and deletion
+fencing. Term bindings require stable Term IDs, current-status lookup and 
deletion hooks.
+
+The four-table model stores a snapshot for each effective content change and 
uses `live_version`
+to select current content. Retaining snapshots preserves the exact title, 
body, Domains and
+bindings together, at the cost of additional storage and transactional writes.
+
+Public APIs and Java/Python clients expose current content only. Historical 
version lists and
+individual-version reads can later use the retained snapshots without changing 
these four
+tables or migrating current content. Historical reads must apply the article's 
current read
+check and resolve deleted target IDs without attaching them to same-name 
replacements.
+
+---
+
+## Usage Scenario
+
+1. An admin grants an analyst `CREATE_DEFINITION` and a reader 
`VIEW_DEFINITION` on a metalake.
+   The analyst also has access to Domain `Finance`, term `net-revenue` and 
table
+   `iceberg.sales.orders`.
+2. The analyst creates "Revenue Calculation Guide", with a Markdown body, 
Domain `Finance`,
+   the term and the table. The server generates a name if none is supplied. 
The analyst becomes
+   the owner; the default status is `APPROVED`, and version 1 takes effect 
immediately.
+3. The reader searches for a word from the body and loads the article. Its 
bindings lead to
+   the current term and table; each target still requires its own read 
privilege.
+4. The analyst loads the article and saves a new body and another binding with 
its `ETag`.
+   One new version becomes effective atomically. The response shows the 
current version;
+   the previous snapshot remains in storage.
+5. An agent acting as the reader calls `search_kb_articles`, then 
`get_kb_article`. It receives
+   the stored body with its format and only the bound objects it can read.
+6. To prepare content privately, the analyst can create or set the article to 
`DRAFT`. Only its
+   owner with CREATE, or a caller with MANAGE, can read it. Setting it to 
`APPROVED` makes it
+   available again without review.
+7. When the explanation is outdated, the owner sets it to `DEPRECATED`. It 
remains readable,
+   but agents stop returning it. The owner with CREATE or an admin with MANAGE 
can delete it
+   directly in any status. Deleting it removes neither the term nor the table.
+
+---
+
+## Design
+
+### Data model
+
+`KnowledgeBaseArticle` is directly under a metalake, alongside Tag, Policy and 
Domain. It is not
+under a catalog or schema, because an article can explain data from several 
catalogs.
+
+```text
+KnowledgeBaseArticle {
+  name, title, body: { format: MARKDOWN | HTML, content },
+  status: DRAFT | APPROVED | DEPRECATED, domains[], comment?, synonyms[],
+  sourceReference?, properties, version, audit_info
+}
+ArticleSnapshot { articleId, version, title, body, domainIds[], bindings[], 
audit_info }
+ArticleBinding { articleId, targetType, targetId, audit_info }
+ArticleDomain  { articleId, domainId, audit_info }
+```
+
+`ArticleSnapshot` is the internal representation of a stored content version. 
The Article's
+`version` identifies its current content snapshot; its ETag separately guards 
the store revision.
+
+- **Identity**: `metalake.articleName`. The name is immutable and unique in 
the metalake; the
+  internal numeric article ID is stable. Add `KNOWLEDGE_BASE_ARTICLE` to 
`MetadataObject.Type`
+  and `Entity.EntityType`, including the single-level object handling used by 
owner APIs.
+- **Explicit name**: accept 1 to 128 Unicode code points, using letters, 
digits, combining marks,
+  `_` and `-`, with at least one letter or digit. Reject other characters with 
`400`, including
+  `/`, backslash, whitespace and control characters. Preserve the supplied 
spelling and case.
+- **Generated name**: `name` is optional on create. Lower-case the title using 
`Locale.ROOT`,
+  preserve Unicode letters, digits and combining marks, and replace each run 
of other characters
+  with `-`. Trim leading/trailing `-` and cut to 128 Unicode code points 
without splitting a
+  character. Chinese text is preserved: `收入计算说明` becomes `收入计算说明`, and
+  `收入 Calculation Guide` becomes `收入-calculation-guide`. Do not transliterate 
to Pinyin.
+  Use `article-<shortId>` only when the result contains no Unicode letter or 
digit, such as an
+  emoji-only or punctuation-only title. The suffix is 8 random lower-case 
alphanumeric
+  characters, regenerated on collision. A derived-name collision adds `-2`, 
`-3`, and so on,
+  cutting the base further to keep the whole name within 128 code points. A 
duplicate explicit
+  name is `409`. Changing the title later never changes the generated name.
+- **Title**: required, nonblank after trimming, at most 512 characters. 
Compare titles after
+  trimming and ignoring case, independent of database collation. Among 
articles that are not
+  `DEPRECATED`, titles are unique within the metalake. Deprecation releases 
the title; leaving
+  `DEPRECATED` checks it again. A conflict is `409`. Different titles can 
generate the same
+  name, which is why generated names also need collision suffixes.
+- **Owner**: the creator becomes the owner through the existing Owner APIs. 
Owners may be users
+  or groups. Persist the relation in the existing `owner_meta` table: 
`metadata_object_id` is
+  the stable article ID, `metadata_object_type` is `KNOWLEDGE_BASE_ARTICLE`, 
and `metalake_id`
+  identifies its metalake. `owner_id` references the user or group ID and 
`owner_type` is `USER`
+  or `GROUP`; owner names are resolved from `user_meta` or `group_meta`. 
Integrate the Article
+  type with `OwnerMetaService` and the existing Owner APIs. No owner column is 
added to the
+  article tables, and ownership is not part of a content snapshot.
+- **Other fields**: `comment` is at most 256 characters. `synonyms` are 
trimmed, at most 128
+  characters each and at most 20 per article; remove duplicates ignoring case. 
They need not be
+  unique across articles. `sourceReference` is optional free text of at most 
1024 characters,
+  such as a wiki URL. It is not validated as a URL, followed or fetched. 
Render it as text unless
+  a client separately validates it as a safe link. `properties` is a string 
map.
+
+#### Body and input validation
+
+`body.format` is `MARKDOWN` or `HTML`, stored with each version. The server 
sanitizes every body
+on write, including raw HTML embedded in Markdown. Both formats use the same 
HTML allowlist:
+remove scripts, active elements, event-handler attributes and unsafe URLs, 
including
+`javascript:` and `data:` URLs and encoded variants. Preserve ordinary 
formatting and the safe
+parts of the original content. Clients also sanitize HTML when rendering.
+
+Limit `body.content` by UTF-8 byte length both before and after sanitization. 
The configurable
+limit defaults to 1 MiB (1,048,576 bytes); allowed settings are 1 through 
16,777,215 bytes, the
+MySQL `MEDIUMTEXT` capacity. An invalid setting prevents startup. An oversized 
request returns
+`400`, without truncation or a stored change. Use the same bounds for create 
and alter.
+
+#### Storage
+
+Persist articles through EntityStore. Add four tables to H2, MySQL and 
PostgreSQL schemas and
+upgrade scripts; use the existing owner and audit storage.
+
+| Table                      | Fields beyond common row metadata               
                                                                                
       | Unique key                                         | Other index       
                    |
+| -------------------------- | 
--------------------------------------------------------------------------------------------------------------------------------------
 | -------------------------------------------------- | 
------------------------------------- |
+| `kb_article_meta`          | `article_id`, `metalake_id`, `article_name`, 
`status`, `live_version`, `article_comment`, `synonyms`, `source_reference`, 
`properties` | `(metalake_id, article_name, deleted_at)`          | Primary 
key: `article_id`             |
+| `kb_article_version_info`  | `id`, `metalake_id`, `article_id`, `version`, 
`title`, `body_format`, `body_content`, `domains`, `bindings`, `version_status` 
         | `(article_id, version, deleted_at)`                | `(metalake_id)` 
                      |
+| `kb_article_relation_meta` | `id`, `article_id`, `target_id`, `target_type`  
                                                                                
       | `(article_id, target_id, target_type, deleted_at)` | `(target_id, 
target_type)`            |
+| `kb_article_domain_rel`    | `id`, `article_id`, `domain_id`                 
                                                                                
       | `(article_id, domain_id, deleted_at)`              | `(domain_id, 
deleted_at, article_id)` |
+
+- Follow `tag_meta`, `tag_relation_meta` and `semantic_model_version_info`: 
numeric IDs,
+  `audit_info`, `deleted_at`, and `utf8mb4_bin` for MySQL. The article ID is 
an entity ID; the
+  other tables have an auto-increment primary key `id`. Relation key columns 
are non-NULL.
+- Article, binding and Domain-relation rows have the usual `current_version` 
and `last_version`
+  store columns. Version rows are locked through the article row. These store 
revisions are
+  distinct from the article content-version number.
+- Use `VARCHAR(128)` for the name, `VARCHAR(512)` for the title, 
`VARCHAR(256)` for the comment,
+  `VARCHAR(1024)` for the source reference, `VARCHAR(32)` for status and 
format, and `VARCHAR(64)`
+  for target type. The body, properties, bindings and audit JSON use MySQL 
`MEDIUMTEXT`;
+  synonyms and Domain snapshots use `TEXT`. Other databases use their native 
equivalents.
+- `domains` is a JSON array of stable Domain IDs. `bindings` is a JSON array 
of target type and
+  stable target ID. These snapshots are authoritative; relation tables are 
projections used by
+  filters and reverse lookups. There are no database foreign keys; services 
validate and fence
+  endpoints in the transaction.
+- `live_version` points to the effective snapshot. All creates set it; all 
content versions have
+  `version_status=APPROVED`, even when the article's own status is `DRAFT`. 
The column follows the
+  `semantic_model_version_info` convention and is reserved for extensions; 
this delivery never
+  writes another value. The private `live_version` column may be nullable for 
extensions, but this
+  implementation never writes a null live pointer.
+- Add the tables to `schema-2.0.0-*.sql` and `upgrade-1.3.0-to-2.0.0-*.sql` 
while 2.0.0 is
+  unreleased. If it is released before implementation lands, use the next 
version's scripts.
+  Table creation uses `IF NOT EXISTS`; that does not make the whole upgrade 
script re-runnable.
+- Snapshot JSON is private storage, not a client contract. Compatible 
additions are optional
+  with documented defaults for older rows. An unrelated edit preserves unknown 
fields. Reject
+  an unsupported structure before changing data. An incompatible change needs 
an explicit
+  migration; no `schema_version` field is introduced in advance.
+
+### Status and versions
+
+| Article status | Ordinary reads                       | Reverse lookup       
              | MCP      |
+| -------------- | ------------------------------------ | 
---------------------------------- | -------- |
+| `DRAFT`        | Current owner with CREATE, or MANAGE | Excluded             
              | Excluded |
+| `APPROVED`     | Effective VIEW                       | Included             
              | Included |
+| `DEPRECATED`   | Effective VIEW                       | Only with 
`includeDeprecated=true` | Excluded |
+
+New articles default to `APPROVED`. Create may explicitly set any of the three 
statuses, and
+`updateStatus` may set any of them without transition rules or lifecycle 
endpoints. Setting a
+status creates no content version. Leaving `DEPRECATED` rechecks title 
uniqueness; an article
+may be edited or deleted in any status with the normal privileges.
+
+The title, body, Domains and bindings are versioned together, following 
Semantic Model storage.
+Owner, article status, comment, synonyms, source reference and properties 
change directly and
+are audited, without a content snapshot. Properties must not be used to hide 
content that
+belongs in the versioned fields.
+
+- Create writes version 1 with its initial Domains and bindings.
+- An effective change to one or more versioned fields writes exactly one new 
snapshot, using
+  the highest version number plus one. It advances the live pointer and 
rewrites effective
+  bindings and Domain memberships in the same transaction. Any failure rolls 
back all of them.
+- Copy the complete stored snapshot before applying changes, including 
relations the editor
+  cannot see. Filter only response data. A body-only edit must not remove 
hidden bindings or
+  Domain memberships.
+- Public loads, summaries and bindings read the current effective version 
only. Older snapshots
+  remain internal.
+  Stored target and Domain IDs remain unchanged after deletion for later 
historical resolution.
+- Keep every version until article deletion. 
`JDBCBackend.deleteOldVersionData` returns `0` for
+  this entity type, so the normal old-version sweep does not remove history. 
Article deletion
+  soft-deletes all its versions atomically; normal deletion garbage collection 
still applies.
+
+### Domain membership
+
+An article belongs to zero or more Domains, using explicit 
`kb_article_domain_rel` rows.
+Membership is part of the content snapshot and changes through Article 
operations. It is
+independent of backing-tag assignments, so tag changes cannot silently move an 
article.
+
+- Requests and responses use Domain names. Resolve names to stable IDs on 
write and return the
+  current names on read. A rename changes neither membership nor history 
identity. An unknown
+  Domain returns `404`.
+- Follow the Domain model's two levels and shared metalake namespace. A Domain 
filter includes
+  the Domain and its subdomains. Domain membership is optional at creation and 
may change later.
+- Article definition privileges remain metalake-scoped. Each added or removed 
Domain also
+  requires its ordinary access check, including `USE_DOMAIN` and draft-Domain 
visibility.
+  Filter every returned Domain list by that check, without names or counts for 
hidden Domains.
+- `updateDomains` replaces the complete set. Compute additions and removals 
from the full stored
+  set and check each changed Domain. An unrelated edit preserves every 
membership. A caller
+  cannot silently remove an unseen membership by submitting only the filtered 
response.
+- Domain deletion must check effective Article and Term memberships under the 
Domain lock. Any
+  remaining membership returns `409 NonEmptyDomainException`, without member 
names or counts.
+  `MANAGE_DOMAIN` alone cannot detach articles. An authorized Article editor 
first removes
+  membership through the Article API. Historical snapshots alone do not 
prevent Domain deletion.
+- This extends the current Domain drop path, which already checks its own 
lifecycle constraints.
+  Changing or deleting a backing tag does not change Article membership.
+
+### Bindings and target lifecycle
+
+| Binding         | Supported targets                                          
                       |
+| --------------- | 
---------------------------------------------------------------------------------
 |
+| Article → Term  | `GLOSSARY_TERM`, by stable numeric ID                      
                       |
+| Article → Asset | Catalog, Schema, Table, View, table Column, Fileset, 
Topic, Model, Semantic Model |
+
+An article may have no bindings. Bindings point to object identity, not to one 
target version.
+Article→Term, Article→Asset and Term→Asset are independent. There is no 
inheritance from a table
+to columns or from a term to its assets. A binding may cross catalogs or 
Domains.
+
+- Adding a binding requires Article edit permission and read access to the 
target. A missing or
+  invisible target fails the complete request; no partial binding changes are 
stored.
+- A new Term binding requires the Term to be `APPROVED`; otherwise return 
`409`. Check target
+  visibility before returning details of that conflict. Existing bindings 
remain if a Term
+  becomes `DRAFT` or `DEPRECATED`; returned Term details carry its current 
status.
+- Add and remove sets apply atomically. Adding an existing binding or removing 
an absent one
+  is a no-op and creates no version. A mixed request creates one version if 
its final set differs.
+- Responses omit unreadable targets and any hidden-target count. Stored 
snapshots remain
+  complete. A binding never grants or blocks access to the target.
+- Rename preserves a binding when the target's registered ID is preserved. 
Deleting a target
+  removes effective binding rows, keeps the article and leaves historical 
snapshots intact.
+  Each affected surviving article gets one store-revision increment and an 
audit record per
+  cleanup transaction, without a new content version. Rebuilding effective 
relations excludes
+  deleted targets rather than resurrecting them from snapshots.
+- Table-column bindings use the registered column ID and the containing 
table's authorization
+  and endpoint fencing. Reuse the platform's column reconciliation and cleanup 
paths, including
+  load-triggered reconciliation. Concurrent external column rename has the 
inherited identity
+  limitation tracked by 
[#14279](https://github.com/apache/gravitino/issues/14279); this design
+  does not promise unconditional preservation when the platform replaces the 
column ID.
+- Store cleanup is atomic with local registered-object changes. External 
catalog DDL is outside
+  that database transaction. Keep existing external DDL responses, record 
cleanup failures, and
+  use the platform's reconciliation/recovery path; a local rollback cannot 
undo external DDL.
+- Links written in the body are ordinary text URLs, independent of bindings. 
Renaming a target
+  updates resolved binding names, but does not rewrite URLs in old or current 
article text.
+
+Deleting an article soft-deletes its identity, versions, bindings and Domain 
memberships in one
+transaction. It never deletes targets. Dropping a metalake removes articles 
through the normal
+parent lifecycle. Removing a user does not delete their articles; MANAGE can 
reassign ownership.
+
+### Access control
+
+Use the definition privileges on the metalake: `VIEW_DEFINITION`, 
`CREATE_DEFINITION`
+and `MANAGE_DEFINITIONS`, abbreviated VIEW, CREATE and MANAGE in this section.
+`MANAGE_DEFINITIONS` implies CREATE, and CREATE implies VIEW. Expand those 
implications and
+apply explicit Deny rules to every required capability. Every operation 
requires effective VIEW;
+ownership never bypasses Deny.
+
+| Operation                         | Required definition privilege            
                      |
+| --------------------------------- | 
-------------------------------------------------------------- |
+| List and load                     | VIEW; drafts also require current owner 
with CREATE, or MANAGE |
+| Create                            | CREATE                                   
                      |
+| Edit, set status, change bindings | Current owner with CREATE, or MANAGE     
                      |
+| Change Domain membership          | Current owner with CREATE, or MANAGE; 
Domain checks also apply |
+| Delete in any status              | Current owner with CREATE, or MANAGE     
                      |
+| Reverse lookup                    | VIEW on the article and read access to 
the lookup root         |
+
+CREATE alone cannot read another owner's draft, and ownership alone cannot 
replace CREATE.
+Use the same rules on direct reads, lists, nested results, reverse lookups and 
MCP.
+Definition grants on a single article are rejected. Administrators explicitly 
grant VIEW to
+reader roles; there is no implicit `PUBLIC` or anonymous read grant.
+
+Resolve current article identity, owner and the authenticated principal's 
group IDs from the
+store/principal for each owner-based decision. Do not use shared name-to-ID or 
owner caches for
+that decision. Recheck ownership in write transactions and apply the same rule 
to generic Owner
+transfer authorization. After a committed transfer, new requests on another 
server cannot use
+the former owner's cached rights. Already-authorized in-flight requests are 
outside that
+guarantee. Group membership follows the platform's authenticated-principal 
freshness rules;
+Gravitino does not add a user-to-group membership store.
+
+Lists, search and counts use the same visibility predicate. A hidden article 
must not appear in
+`total`, nested summaries or candidate lists. Reading an article does not 
authorize its targets;
+loading a reverse lookup first checks the Term or object root, then filters 
the articles.
+
+### Locking and conditional editing
+
+Every effective write advances the article row's `current_version` using the 
store's
+compare-and-set (CAS) check. A concurrent store revision returns `409` with
+`OPTIMISTIC_LOCK_CONFLICT_CODE`. A no-op advances neither the store revision 
nor the content
+version, and emits no content-change success event. Validate identity, 
authorization and any
+condition before detecting a no-op. Compare persisted values, treating 
memberships and bindings
+as sets; updates that cancel out are a no-op.
+
+Plan the complete lock set before acquiring locks. Follow the existing 
endpoint fences and a
+single order: metalake, Domains in ID order, bound target endpoint chains in 
their established
+order, then Article rows in ID order. Revalidate the resolved identities and 
relation sets under
+the locks. If planning discovered a stale set, restart lock planning with a 
bounded retry;
+never retry a failed CAS as an unconditional overwrite.
+
+- Create, title changes and status changes away from `DEPRECATED` claim a 
title under an
+  exclusive metalake-row lock (`SELECT ... FOR UPDATE` on `metalake_meta`). 
Take its final lock
+  mode initially rather than upgrading a shared metalake fence. This 
serializes title claims
+  within a metalake, including two different article IDs claiming the same 
title.
+- A membership write holds a shared Domain-row lock until commit. Domain drop 
takes its
+  exclusive lock, then checks the latest committed memberships, without taking 
Article locks
+  while holding that exclusive Domain lock. Either the membership commits and 
drop fails, or
+  drop commits and the membership write fails; neither leaves a dangling 
membership.
+- Target removal fences the endpoint against new bindings before collecting 
affected articles,
+  then locks Article rows in ID order. Cleanup and ordinary edits cannot lose 
revision increments.
+- Content snapshots, the live pointer and effective relations commit in one 
transaction. Reads
+  use a consistent store snapshot for root status, authorization and payload; 
they do not need
+  write locks. A read that began before a concurrent commit may return the 
earlier complete state.
+
+REST also accepts an optional `If-Match` header, using the last load or 
write's strong `ETag`.
+The token is opaque and unambiguously includes stable metalake ID, article ID 
and store revision.
+It covers all article writes, not just content versions. Names and 
content-version numbers do
+not distinguish a deleted article from a same-name replacement with the same 
numeric revision.
+
+| Request                   | Concurrency headers                    |
+| ------------------------- | -------------------------------------- |
+| Create or load an article | Response `ETag`                        |
+| Alter or change bindings  | Request `If-Match`; response `ETag`    |
+| Delete                    | Request `If-Match`; no response `ETag` |
+| Lists and reverse lookups | No `ETag`; load before editing         |
+
+Under the article lock, resolve and authorize the current identity before 
comparing the token,
+and compare before writes or no-op detection. Missing or hidden roots return 
`404` first; a
+malformed token is `400`, and a stale identity or revision is `412`. A failed 
check changes no
+data, revision or success event. Tokens are concurrency guards, not 
credentials.
+
+An omitted header or `If-Match: *` skips only token comparison. CAS still 
applies and can return
+`409`; there is no automatic retry. A successful write returns the new token, 
including the
+unchanged token for a valid no-op. Article REST resources and Java/Python 
clients use the same
+conditional-edit contract.
+
+### REST API
+
+All paths below start with `/api/metalakes/{metalake}`. Domain is a field or 
filter, not a path
+segment. Successful calls use HTTP `200` and the normal Gravitino response 
envelope with
+`code: 0`, as the Tag APIs do. The table names the other response fields; 
errors use the usual
+error envelope. Article and binding writes also carry the concurrency headers 
above.
+
+Article names are stored and returned as Unicode strings, not URL-encoded 
strings. In every
+single-Article route, clients UTF-8 percent-encode the name as one path 
segment; server routing
+decodes it once. Java and Python clients must preserve Chinese and 
mixed-language names through
+create, load, alter, delete and binding calls. Percent-encoded length is not 
the name length.
+
+| Method and path                          | Request                           
                          | Response fields                | Behavior           
                                |
+| ---------------------------------------- | 
----------------------------------------------------------- | 
------------------------------ | 
-------------------------------------------------- |
+| `POST /kb-articles`                      | Create fields below               
                          | `article`                      | Create identity, 
owner, version 1 and relations    |
+| `GET /kb-articles`                       | List filters below                
                          | `articles`, `total`, `hasMore` | Read visible 
summaries only                        |
+| `GET /kb-articles/{article}`             | Binding `limit`, `offset`         
                          | `article`                      | Read current 
content with bounded binding previews |
+| `PUT /kb-articles/{article}`             | `updates` array                   
                          | `article`                      | Apply all changes 
atomically                       |
+| `DELETE /kb-articles/{article}`          | No body                           
                          | Existing `DropResponse`        | Soft-delete 
article and related rows atomically    |
+| `GET /kb-articles/{article}/terms`       | `limit`, `offset`                 
                          | `terms`, `hasMore`             | Page visible 
current Term bindings                 |
+| `POST /kb-articles/{article}/terms`      | `termsToAdd`, `termsToRemove`: 
name arrays                  | `terms`, `hasMore`             | Change 
bindings; return the first bounded page     |
+| `GET /kb-articles/{article}/objects`     | `limit`, `offset`                 
                          | `objects`, `hasMore`           | Page visible 
current asset bindings                |
+| `POST /kb-articles/{article}/objects`    | `objectsToAdd`, 
`objectsToRemove`: identifiers              | `objects`, `hasMore`           | 
Change bindings; return the first bounded page     |
+| `GET /glossary/terms/{term}/kb-articles` | `includeDeprecated`, `limit`, 
`offset`                      | `articles`, `total`, `hasMore` | Authorize Term 
root, then page summaries           |
+| `GET /objects/{type}/kb-articles`        | `namespace`, `name`, 
`includeDeprecated`, `limit`, `offset` | `articles`, `total`, `hasMore` | 
Authorize asset root, then page summaries          |
+
+The two reverse lookups return only `APPROVED` articles unless 
`includeDeprecated=true`, which
+also includes `DEPRECATED`. They never return drafts. Each returned article, 
Term, asset and
+Domain passes its own visibility check. Reverse lookup does not traverse 
Term→Asset bindings.
+
+#### Pagination and binding previews
+
+Use ordinary `limit` and `offset`, without a cursor token. List, 
reverse-lookup and binding-list
+reads default to `limit=100`, `offset=0`; accept limits from 1 through 10,000 
and nonnegative
+offsets, rejecting invalid values with `400`. Order bindings by stable 
`(target_id, target_type)`.
+Article summaries retain the title/name ordering described below. Apply root 
authorization,
+status filters and target visibility before offset and limit. A page contains 
only readable
+results, without hidden-object counts. `hasMore` means another readable result 
exists; clients
+continue with the same filters, adding the returned item count to offset. 
Pages describe unchanged
+data; concurrent edits may move results between pages, as with the Article 
list.
+
+Binding pages return `terms` or `objects` plus `hasMore`, with no total. Term 
entries contain
+only name and current status, not full definitions or nested Term bindings; 
object entries use
+`ArticleObjectIdentifier`. Query the relation tables for the bounded page 
rather than loading
+the complete snapshot or all target DTOs and then truncating them. Batch 
target resolution for
+the selected page. Article list/reverse pages retain their authorized `total` 
and add `hasMore`.
+
+An `ArticleSummary` embeds at most 20 readable Term entries and 
`termsHasMore`. A full Article
+response embeds Term and object previews with `termsHasMore` and 
`objectsHasMore`. A load accepts
+`limit` and `offset` for both binding sets, defaulting to 20 and 0, with the 
same maximum of 10,000.
+These parameters page bindings, not the body. Clients can instead page each 
set independently
+through the dedicated binding endpoints. Create and alter return the default 
previews; binding
+mutations return the first 100 readable entries of the updated set and 
`hasMore`, plus the
+Article ETag. Pagination never changes the complete stored snapshot or the 
atomic mutation.
+
+#### Create and alter
+
+| Create field      | Type                            | Required | Description 
                                  |
+| ----------------- | ------------------------------- | -------- | 
--------------------------------------------- |
+| `name`            | string                          | No       | Immutable 
name; generated when omitted        |
+| `title`           | string                          | Yes      | Unique 
nondeprecated display title            |
+| `body`            | `{format, content}`             | Yes      | Text body, 
sanitized and byte-limited         |
+| `status`          | string enum                     | No       | Defaults to 
`APPROVED`                        |
+| `domains`         | string array                    | No       | Domain 
names; defaults to an empty set        |
+| `terms`           | string array                    | No       | Approved 
Term names; defaults to an empty set |
+| `objects`         | `ArticleObjectIdentifier` array | No       | Asset 
identifiers; defaults to an empty set   |
+| `comment`         | string                          | No       | Short 
description                             |
+| `synonyms`        | string array                    | No       | Other words 
for the topic; defaults to empty  |
+| `sourceReference` | string                          | No       | Source 
text, without URL fetching             |
+| `properties`      | string map                      | No       | Unversioned 
properties; defaults to empty     |
+
+Example create request:
+
+```json
+{
+  "name": "revenue-calculation-guide",
+  "title": "Revenue Calculation Guide",
+  "body": {
+    "format": "MARKDOWN",
+    "content": "# Revenue\n\nRevenue excludes refunds and taxes."
+  },
+  "domains": ["Finance"],
+  "terms": ["net-revenue"],
+  "objects": [
+    { "type": "TABLE", "namespace": ["iceberg", "sales"], "name": "orders" }
+  ]
+}
+```
+
+Create, load and alter return `{ "code": 0, "article": ... }`, where `article` 
has the typed
+fields in [Data model](#data-model), plus the bounded binding previews 
described above. Bound
+Term entries contain name and current status; object entries use 
`ArticleObjectIdentifier`.
+Owner information is resolved through the existing Owner model, not stored in 
the version snapshot. `audit_info`
+follows the standard AuditInfo DTO. These responses expose current content 
only.
+
+Alter follows the existing `updates` convention. Supported changes are 
`updateTitle`,
+`updateBody`, `updateDomains`, `updateStatus`, `updateComment`, 
`updateSynonyms`,
+`updateSourceReference`, `setProperty` and `removeProperty`. Domain and 
synonym updates replace
+their complete sets. Rename is unsupported. A request changing several 
versioned fields
+creates one version, and an unversioned-only change creates none.
+
+```json
+{
+  "updates": [
+    { "@type": "updateTitle", "newTitle": "Revenue Calculation and Refunds" },
+    { "@type": "updateDomains", "newDomains": ["Finance", "Tax"] }
+  ]
+}
+```
+
+#### Structured object identifiers
+
+`ArticleObjectIdentifier` contains `type`, an ordered `namespace` array and 
`name`. Each component
+is an exact string. Resolve them directly to stable IDs; do not concatenate 
and split a dotted
+name through `MetadataObjects.parse`.
+
+| Type                                                           | Namespace   
               | Name              |
+| -------------------------------------------------------------- | 
-------------------------- | ----------------- |
+| `CATALOG`                                                      | `[]`        
               | Catalog name      |
+| `SCHEMA`                                                       | `[catalog]` 
               | Schema name       |
+| `TABLE`, `VIEW`, `FILESET`, `TOPIC`, `MODEL`, `SEMANTIC_MODEL` | `[catalog, 
schema]`        | Object name       |
+| `COLUMN`                                                       | `[catalog, 
schema, table]` | Table column name |
+
+For example, a column whose literal name is `total.amount` stays one name 
through create,
+binding changes, responses, clients and MCP:
+
+```json
+{
+  "objectsToAdd": [
+    { "type": "COLUMN", "namespace": ["iceberg", "sales", "orders"], "name": 
"total.amount" }
+  ],
+  "objectsToRemove": []
+}
+```
+
+The object reverse lookup repeats `namespace` in component order and provides 
`name` separately:
+
+```http
+GET 
/api/metalakes/demo/objects/column/kb-articles?namespace=iceberg&namespace=sales&namespace=orders&name=total.amount
+```
+
+Omit `namespace` for a catalog. Encode each path or query value normally; 
never split a decoded
+component or name on `.`. A missing name, unsupported type or invalid 
component count is `400`.
+View columns and individual metrics are outside the supported set.
+
+#### Lists and search
+
+`GET /kb-articles` accepts `q`, `domain`, `status`, `owner`, `limit` and 
`offset`.
+
+- `q` matches any substring of the current title, a synonym or the current 
body, ignoring case.
+  Search the stored body, including markup: a word in an HTML attribute can 
match. There is no
+  relevance ranking or conversion to plain text.
+- Use bound parameters with `LOWER(value) LIKE LOWER(?) ESCAPE '!'` on all 
three databases,
+  following `SchemaPOStorageOps.escapeLikeMetacharacters`. Escape the input in 
order: `!` to
+  `!!`, `%` to `!%`, then `_` to `!_`; wrap the result in `%` for substring 
matching. Backslash
+  remains a literal character in the bound parameter. Do not rely on database 
collation or
+  default backslash escaping. A full-text index may replace this 
implementation without an
+  API change.
+- `domain` resolves the visible Domain and includes its subdomains. It 
combines with all other
+  filters. `status` accepts one article status; the unfiltered list includes 
deprecated articles
+  and those drafts the caller may read.
+- `owner` is `user:<name>` or `group:<name>`, matching the direct owner. Group 
members are not
+  expanded. A missing or invalid prefix is `400`.
+- Sort by title, then immutable name. This breaks ties when a deprecated 
article shares a title
+  with its replacement. Offset paging is stable for unchanged data, not a 
snapshot across
+  independent requests while articles change.
+- Each `ArticleSummary` contains name, title, status, Domains, owner, the 
bounded Term preview
+  and `termsHasMore`, content version and audit information, without a body. 
Batch owner and Term
+  lookups for the page rather than querying each article separately.
+- Return `{ "code": 0, "articles": [...], "total": 57, "hasMore": true }`. 
`total` applies all
+  filters and authorization, independently of limit and offset. It never 
counts hidden articles.
+
+#### Errors
+
+| HTTP code | Meaning                                                          
                              |
+| --------- | 
----------------------------------------------------------------------------------------------
 |
+| `400`     | Invalid fields, type, format, size, status, identifier 
components or malformed condition token |
+| `403`     | Visible object, but insufficient privilege for the operation     
                              |
+| `404`     | Missing or hidden article, Term, asset or Domain                 
                              |
+| `409`     | Name/title conflict, CAS conflict, nonapproved new Term binding, 
or nonempty Domain drop       |
+| `412`     | Stale article identity or store revision in `If-Match`           
                              |
+| `502`     | Backend failure, following the existing REST error conventions   
                              |
+
+Check root visibility before action permission, and permissions before content 
conflicts or
+condition details. An unsuccessful mutation leaves the local article, 
snapshots, effective
+relations and revision unchanged. External DDL outcomes have the separate 
limits described in
+[Bindings and target lifecycle](#bindings-and-target-lifecycle).
+
+### Java and Python clients
+
+Add article operations on the metalake, using typed DTOs and structured object 
identifiers.
+The operations are:
+
+```text
+KnowledgeBaseArticleOperations
+  listArticles(filter): ArticlePage
+  loadArticle(name, limit = 20, offset = 0): KnowledgeBaseArticle
+  createArticle(name?, title, body, domains?, status?, comment?, synonyms?,
+                sourceReference?, properties?, terms?, objects?): 
KnowledgeBaseArticle
+  alterArticle(name, changes...): KnowledgeBaseArticle
+  deleteArticle(name): boolean
+  listTermBindings(name, limit = 100, offset = 0): TermBindingPage
+  alterTermBindings(name, termsToAdd, termsToRemove): TermBindingPage
+  listAssetBindings(name, limit = 100, offset = 0): AssetBindingPage
+  alterAssetBindings(name, assetsToAdd, assetsToRemove): AssetBindingPage
+  listArticlesForTerm(term, includeDeprecated = false, limit = 100, offset = 
0): ArticlePage
+  listArticlesForObject(objectIdentifier, includeDeprecated = false, limit = 
100, offset = 0): ArticlePage
+```
+
+`ArticlePage` contains summaries, authorized total and `hasMore`; binding 
pages contain their
+typed entries and `hasMore`. Clients preserve the flags and expose 
limit/offset directly.
+
+Python exposes the equivalent snake_case methods. Both clients retain the 
opaque ETag from load
+or write in their Article handle, send it for conditional mutations and retain 
the next token
+after binding writes as well as alter. Convenience calls without a loaded 
token may omit the
+header; they retain server CAS behavior. A `412` surfaces as a 
concurrent-modification error
+requiring reload. Neither client retries a mutation unconditionally after a 
conflict.
+
+Both clients expose the current Article version. Historical-version listing 
and loading
+methods are deferred with the corresponding REST APIs.
+
+### Agent integration
+
+Add four read-only tools to `mcp-server/`, beside the existing metadata tools:
+
+| Tool                          | Result                                       
                            |
+| ----------------------------- | 
------------------------------------------------------------------------ |
+| `search_kb_articles`          | Summaries matching title, synonyms or body, 
with supported filters       |
+| `get_kb_article`              | Title, body with format, version, visible 
Domains, Terms and assets      |
+| `list_kb_articles_for_term`   | Summaries of articles directly bound to the 
Term                         |
+| `list_kb_articles_for_object` | Summaries of articles directly bound to the 
structured object identifier |
+
+Tools use REST under the effective caller's identity and return only 
`APPROVED` articles,

Review Comment:
   Credential selection is now documented per transport and fallback mode. 
Article APIs return the full stored body, while model-context sizing is left to 
the MCP implementation rather than Article-specific truncation parameters.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to