feat(ingest): POST /triplets/ingest 寫入端 + deprecate-then-append (T3.2-3.5)
對應 issue #1 T3 B 段。 - templates: TRIPLET_SLOTS 加 status/superseded_by/source_uri/content_hash; ENTITY_SLOTS 加 gloss;recordToTriplet 映射新欄位(缺省 status=active 相容舊資料) - kbdb-client: ensureTemplate 改 slot-diff 補丁(既有 template 走 PATCH /templates/:id 補缺 slot,取代 early-return → 免遷移腳本);新增 updateRecord(PATCH /records/:id) - triplet-ingest action(88 行純函式):Zod strict 鏡射 ingest-candidate 契約 → idempotency(uri+hash 同→no-op)→ 先 append 後 deprecate(無「全無 active」空窗) - POST /triplets/ingest route:strict 驗證失敗 → 422(禁送 graph 領域欄位) - queryTriplets 預設 active-only(traverse/search/neighbors 皆經此), includeDeprecated opt-out 供 rollback/考古 - 6 測試案全綠(vitest 16 passed);mock-client 同步 slot-diff + updateRecord gates: zero SQL / zero migration / 無 D1·Vectorize·AI 綁定 / dry-run bundle 乾淨 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
-1
@@ -14,8 +14,12 @@ export const TRIPLET_SLOTS = [
|
||||
'subject', 'predicate', 'object', 'source_block_id',
|
||||
'confidence', 'clusters_json', 'bridge_score',
|
||||
'subject_entity_type', 'object_entity_type',
|
||||
// 取代/快照(T3.2):status=active|deprecated;superseded_by=取代它的新 record id;
|
||||
// source_uri+content_hash 承載 ingest idempotency(按 source_uri 分組 deprecate)。
|
||||
'status', 'superseded_by', 'source_uri', 'content_hash',
|
||||
];
|
||||
export const ENTITY_SLOTS = ['canonical', 'aliases_json', 'entity_type', 'owner'];
|
||||
// gloss(T3.2b):一句話描述,供「詞+gloss」語義 normalize 的 embedding 對象。
|
||||
export const ENTITY_SLOTS = ['canonical', 'aliases_json', 'entity_type', 'owner', 'gloss'];
|
||||
export const ENTITY_PENDING_SLOTS = [
|
||||
'raw_name', 'candidate_entity_id', 'candidate_canonical', 'similarity',
|
||||
];
|
||||
@@ -41,6 +45,11 @@ export function recordToTriplet(rec: BaseRecord): Triplet {
|
||||
bridge_score: parseInt(v.bridge_score ?? '0', 10),
|
||||
subject_entity_type: (v.subject_entity_type as Triplet['subject_entity_type']) || null,
|
||||
object_entity_type: (v.object_entity_type as Triplet['object_entity_type']) || null,
|
||||
// 缺省視為 active(相容尚無 status slot 的舊資料)。
|
||||
status: v.status === 'deprecated' ? 'deprecated' : 'active',
|
||||
superseded_by: v.superseded_by || null,
|
||||
source_uri: v.source_uri || null,
|
||||
content_hash: v.content_hash || null,
|
||||
created_at: 0,
|
||||
updated_at: 0,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user