How to Build an Employee Knowledge Base with AI
Create a self-updating internal knowledge base that answers employee questions.
Jay Banlasan
The AI Systems Guy
Employees ask the same questions over and over. Where is the expense policy? How do I request time off? What is the VPN setup? I built an ai employee knowledge base that answers these questions instantly by searching your internal documents and returning the exact answer.
This internal wiki system uses embeddings to find relevant content and AI to generate clear answers.
What You Need Before Starting
- Python 3.8+
- An AI API key (Claude for answers, OpenAI for embeddings)
- Your internal documents (SOPs, policies, guides) in text format
- A vector database (ChromaDB works locally)
Step 1: Collect and Chunk Your Documents
from pathlib import Path
def load_documents(docs_dir):
documents = []
for filepath in Path(docs_dir).rglob("*.md"):
content = filepath.read_text(encoding="utf-8")
chunks = chunk_text(content, chunk_size=500)
for i, chunk in enumerate(chunks):
documents.append({
"id": f"{filepath.stem}_{i}",
"text": chunk,
"source": filepath.name
})
return documents
def chunk_text(text, chunk_size=500):
words = text.split()
chunks = []
for i in range(0, len(words), chunk_size):
chunks.append(" ".join(words[i:i + chunk_size]))
return chunks
Step 2: Build the Vector Index
import chromadb
def build_index(documents):
client = chromadb.Client()
collection = client.create_collection("knowledge_base")
for doc in documents:
collection.add(
documents=[doc["text"]],
metadatas=[{"source": doc["source"]}],
ids=[doc["id"]]
)
return collection
Step 3: Search for Relevant Content
def search_knowledge(collection, query, top_k=3):
results = collection.query(
query_texts=[query],
n_results=top_k
)
context_parts = []
sources = set()
for doc, metadata in zip(results["documents"][0], results["metadatas"][0]):
context_parts.append(doc)
sources.add(metadata["source"])
return {
"context": "\n\n".join(context_parts),
"sources": list(sources)
}
Step 4: Generate Answers with AI
import anthropic
ai_client = anthropic.Anthropic()
def answer_question(question, search_results):
prompt = f"""Answer this employee question using ONLY the context provided.
If the context does not contain the answer, say "I could not find that in our documentation."
Be specific. Include any relevant steps, links, or contacts mentioned.
Context:
{search_results['context']}
Question: {question}
Sources used: {', '.join(search_results['sources'])}"""
message = ai_client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}]
)
return {
"answer": message.content[0].text,
"sources": search_results["sources"]
}
Step 5: Wire It Up as a Slack Bot
from slack_bolt import App
app = App(token="xoxb-your-bot-token")
@app.message("kb:")
def handle_kb_query(message, say):
query = message["text"].replace("kb:", "").strip()
search_results = search_knowledge(collection, query)
response = answer_question(query, search_results)
say(f"*Answer:* {response['answer']}\n\n_Sources: {', '.join(response['sources'])}_")
What to Build Next
Add a feedback button so employees can flag wrong or incomplete answers. Use those flags to identify documentation gaps. When enough people ask about something that is not in the docs, that is your signal to write new documentation.
Related Reading
- Input, Process, Output: The Universal AI Framework - the pattern behind every AI system
- Build vs Buy: The AI Framework - when to build custom vs use off-the-shelf
- The Compounding Advantage Nobody Talks About - how knowledge bases compound over time
Want this system built for your business?
Get a free assessment. We will map every system your business needs and show you the ROI.
Get Your Free Assessment