KB-6A21

20A/20B-P0 — Search/Vector Hygiene Read-Only Inspection Prompt

11 min read Revision 1
vector-hygienesearch-filtercontext-packinspectionread-only20a20b-p0prompt

20A/20B-P0 — Search/Vector Hygiene Read-Only Inspection Prompt

Date: 2026-05-05 | Status: PROMPT — chờ dispatch Controlling: Design pack 20 + GPT directive + Opus review Scope: READ-ONLY inspection. Không mutation, không delete, không patch. Prior evidence: Agent vector hygiene report (13 câu hỏi PASS), VRC report (2026-05-02)


§0. Mission

Hai mục tiêu trong 1 session:

  1. 20A — Search Filter Feasibility Gate: Inspect Agent Data search API code. Xác nhận có thể thêm exclude filter hay không.
  2. 20B-P0 — Lifecycle Prerequisites: Inspect DOT build script, filesystem VPS, PG manifest. Xác nhận đủ điều kiện để ngừng upload context-pack lên KB và dọn 1.174 bản cũ an toàn.

Primary hypothesis (từ User directive): Context-pack không thuộc về KB/vector. Agent đọc context-pack từ filesystem theo path cố định, không qua search ngữ nghĩa. Ngừng upload KB hoàn toàn là hướng chính. "Giữ latest trên KB" chỉ là fallback nếu inspection phát hiện lý do cụ thể cần giữ.

Hard STOP: Upload report. Không execute bất kỳ thay đổi nào.


§1. Connection

# VPS SSH
ssh contabo

# PG
docker exec -i postgres psql -U directus -d directus

# Agent Data container (nếu cần inspect code)
docker exec -it incomex-agent-data /bin/sh

§2. 20A — Search API Feasibility Inspection

2.1 Tìm search code

# Bước 1: Tìm entry point search function
docker exec incomex-agent-data grep -RIn "def search\|async def search\|def query\|def retrieve" /app/ --include='*.py' | head -30

# Bước 2: Tìm filter logic hiện có
docker exec incomex-agent-data grep -RIn "filter_tags\|filter_status\|metadata\.\|exclude\|include.*pack\|source.*filter" /app/ --include='*.py' | head -50

# Bước 3: Tìm Qdrant client call
docker exec incomex-agent-data grep -RIn "qdrant\|search_points\|scroll\|query_points\|Filter\|FieldCondition\|MatchValue" /app/ --include='*.py' | head -30

Sau khi tìm được file + function, đọc context xung quanh:

# Ví dụ: nếu search function ở vector_store.py dòng ~250
docker exec incomex-agent-data sed -n '<START>,<END>p' /app/agent_data/vector_store.py
# Thay <START>,<END> bằng dòng thực tế tìm được từ grep

KHÔNG dùng line number cứng. Grep trước, đọc context sau.

2.2 Câu hỏi 20A phải trả lời

# Câu hỏi Cách trả lời
A1 Agent Data search API nhận params gì? Đọc function signature + docstring
A2 Filter hiện có: chỉ tags + status? Còn gì khác? Đọc code path từ API → Qdrant
A3 Qdrant filter đang dùng class gì? (Filter, FieldCondition, MatchValue?) Grep Qdrant client code
A4 Payload metadata có source, path không? (Đã biết có từ report Q4, nhưng cần confirm code đọc được) Đọc embedding/upload code path
A5 Thêm exclude_source param = patch nhỏ (≤50 LOC) hay refactor lớn? Đánh giá dựa trên code structure
A6 Nếu patch nhỏ: chỉ rõ file, function, dòng cần sửa Evidence cụ thể
A7 Nếu không khả thi: lý do cụ thể Evidence cụ thể

2.3 Gate decision

Kết quả Hành động
A5 = patch nhỏ (≤50 LOC) 20A VIABLE — ghi patch points vào report, chờ design
A5 = refactor lớn hoặc managed service không sửa được 20A NOT VIABLE — ghi lý do, 20B là primary fix duy nhất

§3. 20B-P0 — Lifecycle Prerequisites Inspection

3.1 DOT build script upload/publish logic

# Đọc script
cat /opt/incomex/dot/bin/dot-context-pack-build.sh | head -20
wc -l /opt/incomex/dot/bin/dot-context-pack-build.sh

# Tìm upload logic
grep -n 'upload_document\|createDocument\|deleteDocument\|delete_document' /opt/incomex/dot/bin/dot-context-pack-build.sh

# Tìm build_id pattern
grep -n 'BUILD_ID\|build_id\|context-pack/' /opt/incomex/dot/bin/dot-context-pack-build.sh | head -20

# Tìm overwrite/cleanup logic
grep -n 'overwrite\|cleanup\|retention\|rm \|find.*mtime\|delete.*old' /opt/incomex/dot/bin/dot-context-pack-build.sh

Câu hỏi B1: Script upload với path context-pack/<build_id>/<file> (accumulate) hay overwrite path cố định? Confirm accumulation pattern từ report.

Câu hỏi B2: Có lệnh deleteDocument cho build cũ không? (Dự kiến: không, dựa trên report.)

Câu hỏi B3: Nếu sửa script thêm delete-after-upload, điểm chèn ở đâu? (Chỉ ghi nhận, không sửa.)

3.2 Filesystem retention

# Context-pack folders
ls -la /opt/incomex/context-pack/ 2>/dev/null || echo "PATH NOT FOUND"
ls -la /opt/incomex/context-pack/current/ 2>/dev/null || echo "current/ NOT FOUND"
ls -la /opt/incomex/context-pack/staging/ 2>/dev/null || echo "staging/ NOT FOUND"

# Depth survey
find /opt/incomex/context-pack/ -maxdepth 2 -type d 2>/dev/null | head -30
find /opt/incomex/context-pack/ -maxdepth 3 -type f 2>/dev/null | wc -l
du -sh /opt/incomex/context-pack/ 2>/dev/null

# Có bao nhiêu build trên FS?
ls -d /opt/incomex/context-pack/*/  2>/dev/null | wc -l

# Build mới nhất trên FS
ls -lt /opt/incomex/context-pack/ 2>/dev/null | head -5

# Cron cleanup
crontab -l 2>/dev/null | grep -Ei 'context|pack|cleanup|retention' || echo "NO CRON CLEANUP"

Câu hỏi B4: FS giữ bao nhiêu bản? Có cron dọn không? (Dự kiến: không có cron, accumulate vô hạn.)

Câu hỏi B5: FS có đủ làm cold archive 7 ngày nếu thiết lập cron? (Disk space, path structure.)

3.3 PG manifest/audit

-- Tables tồn tại?
SELECT table_name FROM information_schema.tables
WHERE table_name IN ('context_pack_manifest','context_pack_requests','context_pack_sections')
ORDER BY table_name;

-- Schema nếu tồn tại
SELECT table_name, column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name IN ('context_pack_manifest','context_pack_requests','context_pack_sections')
ORDER BY table_name, ordinal_position;

-- Counts
SELECT 'context_pack_manifest' AS tbl, count(*) FROM context_pack_manifest
UNION ALL
SELECT 'context_pack_requests', count(*) FROM context_pack_requests
UNION ALL
SELECT 'context_pack_sections', count(*) FROM context_pack_sections;

-- Latest view
SELECT * FROM v_context_pack_latest LIMIT 5;

-- Latest complete build (≥8 sections)
SELECT m.build_id, m.status, m.created_at, count(s.section_name) AS section_count
FROM context_pack_manifest m
LEFT JOIN context_pack_sections s ON s.manifest_id = m.id
GROUP BY m.build_id, m.status, m.created_at
ORDER BY m.created_at DESC
LIMIT 10;

Lưu ý: Nếu table/view không tồn tại, báo absence, không fail. Dùng guard:

SELECT EXISTS (
  SELECT 1 FROM information_schema.tables WHERE table_name = 'context_pack_manifest'
) AS manifest_exists;

Câu hỏi B6: PG manifest có đủ metadata (build_id, checksum, timestamp, status) để làm audit trail vĩnh viễn không?

Câu hỏi B7: v_context_pack_latest trả build nào? Khớp với KB latest (20260504-040018-372b48) không?

3.4 Dry-run delete list feasibility

Không delete. Chỉ kiểm tra khả năng lập danh sách.

# Dùng Agent Data API nếu có CLI, hoặc ghi nhận logic:
# list_documents(path="context-pack/") → lọc bỏ latest build → danh sách delete candidates

Từ report Q1: list_documents(path="context-pack/") trả 1.174 docs. Đã xác nhận hoạt động.

Câu hỏi B8: Nếu latest complete build = 20260504-040018-372b48 (9 files), delete candidates = 1.174 - 9 = 1.165 docs. Confirm logic này đúng không?

Câu hỏi B9: Nếu primary hypothesis (ngừng upload KB hoàn toàn) được chọn, delete candidates = toàn bộ 1.174 docs. Có rủi ro gì khi xóa hết? (Agent có đang đọc context-pack từ KB không, hay chỉ từ filesystem?)

3.5 Agent runtime dependency check

# Agent (Claude Code) có đọc context-pack từ KB hay từ filesystem?
# Tìm trong agent prompts/scripts
grep -RIn 'context-pack\|context_pack\|PROJECT_MAP\|LAWS_INDEX\|DOT_REGISTRY' /opt/incomex/dot/bin/ --include='*.sh' | head -20
grep -RIn 'search_knowledge.*context\|get_document.*context-pack' /opt/incomex/ --include='*.py' --include='*.md' 2>/dev/null | head -20

Câu hỏi B10: Agent hiện đọc context-pack bằng cách nào? Nếu qua filesystem path cố định → xóa KB an toàn. Nếu qua KB search → cần giữ latest trên KB hoặc chuyển đọc sang filesystem trước.


§4. Report format

Upload report tại:

knowledge/dev/laws/dieu44-trien-khai/reports/20a-20b-p0-search-vector-hygiene-inspection-report.md

Report structure:

# 20A/20B-P0 — Search/Vector Hygiene Inspection Report

## 20A Verdict
- Filter feasibility: VIABLE / NOT VIABLE / UNCLEAR
- Evidence: [code snippets, function names, params]
- If VIABLE: patch points (file, function, LOC estimate)
- If NOT VIABLE: reason

## 20B-P0 Findings

### DOT Build Script
- B1 Upload pattern: accumulate / overwrite
- B2 Delete-after-upload: exists / absent
- B3 Patch insertion point: [location]

### Filesystem
- B4 Build count on FS: [number]
- B4 Cron cleanup: exists / absent
- B5 Disk space: [size]
- B5 Cold archive feasible: yes / no

### PG Manifest
- B6 Audit trail sufficient: yes / no
- B6 Schema: [columns]
- B7 v_context_pack_latest build: [build_id] — matches KB latest: yes / no

### Delete Feasibility
- B8 Delete candidates count: [number]
- B9 Full KB removal risk: [assessment]

### Agent Runtime Dependency
- B10 Agent reads context-pack from: KB search / filesystem / both

## Recommendation
- Primary: ngừng upload KB / giữ latest only / khác
- 20A next: patch / skip
- 20B next: design lifecycle P1 / cần thêm investigation

§5. Hard Boundaries

  • ✅ READ-ONLY. Không sửa code, không sửa config.
  • ✅ Không deleteDocument.
  • ✅ Không deindex.
  • ✅ Không patch DOT script.
  • ✅ Không patch Đ43.
  • ✅ Không sửa vector config.
  • ✅ Không cleanup filesystem.
  • ✅ Không service restart.
  • ✅ Không Pack 2C/IU.
  • ✅ Không hỏi lại User — đã đủ rõ.

§6. Nôm na

Cử kiểm tra viên đi xem 2 thứ:

  1. Công cụ tìm kiếm (search API): có lắp được bộ lọc để bỏ qua photocopy không? Nếu chỉ cần vặn 1 ốc nhỏ thì đáng làm. Nếu phải tháo cả máy thì bỏ qua.

  2. Kho lưu trữ (filesystem + sổ kiểm kê PG): có đủ rộng, đủ sổ sách để giữ bản cũ 7 ngày không? Bản mới nhất là bản nào? Agent đang đọc photocopy từ kệ tìm kiếm (KB) hay từ tủ hồ sơ (filesystem)?

Kiểm tra viên không được dọn gì. Chỉ ghi biên bản rồi về.


20A/20B-P0 Inspection Prompt | 2026-05-05 | Read-only. Chờ dispatch.

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/prompts/20a-20b-p0-search-vector-hygiene-inspection-prompt.md