Summarize indexed knowledge sources by topic in chat
This commit is contained in:
+36
-2
@@ -427,11 +427,45 @@ enum KnowledgeInventory {
|
||||
|
||||
static func matches(_ prompt: String) -> Bool {
|
||||
let words = Set(prompt.lowercased().split { !$0.isLetter })
|
||||
let inventory = !words.isDisjoint(with: ["list", "show", "browse", "what", "which"])
|
||||
let subjects = !words.isDisjoint(with: ["topics", "documents", "files", "sources", "contents", "indexed"])
|
||||
let inventory = !words.isDisjoint(with: ["list", "show", "browse", "what", "which", "summarize", "categorize"])
|
||||
let subjects = !words.isDisjoint(with: ["topics", "documents", "files", "sources", "contents", "indexed", "categories", "overview", "summaries"])
|
||||
return words.contains("knowledge") && inventory && subjects
|
||||
}
|
||||
|
||||
static func wantsTopics(_ prompt: String) -> Bool {
|
||||
let words = Set(prompt.lowercased().split { !$0.isLetter })
|
||||
return !words.isDisjoint(with: ["topics", "categories", "overview", "summaries"])
|
||||
}
|
||||
|
||||
static func topicOverview(_ sources: [String]) -> String {
|
||||
let categories: [(String, String, Set<String>)] = [
|
||||
("Development standards", "Standards, guidelines, conventions, and policies.", ["standards", "guidelines", "conventions", "policies"]),
|
||||
("PHP and Laravel", "PHP applications, Laravel, and related frameworks and packages.", ["php", "laravel", "symfony", "composer", "eloquent"]),
|
||||
("Python and data science", "Python programming, data analysis, and scientific computing.", ["python", "pandas", "numpy", "jupyter", "scipy"]),
|
||||
("Databases", "Database design, SQL, and data storage.", ["sql", "database", "databases", "mysql", "postgresql", "sqlite", "db2", "redis"]),
|
||||
("Web development", "Web interfaces, JavaScript, and browser technologies.", ["javascript", "typescript", "react", "vue", "html", "css", "web"]),
|
||||
("Infrastructure and operations", "Deployment, containers, operating systems, and automation.", ["docker", "kubernetes", "linux", "devops", "deployment", "ansible", "terraform"]),
|
||||
("AI and machine learning", "Models, machine learning, and AI tooling.", ["ai", "llm", "mlx", "ollama", "machine", "tensorflow", "pytorch"]),
|
||||
("Software engineering", "Architecture, patterns, testing, and general programming.", ["design", "patterns", "architecture", "testing", "programming", "engineering"])
|
||||
]
|
||||
var grouped: [Int: [String]] = [:]
|
||||
for source in sources {
|
||||
let words = Set(source.lowercased().split { !$0.isLetter }.map(String.init))
|
||||
let category = categories.indices.first { !words.isDisjoint(with: categories[$0].2) } ?? categories.count
|
||||
grouped[category, default: []].append(source)
|
||||
}
|
||||
var lines = ["Topic overview for \(sources.count.formatted()) indexed sources. Categories are inferred from document paths."]
|
||||
for index in (0...categories.count) {
|
||||
guard let entries = grouped[index] else { continue }
|
||||
let title = index < categories.count ? categories[index].0 : "Other indexed documents"
|
||||
let summary = index < categories.count ? categories[index].1 : "Paths without a clear match to the named topics."
|
||||
lines.append("**\(title)** · \(entries.count.formatted()) sources\n\(summary)")
|
||||
lines.append(entries.prefix(3).map { "• " + $0 }.joined(separator: "\n"))
|
||||
}
|
||||
lines.append("Ask “List all documents in our knowledge base” for the full inventory.")
|
||||
return lines.joined(separator: "\n\n")
|
||||
}
|
||||
|
||||
static func sources(client: any MCPToolClient) async throws -> [String] {
|
||||
struct Page: Decodable {
|
||||
let sources: [String]
|
||||
|
||||
Reference in New Issue
Block a user