koan-ai-integration
About
This Claude Skill provides AI integration capabilities for chat endpoints, embeddings, and RAG workflows using entity patterns. It enables developers to store embeddings directly on entities and leverage vector repositories for semantic search. Use this skill when you need to add AI-powered chat functionality or implement retrieval-augmented generation with your existing entity data structures.
Documentation
Koan AI Integration
Core Principle
AI capabilities integrate seamlessly with entity patterns. Store embeddings on entities, use vector repositories for search, and leverage standard Entity<T> patterns for AI-enriched data.
Quick Reference
Chat Endpoints
public class ChatController : ControllerBase
{
private readonly IAi _ai;
[HttpPost]
public async Task<IActionResult> Chat(
[FromBody] ChatRequest request,
CancellationToken ct)
{
var response = await _ai.ChatAsync(new AiChatRequest
{
Model = "gpt-4",
Messages = request.Messages,
SystemPrompt = "You are a helpful assistant.",
Temperature = 0.7
}, ct);
return Ok(new { message = response.Content, usage = response.Usage });
}
}
Entity with Embeddings
[DataAdapter("weaviate")] // Force vector database
public class ProductSearch : Entity<ProductSearch>
{
public string ProductId { get; set; } = "";
public string Description { get; set; } = "";
[VectorField]
public float[] DescriptionEmbedding { get; set; } = Array.Empty<float>();
// Semantic search
public static async Task<List<ProductSearch>> SimilarTo(
string query,
CancellationToken ct = default)
{
return await Vector<ProductSearch>.SearchAsync(query, limit: 10, ct);
}
}
RAG Workflow
public class KnowledgeBaseService
{
private readonly IAi _ai;
public async Task<string> AnswerQuestion(string question, CancellationToken ct)
{
// 1. Find relevant documents via vector search
var relevantDocs = await KnowledgeDocument.SimilarTo(question, ct);
// 2. Build context from documents
var context = string.Join("\n\n", relevantDocs.Select(d => d.Content));
// 3. Query AI with context
var response = await _ai.ChatAsync(new AiChatRequest
{
Model = "gpt-4",
SystemPrompt = $"Answer based on this context:\n\n{context}",
Messages = new[] { new AiMessage { Role = "user", Content = question } }
}, ct);
return response.Content;
}
}
Configuration
{
"Koan": {
"AI": {
"Providers": {
"Primary": {
"Type": "OpenAI",
"ApiKey": "{OPENAI_API_KEY}",
"Model": "gpt-4"
},
"Fallback": {
"Type": "Ollama",
"BaseUrl": "http://localhost:11434",
"Model": "llama2"
}
}
},
"Data": {
"Sources": {
"Vectors": {
"Adapter": "weaviate",
"ConnectionString": "http://localhost:8080"
}
}
}
}
}
When This Skill Applies
- ✅ Integrating AI features
- ✅ Semantic search
- ✅ Chat interfaces
- ✅ Embeddings generation
- ✅ RAG workflows
- ✅ AI-enriched entities
Reference Documentation
- Full Guide:
docs/guides/ai-integration.md - Vector How-To:
docs/guides/ai-vector-howto.md - Sample:
samples/S5.Recs/(AI recommendation engine) - Sample:
samples/S16.PantryPal/(Vision AI integration)
Quick Install
/plugin add https://github.com/sylin-org/koan-framework/tree/main/ai-integrationCopy and paste this command in Claude Code to install this skill
GitHub 仓库
Related Skills
sglang
MetaSGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.
evaluating-llms-harness
TestingThis Claude Skill runs the lm-evaluation-harness to benchmark LLMs across 60+ standardized academic tasks like MMLU and GSM8K. It's designed for developers to compare model quality, track training progress, or report academic results. The tool supports various backends including HuggingFace and vLLM models.
llamaguard
OtherLlamaGuard is Meta's 7-8B parameter model for moderating LLM inputs and outputs across six safety categories like violence and hate speech. It offers 94-95% accuracy and can be deployed using vLLM, Hugging Face, or Amazon SageMaker. Use this skill to easily integrate content filtering and safety guardrails into your AI applications.
langchain
MetaLangChain is a framework for building LLM applications using agents, chains, and RAG pipelines. It supports multiple LLM providers, offers 500+ integrations, and includes features like tool calling and memory management. Use it for rapid prototyping and deploying production systems like chatbots, autonomous agents, and question-answering services.
