Tool: rag_rebuild_index — ให้ caller LLM ช่วยตั้ง topic โดยไม่เสีย deterministic truth

ภาพประกอบ: Tool: rag_rebuild_index — ให้ caller LLM ช่วยตั้ง topic โดยไม่เสีย deterministic truth

rag_rebuild_index จัดการ orientation index ของ MCP-RagMax โดยแก้โจทย์ที่ดูขัดกันสองข้อพร้อมกัน:

  1. อยากได้ high-level topic labels ที่ LLM ตั้งชื่อได้ดี
  2. แต่ไม่อยากให้ backend RAG ต้องเรียก LLM หรือยอมให้ caller เขียน metadata อะไรก็ได้ลง state

คำตอบคือ protocol แบบ prepare → caller proposes topics → commit with fingerprint

Phase 1: prepare

rag_rebuild_index(mode="prepare")

Backend สร้าง bounded deterministic snapshot ของ KB เช่น filenames, tags, source types และคืน expected_fingerprint

ยังไม่มีการเขียน topic ใหม่ใน phase นี้

Caller LLM ทำอะไรได้

Caller อ่าน snapshot แล้วเสนอ topic labels 1–30 รายการ เช่น:

Aircraft Maintenance
Flight Operations
Human Factors

สิทธิ์ของ caller จบที่การเสนอชื่อ topic เท่านั้น Counts, tags, source types และ fingerprint ไม่ได้มาจาก LLM

Phase 2: commit

rag_rebuild_index(
  mode="commit",
  topics=[...],
  expected_fingerprint="..."
)

ก่อนเขียน backend จะ:

  • validate รูปแบบ/จำนวน topic
  • recompute deterministic metadata จาก KB ปัจจุบัน
  • recheck fingerprint
  • เขียน rag_index.json แบบ atomic เฉพาะเมื่อ state ยังตรงกับตอน prepare

ถ้า KB เปลี่ยนระหว่างสอง phase commit จะ fail ด้วย conflict และ caller ต้อง prepare ใหม่

mode="auto"

Contract รองรับ auto เพื่อให้ generic MCP caller ใช้ง่าย: call แรกที่ยังไม่มี fingerprint จะเป็น safe prepare; เมื่อส่ง topics พร้อม fingerprint จึงตีความเป็น commit

การส่ง topic มาก่อนโดยไม่มี fingerprint ไม่ให้ write authority กับ caller

ทำไม fingerprint สำคัญ

ถ้าไม่มี fingerprint อาจเกิด race แบบนี้:

prepare จาก KB รุ่น A
→ build เปลี่ยน KB เป็นรุ่น B
→ caller commit topics ที่สรุปจาก A ทับ orientation ของ B

fingerprint ทำให้ state drift แบบนี้ถูกตรวจพบก่อนเขียน

ต่างจาก memory tool อย่างไร

rag_rebuild_index ไม่ได้เก็บ memory ของบทสนทนา มันสร้าง orientation metadata สำหรับ knowledge base ปัจจุบันเท่านั้น และไฟล์อยู่ใต้ derived state (workspace/.rag_state/) ไม่ใช่เอกสารต้นฉบับ

อ่านต่อ

ความคิดเห็น

กำลังโหลดความคิดเห็น...