KB-3A15 rev 2

INV — Search/Vector Hygiene: Context-Pack Duplication Investigation

7 min read Revision 2
vector-hygienecontext-packsearch-pollutioninvestigationread-only

INV — Search/Vector Hygiene: Context-Pack Duplication Investigation

Date: 2026-05-05 | Status: PROMPT rev2 — chờ duyệt trước dispatch Source: GPT directive + GPT review rev1 (6 patches) + User đề xuất xóa bản cũ Scope: READ-ONLY investigation. Không delete, không deindex, không mutate.


§0. Mục tiêu

Điều tra read-only xem context-pack/ có đang gây nhiễu search/vector không. Đề xuất phương án phân tầng dài hạn. Không xóa, không deindex, không mutate.

4 lớp phải tách rõ trong report:

  1. Source-of-truth docs: luật, design, process, report chính thức
  2. Generated snapshots: context-pack builds (Đ43)
  3. Search/vector index: retrieval layer (Qdrant)
  4. Runtime context cache: file cho agent/tool đọc tại VPS

"Xóa tài liệu" ≠ "deindex khỏi hot vector". Report phải phân biệt rõ.


§1. Read-list bắt buộc TRƯỚC KHI điều tra

  1. knowledge/dev/laws/dieu43-system-context-law.md
  2. knowledge/current-state/context-pack/README.md
  3. knowledge/current-state/context-pack-staging/README.md
  4. knowledge/dev/dot/dot-context-pack-build.sh

Search KB/history bổ sung cho các từ khóa: vector, Qdrant, search, retrieval, context-pack, embedding, hot/cold, TTL, dedup, rerank

Report phải ghi: đã có design/draft canonical nào về vector/search chưa, hay absent.


§2. Câu hỏi điều tra

Q1. Count documents theo prefix

Dùng list_documents API, đếm:

  • Tổng số documents trong KB
  • Số documents dưới mỗi prefix:
    • context-pack/
    • knowledge/current-state/context-pack/
    • knowledge/current-state/context-pack-staging/
    • knowledge/dev/laws/
    • knowledge/ops/processes/
    • knowledge/dev/dot/
    • knowledge/dev/laws/dieu44-trien-khai/
    • registries/

Q2. Count chunks/vector nếu truy được

  • Tổng vector/chunks trong index
  • Chunks thuộc context-pack/
  • Top 5 prefixes theo số chunks

Nếu không có quyền đọc vector DB → ghi "not accessible", dùng document count thay thế.

Q3. Search pollution test

Chạy 7 query đại diện, mỗi query ghi top 20 results:

  1. birth pipeline QT-001 QT-002 fn_birth_registry_auto
  2. DOT-119 birth trigger setup
  3. orphan ghost birth registry
  4. information_unit unit_version schema
  5. description_policy structured_exempt
  6. Điều 43 context pack lifecycle
  7. birth-process-v1 QT-002

Với MỖI query report:

  • Tổng results trả về
  • Bao nhiêu là context-pack (path bắt đầu context-pack/)
  • Bao nhiêu là canonical docs (knowledge/, registries/)
  • Tài liệu canonical có xuất hiện trong top 5 không?
  • Vị trí tài liệu canonical nếu có

Q4. Metadata inspection

Chọn 3 context-pack results + 3 canonical doc results, inspect metadata mỗi cái:

  • tags, path, title, revision, created/updated timestamps

Trả lời:

  • Có metadata nào đủ để filter context-pack ra khỏi search mặc định không?
  • Có phân biệt được live snapshot vs historical snapshot không?
  • Tags có nhất quán không?

Q5. Context-pack lifecycle theo Đ43

Đọc Đ43 + context-pack README:

  • Context-pack là gì?
  • Live folder vs staging folder khác nhau thế nào?
  • Có yêu cầu giữ historical snapshots trong KB/vector không?
  • Chu kỳ build bao lâu?
  • Có TTL/retention/deindex rule chưa?

Q6. Storage pattern hiện tại

Context-pack hiện lưu ở đâu?

  • KB Agent Data (vector index)
  • Filesystem VPS
  • PG tables (context_pack_manifest, context_pack_requests nếu có)
  • Cả hai? Trùng?

Nếu có PG tables liên quan → inspect schema + sample counts (read-only).

Q7. Duplicate / near-duplicate evidence

Chọn 3 file PROJECT_MAP.md từ 3 build khác nhau (cách nhau vài ngày). So sánh path, first 500 chars, ước lượng % giống nhau.

Q8. Latest-only detection

  • Latest context-pack build_id là gì?
  • Có stable live/latest path không?
  • knowledge/current-state/context-pack/ là live real hay README placeholder?
  • Nếu không có latest pointer thì metadata nào xác định latest?

Q9. Industry-aligned options

So sánh các phương án (mỗi cái ghi feasibility, rủi ro, cần DDL/tooling không, phù hợp Đ43 không, ảnh hưởng Agent runtime không):

Option Mô tả
A Exclude toàn bộ historical context-pack/<build_id>/ khỏi vector search mặc định
B Chỉ giữ latest context-pack live trong hot vector
C Giữ snapshots trong cold storage / filesystem / manifest, không vector hot
D Thêm metadata filter mặc định: exclude context-pack trừ khi query yêu cầu
E Dedup/near-dedup trước embedding
F TTL/retention: chỉ giữ N builds gần nhất trong KB/vector
G Hybrid retrieval: canonical docs first, context-pack as fallback
H Delete old snapshots từ KB (chỉ giữ latest), giữ 7 ngày trên filesystem VPS cho audit. DOT build script sau upload bản mới → deleteDocument bản cũ.

Option H là đề xuất User/Opus. Agent phải đánh giá ngang hàng với A–G.

Q10. Retrieval policy recommendation

Agent đề xuất:

  • Prefix nào include/exclude mặc định trong search?
  • Khi nào nên include context-pack?
  • Canonical-first hay snapshot-first?
  • Metadata filters cần thiết?
  • Có cần dedup/rerank không?

Q11. Risk note

Report phải nói rõ:

  • Xóa context-pack docs có thể phá audit/history?
  • Deindex khỏi hot vector an toàn hơn delete?
  • Cold/archive có thể đủ?
  • Filesystem VPS đã là cold storage đủ cho audit chưa?

Q12. Direct recommendation

Trả lời thẳng 8 câu:

  1. Có nên xóa historical context-pack khỏi KB không?
  2. Có nên deindex historical context-pack khỏi vector không?
  3. Có nên giữ latest context-pack trong hot index không?
  4. Có cần cold index riêng không, hay filesystem VPS đủ?
  5. Metadata filter mặc định nên là gì?
  6. Việc này cần sửa luật Đ43, DOT build, hay search layer?
  7. Cần dọn ngay hay staged migration?
  8. Option nào trong A–H khuyến nghị, và kết hợp thế nào?

Q13. Success metrics

Đề xuất tiêu chí đo sau khi fix:

  • Context-pack share trong top-20 canonical queries giảm dưới bao nhiêu %?
  • Canonical docs xuất hiện top-5 cho known queries?
  • Latest context-pack vẫn tìm được khi query rõ context-pack/build_id?

§3. Report path

Upload tại: knowledge/dev/laws/dieu44-trien-khai/reports/inv-search-vector-hygiene-context-pack-report.md


§4. Hard boundaries

  • ❌ NO deleteDocument
  • ❌ NO deindex
  • ❌ NO patch DOT scripts
  • ❌ NO patch Đ43
  • ❌ NO sửa vector config
  • ❌ NO mutate DB
  • ❌ NO cleanup
  • ✅ CHỈ report hiện trạng + options

INV Search/Vector Hygiene prompt rev2 | 2026-05-05 | GPT directive + 6 patches + User Option H. Read-only. 13 câu hỏi.

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/prompts/inv-search-vector-hygiene-context-pack-prompt.md