Build an Internal Knowledge Assistant with the Claude API
An internal knowledge assistant is a chat-based tool that answers employee questions using your company's own documents — wikis, runbooks, policies, support tickets, code comments — instead of relying only on what a model learned during training. If you're searching for how to build one with the Claude API, the short answer is: you combine a retrieval layer over your internal data with Claude's reasoning and conversation handling, then wrap it in an interface your team can actually use (Slack, a web app, or an internal portal).
This guide walks through the practical architecture decisions: how to structure document ingestion, how to decide what context to send to the model, how to handle permissions so people only see what they're allowed to see, and how to deploy it so it's reliable enough for daily use.
The core architecture
A knowledge assistant built on Claude has four moving parts:
- Document store — your source material (Confluence, Notion, Google Drive, a docs repo, ticket history) pulled into a searchable index.
- Retriever — logic that finds the most relevant chunks of text for a given question.
- Claude API — generates an answer grounded in the retrieved chunks, with conversation history for follow-ups.
- Interface — where people actually ask questions: Slack bot, internal web app, CLI, or browser extension.
This is retrieval-augmented generation (RAG) applied internally. The retrieval mechanics — embeddings, vector search, chunking strategy — are their own deep topic; what matters here is how the pieces fit together into something you can ship and maintain.
Ingestion and chunking
Before Claude sees anything, your documents need to be split into retrievable chunks. A few rules of thumb that hold up in practice:
- Chunk by logical section (a heading, a ticket, a paragraph cluster), not by fixed character count alone — arbitrary cuts break context.
- Keep chunks small enough to fit several into a single prompt (roughly 300–800 tokens each) but large enough to be self-contained.
- Store metadata with each chunk: source URL, last-updated date, author, and access group. You'll need this for citations and permissions later.
- Re-index on a schedule or on webhook events from your source systems, not just once. Internal knowledge rots fast.
Retrieval, then prompting
When a user asks a question, retrieve the top handful of relevant chunks (typically 3–8, depending on chunk size) and inject them into the Claude request as context, followed by the question. A minimal request looks like this:
const response = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-sonnet",
max_tokens: 1024,
system: "You are an internal knowledge assistant. Answer only using the provided context. Cite the source document for every claim. If the context doesn't contain the answer, say so explicitly.",
messages: [
{
role: "user",
content: `Context:\n${retrievedChunks.join("\n\n---\n\n")}\n\nQuestion: ${userQuestion}`
}
]
})
});
The system prompt is doing real work here. For an internal assistant, you want three behaviors enforced explicitly: stay grounded in the provided context, cite sources, and admit when the answer isn't in the retrieved material. Without that last instruction, models will confidently fill gaps with plausible-sounding guesses — exactly the failure mode that erodes trust in an internal tool.
See /docs/messages for the full request shape and /docs/quickstart if you're setting up API access from scratch.
Handling permissions correctly
This is the part teams get wrong most often. If your document store has access controls — some wiki pages are engineering-only, some HR documents are manager-only — your retrieval layer must respect those same controls before anything reaches Claude. Two approaches:
- Filter at retrieval time: tag each chunk with the access groups allowed to see it, and filter search results by the requesting user's group membership before building the prompt.
- Filter at ingestion time: only index documents the assistant is allowed to surface to anyone, and run a separate, more restricted index for sensitive material with its own access checks.
Never rely on the model to decide what a user "should" see based on instructions alone — permission logic belongs in your retrieval code, not in the prompt.
Conversation history and follow-ups
Internal assistants get used conversationally: someone asks a question, then asks "and what about staging?" A stateless single-turn system breaks immediately. Keep a running message history per session and pass it with each request so Claude has the prior turns:
{
"model": "claude-sonnet",
"messages": [
{ "role": "user", "content": "Context: ...\n\nQuestion: How do I rotate the deploy key?" },
{ "role": "assistant", "content": "..." },
{ "role": "user", "content": "And what about staging?" }
]
}
For longer sessions, re-run retrieval on the latest question (not the whole history) so context stays relevant, but keep the conversation turns intact so the model understands what "staging" refers to.
Streaming for a better feel
Internal tools live or die on responsiveness. Streaming the response token-by-token instead of waiting for the full answer makes the assistant feel instant, especially for longer explanations. If you're building the UI yourself, stream the response and render it incrementally — see /docs/streaming for the event format.
Tool use for live data
Static documents go stale. If your assistant should answer "what's the current status of ticket #4821" or "who's on call right now," give Claude access to a tool that queries your ticketing or on-call system directly instead of relying on indexed snapshots. Tool use lets the model decide when to call out to a function versus answer from retrieved context — covered in /docs/tools.
Where SubToAPI fits
Once the retrieval and prompt logic are built, the operational side still needs solving: API key management per environment, usage visibility across who's querying the assistant and how much it costs, and team access without sharing a single key in a config file. SubToAPI turns Claude access into a standard HTTPS API with scoped sub_live_... keys, per-key usage metadata, and seat-based team management, so you can issue a separate key for your knowledge assistant's staging and production environments and see exactly how much it's costing without digging through raw usage logs. Plans start at €9/month for solo builders, with Team and Scale tiers for larger rollouts — see /pricing, or start with a free trial at /signup.
questions
Do I need a vector database to build this? For anything beyond a handful of documents, yes — a vector database (or a managed search service) makes relevant-chunk retrieval fast and scalable. For small, static document sets, keyword search or even a flat text match can work as a starting point.
How do I stop the assistant from hallucinating answers? Ground every response in retrieved context, instruct the model explicitly to say when context is insufficient, and show citations so users can verify answers against the source document themselves.
Can this run inside Slack instead of a web app? Yes — the retrieval and Claude API logic stay the same regardless of interface; you just swap the frontend for a Slack bot that posts questions to your backend and streams or posts the response back into the channel.