Shared Library & ACL
The shared knowledge base is the cross-Profile collaboration surface: collections → documents → versions → chunks, permissions granted per Profile, every action audited. Private and shared libraries live in separate tables and are merged by permission at retrieval time.
Storage and permission model
| Table | Role |
|---|---|
shared_collections | collection metadata + owner |
shared_acl | (collection, profile) → permission |
shared_documents | current-version documents |
shared_doc_versions | historical version snapshots (full text) |
shared_chunks | current-version chunks (FTS + vectors) |
shared_audit | per-action audit |
Three permission levels:
| Permission | Capabilities |
|---|---|
use | search, read documents, view versions and diffs |
edit | use + import documents, restore versions |
admin | edit + inbox sync, ACL edits, ownership transfer, document deletion, reindex |
Revocation is immediate: permission() reads shared_acl on every call, with no cache — once an admin removes a Profile, its next search cannot see the collection.
Two ownership invariants:
- The owner must retain admin: downgrading the owner to use/edit returns 400.
- Transfer grants admin to both sides: only the owner or an admin may initiate; both the target's and the old owner's ACL upsert to admin, audited as
acl.transfer(with from).
Versions: diff and restore
- Each import stores the old full text in
shared_doc_versions; history queries cap at 50 per document and 200 per collection. versionDiffruns a line-level diff (lineDiff) of historical version vs current full text.restoreVersionrequires edit/admin (use → 403): it re-imports the historical full text (whole-document replacement) and auditsrestore. Restore is not a pointer rollback — it produces a new current version, keeping the history chain intact.
Retrieval: the shared leg's fusion weights
Shared retrieval is independent of the private library and uses different fusion weights:
score = 0.55 × bm25_norm + 0.45 × cosine(The private library's rescue-style fusion is in Retrieval Pipeline.) Results from both libraries are merged and deduped by caller permission; collections without permission are filtered before merging and never leak into Top-K.
Audit and export
Every write action lands in shared_audit: reindex / sync / acl.update / acl.transfer / acl.remove / restore / delete, with actor, target and detail.
GET /api/v1/kb/audit/export exports CSV (cap 5000 rows): at, actor, actor_name, action, collection, target, detail — actor names resolve server-side, so clients cannot forge identity.
Index consistency
The shared library indexes only the current version: import deletes old chunks and rebuilds FTS and vectors; rebuilds can run as background jobs (see Background Reindex), with audit detail distinguishing sync vs background paths.
Structure at a glance
Figure 1 · Private and shared libraries: separate tables, merged at retrieval under ACL