來源匯入規格

日期:2026-03-20 目的:定義發票、channel_master、群眾蒐集與既有分類系統,如何匯入 item master 的證據層。 相關文件:

1. 核心原則

  1. 所有來源先保留原始樣貌,不直接覆蓋正式商品。
  2. 匯入要以 append-first 為原則,保留來源與時間。
  3. channel_master 與 crowd 都先進證據層,不直接長成 BI / SI
  4. 有時間語意的來源一定要帶 observed_atvalid_from / valid_to
  5. 分級上優先維護 mapping_tieritem_tier 在建立 BI / SI 後預設為 銅級,再逐步升級。

2. 來源對應總表

來源 主要落點 角色
發票 invoice_linesinvoice_name_clusterscluster_members 主輸入
channel_master evidence_observations 候選與證據
crowd review_tasksreview_answersevidence_observations 人工輔助證據
既有品牌與分類系統 brand_hintcategory_hint、未來的 taxonomy 關聯表 提示與先驗

3. 發票資料匯入

目標表

欄位對應

發票欄位 目標欄位
商家 merchant_code
通路 channel_code
店名 store_name
統編 store_tax_id
發票號碼 invoice_id
品名 raw_pn
日期 invoice_date
數量 quantity
金額 amount

匯入規則

  1. invoice_lines 保留原始字串,不在此層硬做正規化映射。
  2. invoice_name_clusters 預設以商家為範圍聚類;必要時再細化到店點。
  3. ML 或既有系統可補 brand_hintcategory_hint

4. channel_master 匯入

目標表

不應做的事

  1. 不可把每一列 channel_master 直接當成 SI
  2. 不可因單一通路資料就自動發新 BI / SI

建議欄位對應

channel_master 欄位 evidence_observations 欄位
source channel source_channel
來源記錄代碼 / 網址 source_record_idsource_url
merchant merchant_code
raw_product_name raw_name
normalized_name normalized_name
barcode barcode
barcode_class barcode_class
risk_flags risk_flags
item_level_hint item_level_hint
item_level_hint_reason payload.item_level_hint_reason
image url image_url
brand brand_hint
category category_hint
package form package_form
規格 / 容量 net_content_valuenet_content_uom
crawl date observed_at

item_level_hint 是 evidence-level hint,不是最終 item_level 定案;若與其他證據衝突,應保留於證據層並交由 Silver / review 決定。

匯入時應補的風險旗標

如果無法判定,不要假設乾淨,請標成待審核風險。

5. crowd 資料匯入

目標表

匯入規則

  1. crowd 原始上傳不可直接改寫 item master。
  2. 每筆 crowd 證據都應帶來源人、時間與上下文。
  3. crowd 自由輸入若與 trusted evidence 強衝突,先進審核或隔離。

6. 既有品牌與分類系統匯入

這套系統的角色不是 BI / SI 真值來源,而是:

第一階段建議先接到:

7. 去重與可重跑原則

  1. 每個來源都應有穩定的 source_record_id 或 fingerprint。
  2. 發票可用 merchant_code + invoice_id + raw_pn + amount 當初始去重鍵。
  3. channel_master 可用 source_channel + source_record_id + observed_at::date 當近似去重鍵。
  4. crowd 可用 review_task_id + answered_by + answered_at::date 做去重參考。

8. 匯入後的分級策略

8.1 mapping_tier

在清整與匯入過程中,最值得先標的是 mapping_tier

8.2 item_tier

item_tier 建議不要一開始就要求很細:

9. 時間欄位使用原則

當條碼有歷史重用時,要用有效期間切開,而不是覆蓋舊關係。

10. 最小實作順序

  1. 先做發票匯入。
  2. 再做 channel_master -> evidence_observations
  3. 再接品牌與分類提示。
  4. 最後接 crowd 證據。

11. 一句話收尾

所有來源都先進證據層,只有通過打分與審核的結果,才往上長成 BI / SI