Semantic Kernel — Microsoft AI SDK Guide
Advertisement
Introduction
Semantic Kernel is Microsoft's SDK for building AI orchestration layers. This guide covers setup and practical usage for production applications.
Installation
pip install semantic-kernel
Basic Setup
import semantic_kernel as sk
kernel = sk.Kernel()
# Add OpenAI service
kernel.add_text_completion_service(
"openai",
sk.OpenAI.TextCompletion(
model_id="text-davinci-003",
api_key="your-key"
)
)
Skills and Functions
skill = kernel.import_semantic_skill_from_directory("skills")
# Execute skill
result = await kernel.run_async(
skill["summarize"],
input=large_text
)
Plugin Architecture
class MyPlugin:
@sk.kernel_function
def analyze_sentiment(self, text: str) -> str:
"""Analyze text sentiment."""
pass
kernel.import_plugin(MyPlugin(), "my_plugin")
Memory
from semantic_kernel.memory import SemanticTextMemory
memory = SemanticTextMemory(
storage=VolatileMemoryStore(),
embeddings_generator=embedding_service
)
await memory.save_information_async(
collection="documents",
id="doc1",
text="Important information"
)
Conclusion
Semantic Kernel provides enterprise-grade orchestration for AI applications. Ideal for complex workflows requiring state management and plugin extensibility.
FAQ
Q: How does Semantic Kernel compare to LangChain? A: Semantic Kernel is more structured; LangChain is more flexible.
Q: Is Semantic Kernel production-ready? A: Yes, backed by Microsoft's engineering.
Q: Can I use Semantic Kernel with local models? A: Yes, with appropriate adapters.
Advertisement