KHANH NGUYENENGINEERING · AI · PRODUCTS
EN

Products / Companion OS

Companion OS

Connects, organises, remembers and searches your own knowledge (repositories, docs, wikis, websites) and answers questions about it with citations you can check. When the answer isn’t in your knowledge, it says so.

Pre-release · Phase 1 Rust · Axum · PostgreSQL 16 · pgvector · Next.js Not public yet

The problem

Engineering knowledge is fragmented across GitHub, documentation sites, PDFs, Markdown, local folders and internal wikis. Chat assistants can talk about all of it, but they can’t tell you where an answer came from, and they rarely admit when your material simply doesn’t contain one.

Companion OS is built around one rule:

Every answer carries citations, or an explicit “I don’t know”. There is no third category.

Phase 1 succeeds when a user can import a project, search it, ask project-specific questions, get a citation or an honest refusal for every answer, and come back later without re-explaining context. The first product on the core is a Knowledge Companion; later companions (code, SQL, API, infrastructure) are meant to reuse the same core by configuration rather than by forking it.

Architecture

A modular monolith: one Rust workspace with a crate per bounded context (identity, workspace, knowledge, indexing, search, conversation), and two binaries, api and worker, built from the same crates with different composition roots. PostgreSQL holds relational data, the job queue, the outbox, vectors and full-text indexes.

Companion OS architecture: web to API over REST and SSE; API and worker share PostgreSQL; worker stores blobs in object storage; both call LLM providers through the AI gateway. WebNext.js 15 APIAxum · /api/v1 AI Gatewaychat · embeddings Workeringest · index PostgreSQL 16 schema per context · RLSoutbox · jobs (SKIP LOCKED)pgvector HNSW + FTS GIN LLM providersOpenAI · Ollama Object storagews/{id}/blobs/{sha} REST·SSE chat scoped tx claim embed
Dashed boxes are external. Chat streams over SSE, and citations are sent before the first content token.

A document goes through one pipeline from source to answer:

fetch → parse → normalize → revision ─(DocumentRevisionCreated)→ chunk → embed
      → write as pending → activate atomically → hybrid search → confidence gate
      → generate → grounding check → durable citations

Dependency direction is part of the architecture, not a convention: contexts may depend only on the kernel, adapters on contexts and platform, apps on everything. Cargo enforces it, and a fitness-function script fails CI on a violation. A self-test deliberately introduces one to prove the check turns red.

Workspace isolation in five layers

The isolation design starts from an uncomfortable assumption: application code will eventually be wrong. So no single layer is trusted to keep one workspace’s data out of another’s.

LayerMechanism
L1 RequestWorkspace resolved and authorised once, at the edge.
L2 TypeA WorkspaceScope token that repositories require; the compiler rejects unscoped access (checked with trybuild tests).
L3 DatabasePostgres row-level security; ScopedPool sets app.workspace_id per transaction.
L4 StorageObject keys prefixed ws/{workspace_id}/.
L5 IndexEvery vector and full-text query carries a workspace filter.

Key decisions

Each one is an accepted ADR with the alternatives written down. A few of them:

ADR-0021

Modular monolith with extraction seams

One crate per context, no cross-context joins or foreign keys. A context is extracted into a service only when a measured trigger says so.

Rejected: microservices per context (independent scaling nobody needs yet), a single-crate monolith (boundaries erode silently), serverless.

ADR-0024

Hybrid retrieval by default

Dense (pgvector) and lexical (Postgres FTS) retrieval run concurrently and are fused with reciprocal rank fusion, k = 60. Embeddings are systematically weak on rare literal tokens like E_CONN_REFUSED. Longer note →

Rejected: semantic-only with lexical “later”, weighted score fusion, a separate search engine, query-time routing.

ADR-0025

Index generations and embedding-model pinning

The tuple (model, dimensions, chunker version) defines an index generation. A new generation builds in the background and is activated atomically. Embedding never fails over to a different model.

Rejected: filtering by model at query time, rebuilding in place, continuous dual-write.

ADR-0026 · 0027

Postgres is the queue; events go through an outbox

Jobs are rows claimed with FOR UPDATE SKIP LOCKED under a lease. Domain events are written to an outbox in the same transaction as the change, relayed to an in-process bus, and handled idempotently. Longer note →

Rejected: Redis/BullMQ, Kafka/NATS, SQS, DB triggers with NOTIFY, CDC.

ADR-0028

Server-sent events for chat

Citations are streamed before content, with a time-to-first-token target of p95 < 2 s.

Rejected: WebSocket, long polling, gRPC streaming, non-streaming responses.

Status

Phase 1 is pre-release with no public users. Milestones as of September 2026:

  • M0 Governance · 14 ADRs accepted
  • M1 Walking skeleton · fitness functions verified in both directions
  • M2 Platform foundations · jobs, outbox, envelope encryption
  • M3 Identity, workspace, isolation · type-layer isolation proven by the compiler
  • M4 Knowledge & ingestion · PDF/DOCX, crawler and S3 adapter not yet
  • M5 Indexing + AI gateway · worker wiring and reindex job remain
  • M6 Hybrid search · not yet wired into the API
  • M7 Conversation, RAG, SSE · provider chat adapters remain
  • M8 Memory · M9 Companion composition + web · M10 Evals & release
What isn’t proven yet. Migrations, RLS and the database-layer isolation tests are written but haven’t been run against a real Postgres. The time-to-first-token target isn’t met: the full answer is currently generated before the first token is sent. There’s no eval runner yet, so retrieval quality hasn’t been measured.

Engineering evidence

~700unit and integration tests across M2–M7
6 / 6architecture fitness checks passing in CI
30golden eval queries, 6 deliberately unanswerable
≥ 0.95groundedness threshold the eval gate will enforce

Bugs the tests caught before any user could:

  • Chunk overlap corrupted character offsets, so a citation would have quoted the wrong passage.
  • Sibling Markdown headings were nested under each other.
  • A paragraph without sentence punctuation was never split.

Properties pinned by tests: re-importing unchanged content performs zero writes; one fabricated citation ungrounds the whole answer; citations arrive before the first token. Security tests cover SSRF (cloud metadata IP, @-userinfo tricks, IPv4-mapped loopback, DNS rebinding), path traversal, login timing, and refresh-token misuse.

Roadmap

  • Rest of Phase 1: memory v1 (bitemporal, with provenance), a second companion defined only by configuration, the full web UI, a ≥ 100-question eval set as a CI gate, load tests and a restore drill, then v0.1.0.
  • Phase 2: agents, MCP client and server, a companion SDK, reranking.
  • Phase 3: a Tauri desktop app with local-first sync.
  • Phase 4: WASM component-model plugins.

Later phases are ordered, not scheduled. Each one starts on a trigger, not a date.

Working on a hard problem?

I’m happy to talk about retrieval, backend architecture, developer tools, or anything on this site.