Skip to content
FlyCockpit
Knowledge Base/ Git, Search & Assets
Knowledge Base logo

Git, Search & Assets

Knowledge BaseRust + TypeScriptApache-2.0
Repository

Work with bare Git storage and smart-HTTP pushes, PR proposals, provenance tracking, one-way mirrors, SQLite hybrid search, embeddings, and content-addressed assets.

Platforms: Linux, macOS, Windows (kb CLI) · Docker (server)

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 main requires write + an edit-capable PAT (edit or both); pushing a non-default user branch requires propose + 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. Only main is 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.json lineage, 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.json are 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-rollup every 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 active refs/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 main advances and creates conflicts, proposing against the new main returns CONFLICT with reason: "PROPOSAL_CONFLICT" containing headSha, baseSha, proposalHeadSha, and up to 50 conflicted paths with base/theirs/yours contents. Callers resolve conflicts progressively (even across >32 conflicts) by supplying baseRevision, proposalNumber, and proposalHeadSha.
  • Reviewed merges: Merging requires review permission (independent of write), explicit expectedHeadSha and expectedTargetSha from the inspected diff, and confirm: "MERGE". Every reviewed merge creates a two-parent audit commit (main first, 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 dream and agent documents, but can never overwrite human or 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 forge Acted-by: or Kb-*: trailers.
  • Commit trailers: Server commits attach Acted-by, Kb-Actor-Key (user:<id> or grant:<id>), and Kb-Provenance trailers, 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:

  1. Remote URL: Normalized to ssh://git@host[:port]/owner/repo.git under the public-network egress policy (private IPs rejected).
  2. Host identity: The server fetches and verifies SSH host keys via curve25519 key exchange—auto-approving github.com, gitlab.com, and bitbucket.org only against pinned provider fingerprints, and requiring explicit user fingerprint confirmation for custom hosts (no blind TOFU).
  3. 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.
  4. Dry-run test: The worker runs ls-remote and a dry-run push using a private 0700 tmpfs 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_hash when ≥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 explicit kbIds (or all readable bases when omitted, up to the instance limit kb.searchAll.limit, default 16; exceeding it returns TOO_MANY_BASES rather 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, or 8192 tokens, 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 (unpatched llama.cpp v0.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 via knowledge_assets_put or knowledge_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-range 206 support, and Cache-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.