Systems Library / Customer Service / How to Build an AI Knowledge Article Suggester
Customer Service ticket management

How to Build an AI Knowledge Article Suggester

Suggest relevant knowledge articles to agents while they handle tickets.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

An ai knowledge article suggestion system for support agents surfaces the right help article the moment a ticket opens. I build these to cut the time agents spend searching through documentation. Instead of digging through a knowledge base, the system reads the ticket and suggests the 3 most relevant articles with confidence scores.

Agents who use suggested articles resolve tickets 40% faster. That is the difference between searching and finding.

What You Need Before Starting

Step 1: Index Your Knowledge Base

Convert articles to embeddings for semantic search:

import chromadb
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("all-MiniLM-L6-v2")
chroma = chromadb.PersistentClient(path="./kb_vectors")
collection = chroma.get_or_create_collection("knowledge_base")

def index_articles(articles):
    for article in articles:
        text = f"{article['title']} {article['content']}"
        embedding = model.encode(text).tolist()
        collection.add(
            ids=[article["id"]],
            embeddings=[embedding],
            documents=[text],
            metadatas=[{"title": article["title"], "url": article["url"], "category": article["category"]}]
        )

Step 2: Build the Suggestion Engine

When a ticket comes in, find the closest matching articles:

def suggest_articles(ticket_subject, ticket_body, top_k=3):
    query_text = f"{ticket_subject} {ticket_body}"
    query_embedding = model.encode(query_text).tolist()

    results = collection.query(
        query_embeddings=[query_embedding],
        n_results=top_k
    )

    suggestions = []
    for i in range(len(results["ids"][0])):
        suggestions.append({
            "id": results["ids"][0][i],
            "title": results["metadatas"][0][i]["title"],
            "url": results["metadatas"][0][i]["url"],
            "relevance_score": round(1 - results["distances"][0][i], 3)
        })

    return suggestions

Step 3: Hook into the Ticket Workflow

Trigger suggestions automatically on new tickets:

from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/ticket-created", methods=["POST"])
def on_ticket_created():
    ticket = request.json

    suggestions = suggest_articles(ticket["subject"], ticket["body"])

    add_internal_note(ticket["id"], format_suggestions(suggestions))

    return jsonify({"ticket_id": ticket["id"], "suggestions": suggestions})

def format_suggestions(suggestions):
    lines = ["Suggested knowledge articles:"]
    for s in suggestions:
        lines.append(f"- [{s['title']}]({s['url']}) (relevance: {s['relevance_score']})")
    return "\n".join(lines)

Step 4: Track Which Suggestions Get Used

Log when agents click a suggested article to measure usefulness:

import sqlite3

def log_suggestion_used(ticket_id, article_id):
    conn = sqlite3.connect("suggestions.db")
    conn.execute("""
        INSERT INTO suggestion_usage (ticket_id, article_id, used_at)
        VALUES (?, ?, datetime('now'))
    """, (ticket_id, article_id))
    conn.commit()

def get_usage_stats():
    conn = sqlite3.connect("suggestions.db")
    total_suggested = conn.execute("SELECT COUNT(*) FROM suggestions").fetchone()[0]
    total_used = conn.execute("SELECT COUNT(*) FROM suggestion_usage").fetchone()[0]
    return {"usage_rate": round(total_used / total_suggested * 100, 1) if total_suggested else 0}

Step 5: Re-Index on Content Updates

Keep suggestions fresh by re-indexing when articles change:

def update_article_index(article):
    text = f"{article['title']} {article['content']}"
    embedding = model.encode(text).tolist()
    collection.update(
        ids=[article["id"]],
        embeddings=[embedding],
        documents=[text],
        metadatas=[{"title": article["title"], "url": article["url"], "category": article["category"]}]
    )

What to Build Next

Add a feedback button. When an agent marks a suggestion as "not helpful," log that data and use it to fine-tune your embedding model or add missing articles to the knowledge base.

Related Reading

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

Related Systems