「AIとのチャット履歴を別のAIでも参照できたら...」
「過去の会話の文脈を踏まえた応答がほしい...」
このような課題を解決する可能性を秘めているのが、Apache UnomiとModel Context Protocol(MCP)の組み合わせです。この記事では、Apache UnomiをAIチャット履歴の管理に活用する方法について、実践的に解説していきます。
Apache Unomiは、顧客データプラットフォーム(CDP)として知られていますが、その特徴は:
これらの機能は、AIチャットの履歴管理にも非常に適しています。
// チャット履歴の保存 profile.setProperty("lastChat", { timestamp: "2024-01-19T10:00:00", content: "こんにちは、気温が低いですね", context: ["天候", "挨拶"] }); // 文脈を考慮した応答の取得 const context = profile.getProperty("lastChat").context; if (context.includes("天候")) { // 天候に関する文脈を考慮した応答 }
複数AIでの履歴共有
長期的な文脈理解
ユーザー嗜好の学習
ClaudeのMCPを使用することで、より高度な文脈管理が可能になります。
{ "mcpServers": { "unomi-server": { "command": "npx", "args": ["@inoyu/mcp-unomi-server"], "env": { "UNOMI_BASE_URL": "http://your-unomi-server:8181", "UNOMI_USERNAME": "karaf", "UNOMI_PASSWORD": "karaf", "UNOMI_PROFILE_ID": "your-profile-id", "UNOMI_KEY": "your-key", "UNOMI_EMAIL": "your@email.com" } } } }
プロファイルの自動作成と管理
セッション単位での文脈保持
スコープによる文脈の分離
// AI-A との会話をUnomiに保存 await unomiClient.saveChat({ aiType: "claude", content: message, context: currentContext }); // AI-B で過去の文脈を参照 const history = await unomiClient.getChatHistory({ timeRange: "24h", aiTypes: ["claude", "gpt"] });
キーワード抽出による文脈理解
センチメント分析との連携
トピックモデリングの適用
センシティブ情報の自動検出
データ保持期間の管理
アクセス制御の実装
公式ドキュメント
https://unomi.apache.org/manual/latest/
Apache UnomiのDockerイメージが公式に提供されています!これを使うと、セットアップがより簡単になります。
https://hub.docker.com/r/apache/unomi
Quick start with に記載がある
version: '3.8' services: elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5 environment: - discovery.type=single-node ports: - 9200:9200 unomi: # Unomi version can be updated based on your needs image: apache/unomi:2.0.0 environment: - UNOMI_ELASTICSEARCH_ADDRESSES=elasticsearch:9200 - UNOMI_THIRDPARTY_PROVIDER1_IPADDRESSES=0.0.0.0/0,::1,127.0.0.1 ports: - 8181:8181 - 9443:9443 - 8102:8102 links: - elasticsearch depends_on: - elasticsearch
docker pull apache/unomi
docker pull apache/unomi:2.4.0
https://github.com/modelcontextprotocol
https://github.com/modelcontextprotocol/specification
inoyu-mcp-unomi-server Claude Desktop Configuration Guide
https://mcp.so/server/inoyu-mcp-unomi-server
# POSTリクエストでプロファイルを作成 curl -X POST http://localhost:8181/cxs/profiles/ \ -H "Content-Type: application/json" \ -d '{ "itemType": "profile", "properties": { "firstName": "John", "lastName": "Doe", "email": "john@doe.com" } }'
# PATCHリクエストでプロファイルを更新 curl -X PATCH http://localhost:8181/cxs/profiles/profile-id \ -H "Content-Type: application/json" \ -d '{ "properties": { "age": 25, "interests": ["sports", "music"] } }'
{ "itemType": "session", "profileId": "profile-id", "properties": { "deviceId": "mobile-123", "browser": "Chrome" } }
{ "eventType": "view", "sessionId": "session-id", "profileId": "profile-id", "source": { "itemType": "site", "scope": "acme", "itemId": "page-123" } }
{ "itemType": "segment", "metadata": { "id": "premium-users", "name": "Premium Users", "scope": "acme" }, "condition": { "type": "profilePropertyCondition", "parameterValues": { "propertyName": "accountType", "comparisonOperator": "equals", "propertyValue": "premium" } } }
# セグメントに基づくユーザー検索 curl -X POST http://localhost:8181/cxs/profiles/search \ -H "Content-Type: application/json" \ -d '{ "segment": "premium-users", "offset": 0, "limit": 10 }'
{ "eventType": "purchase", "scope": "ecommerce", "profileId": "profile-id", "properties": { "productId": "123", "amount": 99.99 }, "source": { "itemType": "site", "itemId": "online-store" } }
curl -X POST http://localhost:8181/cxs/events/search \ -H "Content-Type: application/json" \ -d '{ "timeRange": { "from": "2024-01-01T00:00:00Z", "to": "2024-01-31T23:59:59Z" }, "condition": { "type": "eventTypeCondition", "parameterValues": { "eventTypeId": "purchase" } } }'
{ "itemType": "personalization", "scope": "acme", "strategy": "matching-first", "strategyOptions": { "segments": ["premium-users", "new-visitors"], "fallback": "default-content" } }
{ "itemType": "rule", "metadata": { "id": "ab-test-homepage", "name": "Homepage A/B Test" }, "condition": { "type": "randomCondition", "parameterValues": { "percentage": 50 } }, "actions": [ { "type": "setPropertyAction", "parameterValues": { "propertyName": "selectedVersion", "propertyValue": "A" } } ] }
"itemType": "consent", "scope": "acme", "status": "granted", "properties": { "purpose": "marketing", "expiration": "2025-01-01T00:00:00Z" } }
curl -X DELETE http://localhost:8181/cxs/profiles/profile-id
{ "eventType": "ai_chat", "scope": "chatbot", "profileId": "user-123", "properties": { "message": "こんにちは", "context": ["greeting"], "timestamp": "2024-01-20T10:00:00Z" } }
curl -X POST http://localhost:8181/cxs/events/search \ -H "Content-Type: application/json" \ -d '{ "condition": { "type": "eventTypeCondition", "parameterValues": { "eventTypeId": "ai_chat" } }, "sortby": "timestamp", "limit": 10 }'
{ "itemType": "rule", "condition": { "type": "booleanCondition", "parameterValues": { "operator": "and", "subConditions": [ { "type": "pastEventCondition", "parameterValues": { "eventType": "view", "minimumCount": 5 } }, { "type": "pastEventCondition", "parameterValues": { "eventType": "purchase", "minimumCount": 1 } } ] } } }
{ "itemType": "rule", "metadata": { "id": "realtime-reaction", "name": "Realtime User Action" }, "condition": { "type": "eventTypeCondition", "parameterValues": { "eventTypeId": "cart_abandon" } }, "actions": [ { "type": "sendEventAction", "parameterValues": { "eventType": "notification" } } ] }
# Basic認証の確認 curl -u karaf:karaf http://localhost:8181/cxs/cluster
org.apache.unomi.cors.allowed.origins=http://localhost:*
curl http://localhost:8181/cxs/sessions/current
Apache UnomiとMCPの組み合わせは、AIチャットの新しい可能性を開きます。特に:
文脈の永続化
マルチAI連携
プライバシー管理
これらの機能により、より自然で継続的なAIとの対話が実現できます。 ぜひ、あなたのプロジェクトでもApache UnomiとMCPを活用し、次世代のAIチャット体験を創造してみてください。