GitRepository "SAP-samples/cap-ai-vector-engine-sample"に記載の、CAP, SAP HANA Vector Engine, SAP AI CoreをローカルPCとクラウドのHybridで動かしてみました(面倒なのでCAPをデプロイしていないだけです)。
上記のアーキテクチャで動きます(出典: 以下GitHub)。
時間なくてざっと動かして確認しました。そのため、非効率的な方法や誤りあるかもしれません。
前提
- SAP AI Coreはインスタンス作成済(Generative AI Hub、そしてOpenAIのサービスデプロイ済状態)
- SAP AI Launchpad はサービス作成済で、SAP AI Coreとも接続済
- SAP HANA Cloud をVector Engine 使える状態
- VS Code 1.89.1 を Macにインストール済
- cf cli は 8.4.0+b4c083e.2022-06-02
- Node関連
- Node: 20.11.0
ステップ
1. git clone
git clone で以下のリポジトリを落とします。
git clone https://github.com/SAP-samples/cap-ai-vector-engine-sample.git
2. install hana-cli
"optional"と書いてあって、不要なのかもしれませんがインストール。
% npm install -g hana-cli
added 983 packages in 47s
179 packages are looking for funding
run `npm fund` for details
3. npm install
application
のディレクトでnpm install
実行。
% npm install
added 593 packages, and audited 594 packages in 2m
57 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
4. BTP Cockpit
4.1. HDIサービスインスタンス作成
BTP Cockpit で該当のSpaceで Services -> Instances から "SAP HANA Schemas & HDI Containers"インスタンスを作成(planはhdi-shared)。名前は"i348221-hdi"で設定。
4.2. Destinationサービスインスタンス作成
BTP Cockpit で該当のSpaceで Services -> Instances から "Destination Service"インスタンスを作成(planはlite)。名前は"i348221-destination"で設定。
4.3. Destination登録
BTP Cockpit で該当のサブアカウントで Destination 登録。SAP AI Coreの Service Keyの情報とGitHubのReadmeを見ながら設定。
"URL"は<AI-API-OF-AI-CORE-SERVICE-KEY>/v2 # make sure to add /v2!
と記載がありますが、最後に/v2を付加しないで成功しています。他の人が設定したDestinationをコピーして作っていて、"/v2"なしで上手くできたので、そのままにしています(シナリオによっては動かない?)。
5. cds bind
5.1. cf login
ターミナルから cf login します。
cf login
5.2 cds bind(hdi)
ターミナルから以下のコマンド実行して、hdi サービスとbind。
% cds bind --to i348221-hdi:default
Retrieving data from Cloud Foundry...
Creating service key default - please be patient...
Binding db to Cloud Foundry managed service i348221-hdi:default with kind hana-cloud
Saving bindings to .cdsrc-private.json in profile hybrid
To run with cloud bindings use cds watch --profile hybrid
Service Keyが作られたようなので確認します。
cf service-keys i348221-hdi
Getting keys for service instance i348221-hdi as y.fukuhara@sap.com...
name last operation message
default create succeeded
5.3. cds bind(destination)
ターミナルから以下のコマンド実行して、destination サービスとbind。
cds bind --to i348221-destination
Retrieving data from Cloud Foundry...
Creating service key i348221-destination-key - please be patient...
Binding destinations to Cloud Foundry managed service i348221-destination:i348221-destination-key with kind destinations
Saving bindings to .cdsrc-private.json in profile hybrid
To run with cloud bindings use cds watch --profile hybrid
Service Keyが作られたようなので確認します。
cf service-keys i348221-destination
Getting keys for service instance i348221-destination as y.fukuhara@sap.com...
name last operation message
i348221-destination-key create succeeded
5.4. cdsrc-private.json 確認
cdsrc-private.json というファイルを確認。
{
"requires": {
"[hybrid]": {
"db": {
"binding": {
"type": "cf",
"apiEndpoint": "https://api.cf.eu10.hana.ondemand.com",
"org": "DBS Japan Shared_eu10",
"space": "demo-eu10",
"instance": "i348221-hdi",
"key": "i348221-hdi-key",
"resolved": false
},
"kind": "hana",
"vcap": {
"name": "db"
}
},
"destinations": {
"binding": {
"type": "cf",
"apiEndpoint": "https://api.cf.eu10.hana.ondemand.com",
"org": "DBS Japan Shared_eu10",
"space": "demo-eu10",
"instance": "i348221-destination",
"key": "i348221-destination-key",
"resolved": false
},
"kind": "destinations",
"vcap": {
"name": "destinations"
}
}
}
}
}
6. cds build
HANA のデータベースArtifactをビルドします。
cds build --for hana
building project [/Users/i348221/Documents/repositories/cap-ai-vector-engine-sample/application], clean [true]
cds-dk [7.9.4], cds [7.9.3], compiler [4.9.4], home [/Users/i348221/Documents/repositories/cap-ai-vector-engine-sample/application/node_modules/@sap/cds]
{
build: {
target: 'gen',
tasks: [
{ for: 'hana', src: 'db', options: { model: ['db', 'srv'] }}
]
}
}
done > wrote output to:
gen/db/data/codejam_roadshow_itinerary.txt
gen/db/package.json
gen/db/src/.hdiconfig
gen/db/src/gen/.hdiconfig
gen/db/src/gen/.hdinamespace
gen/db/src/gen/EmbeddingStorageService.DocumentChunk.hdbview
gen/db/src/gen/sap.advocates.demo.DocumentChunk.hdbtable
gen/db/src/gen/sap.advocates.demo.Files.hdbtable
gen/db/undeploy.json
build completed in 970 ms
7. cds deploy
cds deployします。
ここでもBuildしているから前ステップいらなかったっぽい。
% cds deploy --to hana:i348221-hdi
Running build
building project [/Users/i348221/Documents/repositories/cap-ai-vector-engine-sample/application], clean [true]
cds-dk [7.9.4], cds [7.9.3], compiler [4.9.4], home [/Users/i348221/Documents/repositories/cap-ai-vector-engine-sample/application/node_modules/@sap/cds]
{
build: {
target: 'gen',
tasks: [
{ for: 'hana', src: 'db', options: { model: ['db', 'srv'] }}
<中略>
Getting service key i348221-hdi-key
Binding db to Cloud Foundry managed service i348221-hdi:i348221-hdi-key with kind hana
Saving bindings to .cdsrc-private.json in profile hybrid
To run with cloud bindings use cds watch --profile hybrid
If not already done, use cds add hana to configure the project for SAP HANA.
Done.
8. .cdsrc.json 作成
ファイルapplication/.cdsrc.json
を作成します。
あまり確認できていないですが、 以下の点に注意しています。
パス | 値 | 備考 |
---|---|---|
requires -> GENERATIVE_AI_HUB->CHAT_MODEL_DEPLOYMENT_URL | v2/inference/deployments/d87a9a02df17c15c | AI Launch PadでChatモデルのDeployパスを確認して設定 |
requires -> GENERATIVE_AI_HUB->CHAT_MODEL_RESOURCE_GROUP | default | AI Coreのリソースグループ |
requires -> GENERATIVE_AI_HUB->CHAT_MODEL_API_VERSION | 2023-03-15-preview | 本当は確認・変更すべきだとコピペ元の値のまま |
requires -> GENERATIVE_AI_HUB->EMBEDDING_MODEL_DEPLOYMENT_URL | /v2/inference/deployments/d3a862d041262481 | AI Launch PadでChatモデルのDeployパスを確認して設定 |
requires -> GENERATIVE_AI_HUB->EMBEDDING_MODEL_RESOURCE_GROUP | default | AI Coreのリソースグループ |
requires -> GENERATIVE_AI_HUB->MBEDDING_MODEL_API_VERSION | 2023-05-15 | 本当は確認・変更すべきだとコピペ元の値のまま |
requires -> aicore_dest->credentials->destination | i348221-aicore | 「4.3. Destination登録」で登録したdestination名 |
{
"cdsc": {
"beta": {
"vectorType": true
}
},
"requires":{
"GENERATIVE_AI_HUB": {
"CHAT_MODEL_DESTINATION_NAME": "aicore_dest",
"CHAT_MODEL_DEPLOYMENT_URL": "v2/inference/deployments/d87a9a02df17c15c",
"CHAT_MODEL_RESOURCE_GROUP": "default",
"CHAT_MODEL_API_VERSION": "2023-03-15-preview",
"EMBEDDING_MODEL_DESTINATION_NAME": "aicore_dest",
"EMBEDDING_MODEL_DEPLOYMENT_URL": "/v2/inference/deployments/d3a862d041262481",
"EMBEDDING_MODEL_RESOURCE_GROUP": "default",
"EMBEDDING_MODEL_API_VERSION": "2023-05-15"
},
"aicore_dest": {
"kind": "rest",
"credentials": {
"destination": "i348221-aicore",
"requestTimeout": "300000"
}
}
}
}
以下からコピーしました。
9. cds watch
cds watch します。これで、hanaへもdeployされます。
% cds watch --profile hybrid
cds serve all --with-mocks --in-memory? --profile hybrid
live reload enabled for browsers
resolving cloud service bindings...
Getting service key i348221-hdi-key
Getting service key i348221-destination-key
bound db to Cloud Foundry managed service i348221-hdi:i348221-hdi-key
bound destinations to Cloud Foundry managed service i348221-destination:i348221-destination-key
<後略>
HANA DB Explorerからもテーブルが確認できます。
10. サービス実行
以下に記載のサービスを実行(ブラウザにURLを入れるだけ)。この後は省略します。