Memory chưa phải knowledge
AI agent có memory — nhưng memory không phải knowledge. GoClaw đã có 3-tier memory: Working → Episodic → Semantic. Nhưng khi agent cần tìm document cụ thể, cross-reference giữa files, hoặc track mối quan hệ tài liệu — memory system không đủ.
Tìm kiếm phân mảnh — phải query từng store riêng
Không có document relationships — backlinks không tồn tại
Stale content — external edits không đồng bộ vào DB
Knowledge Vault giải quyết cả 3: document registry + wikilinks + hybrid search + filesystem sync.
Query layer trên memory system
| Component | Vai trò |
|---|---|
| VaultStore | Document CRUD, quản lý links, hybrid search (FTS + vector) |
| VaultSearchService | Điều phối search: fan-out song song qua vault, episodic, KG |
| EnrichWorker | Pipeline async 5 phase: prepare → summarize → embed → classify → wikilinks |
| VaultSyncWorker | Giám sát filesystem: phát hiện file thay đổi, đồng bộ hash |
| VaultInterceptor | Hook file operations: tự đăng ký document khi agent write |
| VaultRetriever | Cầu nối vault search vào agent L0 memory |
Write Path
Read Path
Tenant & Scope Isolation
Mỗi document thuộc 1 phạm vi: personal (riêng agent), team (team workspace), shared (cross-agent, chưa triển khai). Documents của tenant A hoàn toàn tách biệt tenant B — kể cả links cũng không thể cross-tenant. Personal docs có thể link đến team docs.
vault_documents + vault_links
Document registry: metadata pointers. Content sống trên filesystem; DB giữ path, hash, embeddings.
Indices
HNSW (Hierarchical Navigable Small World, m=16, ef=64) — index chuyên dụng cho vector search, tìm documents "gần nhau" về ngữ nghĩa. GIN (Generalized Inverted Index) — index cho full-text search, tìm nhanh documents chứa keyword cụ thể.
vault_links
7 loại link: wikilink (tự động từ [[...]]), reference, depends_on, extends, related, supersedes, contradicts. Semantic links do LLM phân loại.
[[Links]] hai chiều
Bidirectional markdown links theo format [[target]] — giống Obsidian hay Notion.
Resolution Strategy
GetDocument(tenantID, agentID, target).md suffixpath_basenameSync Strategy
SyncDocLinks() — replace strategy: Extract [[...]] → xóa outgoing wikilinks cũ → resolve targets → batch tạo mới. Semantic links (LLM-classified) không bị ảnh hưởng.
FTS + Vector + Cross-Store Fan-Out
Tại sao cần "hybrid"?
Giả sử agent search "cách xác thực người dùng": FTS tìm đúng keyword nhưng bỏ sót docs dùng từ khác ("authentication flow"). Vector search hiểu nghĩa tương đương nhưng đôi khi trả kết quả "gần nghĩa" nhưng không liên quan. Kết hợp cả hai: FTS cho precision, vector cho recall.
Bước 1: FTS + Vector trong Vault
Bước 2: Fan-Out qua 3 Sources
Graceful degradation: Store nil → skip.
Overshooting: Mỗi store trả maxResults*2.
Team context: Từ RunContext — chống spoofing.
5-phase async worker
Khi document ghi vào workspace, chưa sẵn sàng cho search. EnrichWorker xử lý async qua 5 phase để biến raw file thành searchable document.
Dedup check (docID + hash) → batch fetch metadata → đọc file (max 4MB) → filter docs đã có summary.
Gom 5 docs vào 1 LLM call. Temp 0.2, max 1536 tokens. Output JSON: [{"idx":1,"summary":"..."}]. Giảm 5x LLM calls.
Ghép title + path + summary → embedding vector 1536 chiều. Biến text thành "tọa độ" trong không gian ngữ nghĩa.
FindSimilarDocs (cosine ≥ 0.7) → LLM classify thành 6 loại link. Temp 0.1. Output SKIP nếu không có mối quan hệ.
Extract [[...]] → resolve targets → xóa wikilinks cũ → batch tạo mới. Dedup map bounded 10K entries, evict 25%.
Tuning Constants
Retry: Escalating timeouts 5→7→10 phút, backoffs 0→2→4s. BatchQueue: Lock-free producer-consumer per tenant:agent — ngăn thundering herd khi rescan.
Đồng bộ & bảo vệ workspace
Agent ghi file, nhưng file có thể bị sửa từ bên ngoài (user edit, git pull). Vault có 3 cơ chế đồng bộ:
fsnotify theo dõi workspace. Debounce 500ms → SHA-256 hash → so sánh DB → trigger EnrichWorker nếu thay đổi. Chỉ sync docs đã đăng ký.
Quét toàn bộ workspace với limits: 5K files, 500MB total, 50MB/file. Skip symlinks, node_modules, .git. Path traversal blocked.
VaultInterceptor.BeforeRead() — khi agent đọc file, check hash FS vs DB. Catch external edits ngay cả khi watcher không chạy.
Ownership Inference
Auto-inject vào agent context
VaultRetriever tự động inject relevant documents vào context trước khi agent suy nghĩ — agent không cần chủ động gọi vault_search.
User hỏi "cách thiết lập authentication" → vault tự inject docs/auth.md (score 0.92) + SOUL.md (score 0.45) vào context → agent trả lời chính xác hơn, không cần user chỉ file.
Ứng dụng thực tế
Agent ghi notes, dùng [[wikilinks]] cross-reference. Vault tự phát hiện links, tạo backlinks, index nội dung. Search trả về cả file trực tiếp lẫn docs liên quan qua wikilinks.
Personal docs (agents/my-agent/) chỉ agent thấy. Team docs (teams/uuid/) mọi thành viên search được. Personal có thể [[link]] đến team docs.
VaultRetriever tự inject relevant docs trước khi agent trả lời. User hỏi "authentication?" → agent đã có docs/auth.md trong context, không cần chỉ dẫn.
Mở Dashboard, dùng ngay
Knowledge Vault không cần cài đặt hay cấu hình gì thêm — mở Dashboard là dùng được ngay.
Mở Knowledge Vault
Sidebar trái → Vault (nhóm DATA). Giao diện 2 phần: danh sách documents (trái) + knowledge graph visualization (phải). Thanh lọc theo type (context, memory, note, skill, episodic, media) + dropdown lọc agent/team.
Upload Documents
Nhấn + (góc phải trên) → dialog "Upload to Vault" hiện lên → chọn phạm vi (Shared/Agent/Team) → kéo thả hoặc click để chọn files (.md, .txt, .json, .yaml, .csv, ...) → Upload. Enrichment pipeline tự chạy.
Rescan Workspace (tùy chọn)
Nhấn nút Rescan workspace (ngay cạnh nút +) → quét toàn bộ workspace, phát hiện files mới/thay đổi, tự suy luận scope (personal/team/shared).
Explore, Graph & Search
Sidebar duyệt documents theo type. Panel phải hiển thị knowledge graph — pan/zoom khám phá relationships giữa các docs. Search bar tìm kiếm thống nhất. Tạo manual links trong detail panel. Agent tự dùng vault trong hội thoại.
vault_search
Tool tìm kiếm thống nhất qua tất cả knowledge sources — agent gọi trực tiếp trong hội thoại khi cần tìm tài liệu.
| Param | Type | Required | Mô tả |
|---|---|---|---|
query | string | ✓ | Natural language search query |
scope | string | Filter: personal, team, shared (mặc định: all) | |
types | string | Comma-separated: context, memory, note, skill, episodic (mặc định: all) | |
maxResults | number | Số kết quả tối đa (mặc định: 10) |
HTTP Endpoints
Documents
| Method | Endpoint | Chức năng |
|---|---|---|
GET | /v1/vault/documents | Danh sách documents (filter: scope, doc_type, team_id) |
POST | /v1/vault/documents | Tạo document mới |
GET | /v1/vault/documents/{docID} | Chi tiết 1 document |
PUT | /v1/vault/documents/{docID} | Cập nhật metadata |
DELETE | /v1/vault/documents/{docID} | Xóa document |
Links
| Method | Endpoint | Chức năng |
|---|---|---|
GET | .../{docID}/links | Outbound + backlinks |
POST | /v1/vault/links | Tạo link (from, to, type, context) |
DELETE | /v1/vault/links/{linkID} | Xóa link |
POST | /v1/vault/links/batch | Batch get links cho nhiều doc IDs |
Search & Operations
| Method | Endpoint | Chức năng |
|---|---|---|
POST | /v1/vault/search | Unified cross-store search |
POST | /v1/vault/upload | Upload files (max 50 files, 50MB/file) |
POST | /v1/vault/rescan | Quét lại workspace |
GET | ...enrichment-status | Tiến độ enrichment (JSON/SSE) |
Per-agent endpoints: Tất cả cũng có bản scoped tại /v1/agents/{agentID}/vault/... (backward compatible).
Concurrency guard: Rescan chặn 2 scan song song cùng tenant. Non-owner: Chỉ thấy personal docs + teams mình thuộc về.
4 migrations
| Migration | Nội dung |
|---|---|
| 000038 | Initial: vault_documents, vault_links, vault_versions |
| 000042 | Thêm summary, regenerate tsvector |
| 000043 | Thêm team_id, custom_scope |
| 000046 | Nullable agent_id, COALESCE constraint, trigger auto-scope |
File references
| Component | File | Vai trò |
|---|---|---|
| Vault service | internal/vault/*.go | Search coordinator, enrichment, wikilinks, FS walk |
| PG store | internal/store/pg/vault_*.go | Hybrid search (FTS + vector), link management |
| SQLite store | internal/store/sqlitestore/vault_*.go | Lite edition: FTS-only |
| Tools | internal/tools/vault_*.go | vault_search tool, VaultInterceptor hooks |
| HTTP handlers | internal/http/vault_*.go | REST API, upload, rescan, enrichment status |
| Migrations | migrations/000038-000046 | Schema evolution (4 iterations) |
Design Trade-offs
FTS 0.4, Vector 0.6 — Vector ưu tiên semantic; FTS bổ sung keyword precision. Cross-store 0.4/0.3/0.3 — Vault curated content ưu tiên.
5 docs/LLM call — Balance throughput vs quality. Cosine 0.7 — Chỉ classify truly similar, giảm noise.
Nullable agent_id — Team docs không bắt buộc thuộc agent. Replace strategy cho wikilinks — đơn giản, idempotent.