A multi-tenant, permissions-aware knowledge assistant. Each organization connects its documents, the system indexes them per tenant, and users ask questions and get grounded, cited answers drawn only from the documents they are allowed to see.
This is a portfolio project about the operational layer around an LLM application, not the retrieval technique. The interesting parts are tenancy, access-controlled retrieval, background ingestion, quotas and cost attribution, audit, and evals that gate merges. The RAG core is reused from earlier work.
https://knowledge-desk.fly.dev
Recorded against the live deployment with vhs demo.tape, so every answer above
is a real Claude call over real retrieval. Acme's handbook answers the question.
Globex retrieves only its own documents and the assistant refuses rather than
reaching for the model's general knowledge, which is the permission boundary
holding all the way through to the generated text.
Log in as owner@acme.test or owner@globex.test (password
demo-password-123) and ask "how long do refunds take?" in both. Acme answers
it with a citation; Globex retrieves only its own documents and says it has
nothing it is allowed to cite. That refusal is the whole point of the project.
Running with real Claude answers and Voyage embeddings. The machine sleeps when idle, so the first request after a quiet period pays a cold start.
Six evals gate every merge here, and each asserts a system property that holds whatever the model says: a permission boundary held, a citation resolves, an injected instruction was quoted rather than obeyed. They pass identically on any model you point them at, which is what makes them trustworthy and also what they cannot tell you. Nothing in this repository measures whether the answers are any good.
They also cannot tell you whether a model answered at all. claude-opus-5
declines this system prompt outright, with stop_reason: refusal and category
reasoning_extraction, so every answer came back empty while all six evals
stayed green. A property that holds for any model also holds when no model
answered. tests/test_real_provider.py is the one check that calls a real model
and asserts it was not refused; it runs on its own, with a key, and the story is
in LESSONS.md.
model-swap is the project that
does, with this app as its system under test. It drives the assistant in-process
against its own corpus, grades the answers with a judge calibrated against human
labels, and reads the result against a margin declared before the comparison ran.
Three defects in this repository were found by it and fixed here: a tenant delete
that stranded its owner's account, a pricing table the budget cap is summed from
that was wrong for Sonnet, and a request parameter that made answer_model
configurable in name only.
Feature complete and deployed. See WALKTHROUGH.md for a narrated trip through the app end to end (branch points, gotchas, and what it is and is not good at), LESSONS.md for what the build taught, including the mistakes, and CHANGELOG.md for what changed when.
Ingestion is asynchronous, so embedding never blocks a request. Asking is synchronous and streams. The interesting property is that a question can only ever reach documents the asker is allowed to see, and that is enforced three independent times (marked below), so no single missed filter leaks data.
flowchart TB
subgraph client [Browser]
UI[React SPA<br/>ask, sources, members, usage]
end
subgraph api [FastAPI]
AUTH[Session auth<br/>bearer token, role gate]
SCOPE["TenantScope<br/>🛡️ 1. stamps org_id on every query"]
ASK[Assistant<br/>SSE stream]
RL[Rate limit + budget cap]
end
subgraph workers [Background]
Q[(jobs table<br/>skip-locked, retry, dead-letter)]
W[Drain, in the API process<br/>chunk, embed, store]
end
subgraph data [Postgres + pgvector]
DB["orgs, users, documents, chunks<br/>🛡️ 3. row-level security<br/>least-privilege role"]
end
subgraph ext [External]
VO[Voyage embeddings]
CL[Claude]
LF[Langfuse traces]
end
UI -->|upload| AUTH
UI -->|ask| AUTH
AUTH --> SCOPE
SCOPE --> RL
RL --> ASK
SCOPE -->|enqueue| Q
Q --> W
W --> VO
W --> DB
ASK -->|"🛡️ 2. ACL filter inside<br/>the candidate fetch"| DB
ASK --> CL
ASK -.->|org and user tagged| LF
ASK -->|"meta, sources, tokens, done"| UI
The three shields are the whole point: the data layer filters by org_id, the
retrieval query filters by the caller's ACL in the same SQL that ranks
candidates (so forbidden rows are never scored), and row-level security denies
by default underneath both. A bug in any one of them is not a data leak.
FastAPI, Postgres with pgvector, a Postgres-backed job queue, React plus Vite plus TypeScript, Voyage embeddings, Claude for answers, Langfuse for observability, Docker, and GitHub Actions. Runs keyless with a loud mock fallback, so it works and tests green with no API keys.
For development, run the database in Docker and the app on the host:
docker compose up -d db # Postgres + pgvector on :5436
python -m knowledge_desk.migrate # creates schema, RLS, and the app role
python check_setup.py # preflight
python -m knowledge_desk.seed # two demo orgs (optional)
uvicorn knowledge_desk.main:app --reload # API on :8000, drains the job queue itself
cd frontend && npm install && npm run dev # UI on :5173 (set VITE_API_BASE=http://localhost:8000)Or run the whole stack (API + built UI + db) in containers:
docker compose up --build # app on http://localhost:8000After python -m knowledge_desk.seed (password demo-password-123):
| org | |
|---|---|
| acme | owner@acme.test |
| globex | owner@globex.test |
Each org's documents are non-overlapping, so a question in one org can never retrieve the other's content.
With LANGFUSE_* keys set, each question emits one Langfuse trace tagged by org
and user: a retriever span that records how many of the org's chunks the caller
was allowed to see (the ACL filter, made visible), and the answer as a generation
with token usage and cost. Without keys it is a no-op, and every tracer call is
exception-proof, so observability can never take the product down.
Questions, answers, and document paths are PII-redacted on the way out, and the user is tagged by id rather than email address. The same text is stored unredacted in Postgres, which is deliberate: a question is content, and reading that table already means being an admin of the asker's own org. Langfuse is a third party, so neither half of that argument travels with it.
MIT. See LICENSE.
