Git, Search & Assets
Work with bare Git storage and smart-HTTP pushes, PR proposals, provenance tracking, one-way mirrors, SQLite hybrid search, embeddings, and content-addressed assets.
Knowledge Base treats Git as the canonical source of truth for Markdown documents and asset manifests, SQLite (FTS5 + sqlite-vec) as a rebuildable hybrid search engine, and SHA-256 content-addressed storage (disk or optional S3) for immutable binary assets.
Bare Git storage and smart-HTTP
Every knowledge base is backed by a bare Git repository under KB_DATA_ROOT/repos/kb_<kbId>.git. Clone or push using the KB ID (never the display slug) with any HTTP Basic username and a PAT (kbp_…) as the password:
git clone https://kb.example.com/git/<kbId>.git knowledge
cd knowledge
git switch -c research
# Edit Markdown with `provenance: agent` in front matter, then commit
git push origin HEAD:refs/heads/research
Cookies and OAuth tokens are rejected on Git smart-HTTP. Keep PATs in your Git credential manager, never embedded in clone URLs.
Push admission and validation rules
- Single-ref, fast-forward CAS only: Multi-ref pushes, force pushes, branch deletions, and tags are refused before canonical refs move. Pushing
mainrequireswrite+ an edit-capable PAT (editorboth); pushing a non-default user branch requirespropose+ edit mode. Only the branch’s owner may advance it. - Reserved namespaces:
refs/heads/pr/<number>is reserved for server-managed auto-PRs and cannot be pushed over Git. Onlymainis indexed for search. - Whole-commit validation: Every newly reachable commit is validated for UTF-8/NFC paths, unique document IDs, restricted YAML front matter, valid
.assets/manifest.jsonlineage, and repository ceilings: 4,096 files, 8,192 entries, depth 32, 2 MiB per Markdown file, and 64 MiB total tree. Only Markdown, the fixed comment-only.gitignore, and.assets/manifest.jsonare permitted—no binaries, symlinks, executable modes, gitlinks, or Git LFS. - Push budgets: 50 MiB encoded request, 512 new commits, 100,000 objects / 128 MiB expanded objects, 120 s upload (10 s idle), and 60 s execution.
- Automatic compaction: The worker runs
kb-git-rollupevery 5 minutes to geometrically pack loose objects and small packs without ever garbage-collecting history.
Pull-request proposal workflow
Agents or collaborators with propose access never write directly to main:
- Auto-PRs: Propose-only MCP calls (
knowledge_changes_apply,knowledge_documents_*,knowledge_assets_put) open or extend the caller’s activerefs/heads/pr/<number>pull request. - Logical-model conflict detection: Conflicts are evaluated on documents (by path and ID) and asset manifest entries—catching simultaneous edits, duplicate IDs, case collisions, file/directory clashes, and repo limit breaches without ever writing Git merge markers.
- Progressive resolution: When
mainadvances and creates conflicts, proposing against the newmainreturnsCONFLICTwithreason: "PROPOSAL_CONFLICT"containingheadSha,baseSha,proposalHeadSha, and up to 50 conflicted paths withbase/theirs/yourscontents. Callers resolve conflicts progressively (even across >32 conflicts) by supplyingbaseRevision,proposalNumber, andproposalHeadSha. - Reviewed merges: Merging requires
reviewpermission (independent ofwrite), explicitexpectedHeadShaandexpectedTargetShafrom the inspected diff, andconfirm: "MERGE". Every reviewed merge creates a two-parent audit commit (mainfirst, proposal second) recording the reviewer even when fast-forward would be possible.
Provenance front matter and Git trailers
Every document carries a server-enforced provenance: field in its YAML front matter—clients never choose it:
| Value | Meaning |
|---|---|
human |
Last edited by a person in the web control plane |
agent |
Last edited directly by a credential over MCP or pushed via Git smart-HTTP |
dream |
Written by knowledge_changes_apply in mode: "dream" |
- Dream protection: Dreams may update
dreamandagentdocuments, but can never overwritehumanor unlabelled documents. - Merge precedence: When both sides of a PR modify the same document, the merged result keeps the more protected provenance (
human>agent>dream). - Git push enforcement: Every Markdown file added or modified by a Git push must declare
provenance: agent, and pushed commit messages may not forgeActed-by:orKb-*:trailers. - Commit trailers: Server commits attach
Acted-by,Kb-Actor-Key(user:<id>orgrant:<id>), andKb-Provenancetrailers, displayed in web document history and PR reviews.
One-way external mirrors
Managers can configure a one-way push mirror from main to an external Git repository under KB settings → Mirror:
- Remote URL: Normalized to
ssh://git@host[:port]/owner/repo.gitunder the public-network egress policy (private IPs rejected). - Host identity: The server fetches and verifies SSH host keys via curve25519 key exchange—auto-approving
github.com,gitlab.com, andbitbucket.orgonly against pinned provider fingerprints, and requiring explicit user fingerprint confirmation for custom hosts (no blind TOFU). - Deploy key: Generates a dedicated Ed25519 keypair, stores the private key encrypted under
KB_MASTER_KEY, and exposes only the public key to add to the remote. - Dry-run test: The worker runs
ls-remoteand a dry-run push using a private0700tmpfs scratch directory (/run/kb-mirror, never disk-backed) to verify write access.
Pushes are always explicit human actions (Push now)—never pull-backs, force pushes, or automatic side effects. Ownership transfers and restores automatically disconnect mirrors and destroy deploy-key ciphertext.
Hybrid SQLite search and knowledge_search_all
The worker builds each search index generation as an immutable SQLite file (index/<kbId>/<generationId>.sqlite) containing both an FTS5 lexical arm and a sqlite-vec vector arm, published read-only for the server’s reader thread pool.
Quantization and chunk bounds
| Quantization | Vector storage | Hard chunk bound |
|---|---|---|
binary_int8_rescore (default) |
1-bit Hamming + int8 cosine rescore (K = clamp(ceil(n/200), 200, 2000)) |
400,000 chunks |
int8 |
Per-file calibrated int8 cosine | 200,000 chunks |
- Incremental builds: Unchanged chunks (matched by SHA-256
chunk_hashwhen ≥50% of chunks match a retained generation of the same profile) copy their stored vectors directly without re-embedding. - Read-your-writes companion: Whenever a new commit has no active index on
main, a fast lexical-only companion builds first so newly committed documents are immediately searchable (SEMANTIC_INDEX_BUILDING) while semantic embedding completes in the background. - Fusion & graceful fallback: Hybrid search combines up to 80 candidates per arm with Reciprocal Rank Fusion (
1 / (60 + rank)), dropping English/Spanish stopwords and requiring >50% query-word coverage on the lexical arm during hybrid queries. Query embeddings time out after 8 s and trip a per-process circuit breaker (30 s doubling to 5 min) so slow or revoked providers transparently degrade to keyword search (LEXICAL_ONLY) instead of failing queries. - Multi-KB search (
knowledge_search_all): Searches up to 64 explicitkbIds(or all readable bases when omitted, up to the instance limitkb.searchAll.limit, default 16; exceeding it returnsTOO_MANY_BASESrather than silently truncating). Runs up to 2 bases concurrently with per-base authorization and budgets, returning up to 100 rank-interleaved hits (order: "rank_interleaved") plus a status row (ok,lexical_only,rebuilding,unavailable,rate_limited,deadline,not_found) for every base.
Embedding providers
Each KB attaches either the admin-enabled SYSTEM_BUILTIN model (providerId: "builtin") or a user-owned OpenAI-compatible HTTPS /embeddings provider (encrypted under KB_MASTER_KEY, pinned to public IP egress with no redirects):
- Built-in Apache-2.0 models (opt-in, never bundled in images):
embeddinggemma-2-Q8_0.gguf(768 dims, MEAN pooling, recommended when RAM fits)Qwen3-Embedding-0.6B-Q8_0.gguf(1024 dims, LAST pooling)
- Context tiers:
1024(default),2048,4096, or8192tokens, admitted against container cgroup/host RAM (<70% direct, 70%–90% explicit acknowledgement, ≥90% refused). - Process isolation: Only a forked worker child loads
node-llama-cpp(unpatchedllama.cppv0.9.0) and exits after 15 minutes idle to release RSS. The API server never loads native model runtimes.
Content-addressed assets and ZIP exports
Binary assets are stored outside Git in SHA-256 content-addressed storage (assets/) and referenced by each KB’s sorted .assets/manifest.json ({version: 1, entries: [{path, hash, size, mime}]}):
- Staging & limits: Upload in 192 KiB frames (
knowledge_upload_begin→write→finish, 1-hour staging TTL), then commit atomically viaknowledge_assets_putorknowledge_changes_apply. Max 25 MiB per asset, 2 MiB per Markdown upload (128 KiB inline). Logical quotas default to 1 GiB/KB and 5 GiB/owner. - Media & strict MIME boundary: Inline viewer supports JPEG, PNG, GIF, WebP, MP4, WebM, MP3, WAV, and Ogg. PDF is attachment-only; HTML, SVG, and unknown MIME types are rejected. Assets serve privately at
/kb-assets/:kbId/:hash?rev=<sha>with live auth, historical revision verification, single-range206support, andCache-Control: private, no-store. - Optional S3 asset authority (
KB_ASSET_S3_ENABLED=true): Disk CAS is the default. Opt-in S3 stores authoritative objects remotely while keeping a strictly bounded shared local cache (KB_ASSET_CACHE_MAX_BYTES, minimum 25 MiB). Switching between disk and S3 (or initializing a new S3 instance) requires the offline dual-fenced command/app/scripts/docker-entrypoint.sh asset-storage migrate --to s3|disk --attempt <uuid>. - ZIP exports: Whole-KB or assets-only exports (up to 8,192 entries and 256 MiB uncompressed; 1 active per user, 2 per server) build asynchronously as background jobs (30-minute deadline) so downloads never hit reverse-proxy timeouts.