How K-AI works
Five flows cover the whole system: the architecture, a chat request, a rented pod, a document going into a knowledge base, and who is allowed to do what.
Architecture
Three kinds of caller reach K-AI: chat front ends and software over the OpenAI API, agents over MCP, and people in the control panel. Everything passes the edge, where people authenticate with single sign-on and software presents a scoped key. The router is the centre: it owns the queue, picks nodes and grounds chats in knowledge. Compute nodes run vLLM; the knowledge API stores documents in a graph and vector database.
A chat request
- Authorise. The router checks the bearer key (the shared key or a personal one), its expiry and that it may use models. Failures return 401 or 403 in the OpenAI error shape.
- Resolve the profile. The model name is a profile. K-AI works out its engine settings (the load key) and its knowledge bases, intersected with what this key may read. Bases the key can't read are skipped.
- Find a node. The dispatcher considers nodes that are online, allowed by the profile's placement rules, big enough for the model and not recently failed. It prefers one already serving the model, least busy first, local before remote.
- Queue and swap. If nothing is serving the model, the request joins a queue. When in-flight requests drain and the grace window passes, the node pulls the model if it lacks it, stops the old engine, starts the new one and waits until it is ready. One swap serves everyone waiting.
- Nothing can serve it? If a rented pod could, the 503 says so and points to Start a pod. Otherwise it names the reason for each node.
- Admit and ground. Once admitted, the router searches the knowledge bases (inject), offers a search tool (tool), or both, so a slow knowledge service can't hold up the queue. If the service is down the request proceeds without it.
- Serve and record. The request is proxied to the node, the stream passes through, and a usage row is written: tokens, latency, node and status, never the content.
A RunPod pod
- Start. A button press, a schedule window or a burst rule asks for a pod. K-AI refuses if the spend cap is reached, no pod image is configured, or a pod for that profile is already deploying.
- Check the cap. The new pod's hourly price plus what is already running, looked ahead one hour, must stay under the monthly cap.
- Create and boot. K-AI creates the pod in the network volume's region, trying GPU types in order. A boot timeout terminates pods that never come online.
- Join. The pod's agent comes up; K-AI sees it and adds it to the router as a node.
- Load. The model is read from the network volume (downloaded once if missing) and the engine starts. About 15 minutes cold, about two minutes on a warm reload.
- Serve. Requests arrive like any other node's, with local nodes preferred unless the profile says otherwise.
- Stop. After the idle period with no finished request the pod is deleted; the model stays on the volume. A spend-cap latch, a boot timeout, a 12-hour backstop or an operator delete also end a pod.
Knowledge ingestion
- Accept. An upload, URL, chat capture or git sync arrives. Oversized files and duplicates (same hash in the same base) are rejected.
- Queue. A job is created; jobs run in order and resume after a restart.
- Extract text. Text and code are read directly; PDFs, EPUBs and Office files go through Apache Tika, with OCR for scanned pages. Headings are kept.
- Chunk. Heading-aware chunks of about 700 tokens with a small overlap.
- Embed. Each chunk gets a vector from the
embedmodel through the router. - Extract the graph. The
extractmodel returns entities and relationships per chunk, each with a short reason. Invalid answers are retried once. - Store. Chunks, vectors, entities and relations are written; evidence accumulates on repeated relations.
- Search. A query is embedded, matched by vector and by keyword, fused, and expanded one hop through the graph.
Speed: graph extraction is the slow step. On a single 16 GB consumer GPU, a typical technical book (a few hundred chunks) takes on the order of ten to fifteen minutes. Embedding is fast.
Sign-in and grants
- People sign in. The control panel is behind an OIDC reverse proxy. Membership of the allowed group lets you in; an admin group unlocks admin pages.
- Mint a key. On the API keys page, name it, choose model and knowledge grants and an expiry. The key is shown once; only a peppered hash is kept.
- Software calls the API. The router verifies the key and checks the grant. The knowledge API asks K-AI to verify the same key over a pinned TLS channel and caches the answer briefly.
- Narrow or revoke. Take effect at once on the router and within a minute on the knowledge API. Keys can only be narrowed.