パブリックRESTプロバイダを使用したサマリーの生成
Cohere、生成AI、Google AI、Hugging Face、OpenAIまたはVertex AIによってパブリックにホストされたサードパーティのテキスト要約モデルを使用して、テキストからサマリーへの変換を実行します。
ここでは、連鎖可能ユーティリティ関数UTL_TO_SUMMARY
をコールします。
警告:
データベースの特定の機能により、たとえば、REST APIへのアクセスを容易にするJSON仕様を使用して、第三者によって個別に提供されるサービスにアクセスできる場合があります。
お客様によるこれらの機能の使用は、お客様自身の責任においてのみ行われ、お客様は、当該第三者サービスの使用に関連するあらゆる条件を遵守する責任を負います。第三者のサービスに関するその他の条件にかかわらず、お客様は、かかるデータベース機能の使用によって、そのリスクを受諾し、当該アクセスにより生じた一切の損害について、Oracleの責任または法的責任を明示的に除外することになります。
外部LLMを使用してテキスト抜粋を要約するには:
- ローカル・ユーザーとしてOracle Databaseに接続します。
- SQL*Plusに
SYS
ユーザーとしてログインし、SYSDBA
として接続します。conn sys/password as sysdba
CREATE TABLESPACE tbs1 DATAFILE 'tbs5.dbf' SIZE 20G AUTOEXTEND ON EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
SET ECHO ON SET FEEDBACK 1 SET NUMWIDTH 10 SET LINESIZE 80 SET TRIMSPOOL ON SET TAB OFF SET PAGESIZE 10000 SET LONG 10000
- ローカル・ユーザー(
docuser
)を作成し、必要な権限を付与します。DROP USER docuser cascade;
CREATE USER docuser identified by docuser DEFAULT TABLESPACE tbs1 quota unlimited on tbs1;
GRANT DB_DEVELOPER_ROLE, create credential to docuser;
- ローカル・ユーザー(
docuser
)として接続します:CONN docuser/password
- SQL*Plusに
- プロキシを設定します(存在する場合)。
EXEC UTL_HTTP.SET_PROXY('<proxy-hostname>:<proxy-port>');
DBMS_NETWORK_ACL_ADMIN
プロシージャを使用して、ホストへの接続を許可するための接続権限をdocuser
に付与します。この例では、
*
を使用して任意のホストを許可します。ただし、接続するホストを明示的に指定できます。BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => '*', ace => xs$ace_type(privilege_list => xs$name_list('connect'), principal_name => 'docuser', principal_type => xs_acl.ptype_db)); END; /
- アクセスするRESTプロバイダの資格証明を設定し、
UTL_TO_SUMMARY
をコールします。-
生成AIの使用:
ノート:
現在、生成AIでサポートされているモデルおよびサマリー・エンドポイントが廃止されたため、UTL_TO_SUMMARY
は生成AIでは機能しません。以降のリリースで使用可能になる予定です。-
DBMS_VECTOR_CHAIN.CREATE_CREDENTIAL
を実行して、OCI資格証明(OCI_CRED
)を作成および格納します。生成AIには、次の認証パラメータが必要です。{ "user_ocid" : "<user ocid>", "tenancy_ocid" : "<tenancy ocid>", "compartment_ocid": "<compartment ocid>", "private_key" : "<private key>", "fingerprint" : "<fingerprint>" }
後で、
UTL_TO_SUMMARY
コールのJSONパラメータを宣言するときに、この資格証明名を参照します。ノート:
生成された秘密キーは次のように表示されます。
(-----BEGIN RSA PRIVATE KEY----- <private key string> -----END RSA PRIVATE KEY-----
BEGIN
とEND
の行を除く)<private key string>
値を単一行または複数行として渡します。exec dbms_vector_chain.drop_credential('OCI_CRED');
declare jo json_object_t; begin jo := json_object_t(); jo.put('user_ocid','<user ocid>'); jo.put('tenancy_ocid','<tenancy ocid>'); jo.put('compartment_ocid','<compartment ocid>'); jo.put('private_key','<private key>'); jo.put('fingerprint','<fingerprint>'); dbms_vector_chain.create_credential( credential_name => 'OCI_CRED', params => json(jo.to_string)); end; /
すべての認証パラメータ値を置換します。
次に例を示します。
declare jo json_object_t; begin jo := json_object_t(); jo.put('user_ocid','ocid1.user.oc1..aabbalbbaa1112233aabbaabb1111222aa1111bb'); jo.put('tenancy_ocid','ocid1.tenancy.oc1..aaaaalbbbb1112233aaaabbaa1111222aaa111a'); jo.put('compartment_ocid','ocid1.compartment.oc1..ababalabab1112233abababab1111222aba11ab'); jo.put('private_key','AAAaaaBBB11112222333...AAA111AAABBB222aaa1a/+'); jo.put('fingerprint','01:1a:a1:aa:12:a1:12:1a:ab:12:01:ab:a1:12:ab:1a'); dbms_vector_chain.create_credential( credential_name => 'OCI_CRED', params => json(jo.to_string)); end; /
-
DBMS_VECTOR_CHAIN.UTL_TO_SUMMARY
を実行します。ここでは、cohere.command-r-16kモデルが使用されます。必要に応じて、
model
値を置き換えることができます。ノート:
生成AIでの使用がサポートされているすべてのRESTエンドポイントURLおよびモデルのリストは、「サポートされるサードパーティ・プロバイダの操作およびエンドポイント」を参照してください。-- select example var params clob; exec :params := ' { "provider" : "ocigenai", "credential_name": "OCI_CRED", "url" : "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/chat", "model" : "cohere.command-r-16k" }'; select dbms_vector_chain.utl_to_summary( 'A transaction is a logical, atomic unit of work that contains one or more SQL statements. An RDBMS must be able to group SQL statements so that they are either all committed, which means they are applied to the database, or all rolled back, which means they are undone. An illustration of the need for transactions is a funds transfer from a savings account to a checking account. The transfer consists of the following separate operations: 1. Decrease the savings account. 2. Increase the checking account. 3. Record the transaction in the transaction journal. Oracle Database guarantees that all three operations succeed or fail as a unit. For example, if a hardware failure prevents a statement in the transaction from executing, then the other statements must be rolled back. Transactions set Oracle Database apart from a file system. If you perform an atomic operation that updates several files, and if the system fails halfway through, then the files will not be consistent. In contrast, a transaction moves an Oracle database from one consistent state to another. The basic principle of a transaction is all or nothing: an atomic operation succeeds or fails as a whole.', json(:params)) from dual; -- PL/SQL example declare input clob; params clob; output clob; begin input := 'A transaction is a logical, atomic unit of work that contains one or more SQL statements. An RDBMS must be able to group SQL statements so that they are either all committed, which means they are applied to the database, or all rolled back, which means they are undone. An illustration of the need for transactions is a funds transfer from a savings account to a checking account. The transfer consists of the following separate operations: 1. Decrease the savings account. 2. Increase the checking account. 3. Record the transaction in the transaction journal. Oracle Database guarantees that all three operations succeed or fail as a unit. For example, if a hardware failure prevents a statement in the transaction from executing, then the other statements must be rolled back. Transactions set Oracle Database apart from a file system. If you perform an atomic operation that updates several files, and if the system fails halfway through, then the files will not be consistent. In contrast, a transaction moves an Oracle database from one consistent state to another. The basic principle of a transaction is all or nothing: an atomic operation succeeds or fails as a whole.'; params := ' { "provider" : "ocigenai", "credential_name": "OCI_CRED", "url" : "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/chat", "model" : "cohere.command-r-16k" }'; output := dbms_vector_chain.utl_to_summary(input, json(params)); dbms_output.put_line(output); if output is not null then dbms_lob.freetemporary(output); end if; exception when OTHERS THEN DBMS_OUTPUT.PUT_LINE (SQLERRM); DBMS_OUTPUT.PUT_LINE (SQLCODE); end; /
オプションで、RESTプロバイダ固有の追加パラメータを指定できます。次に例を示します。
{ "provider" : "ocigenai", "credential_name": "OCI_CRED", "url" : "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/chat", "model" : "cohere.command-r-16k", "length" : "MEDIUM", "format" : "PARAGRAPH", "temperature" : 1.0 }
-
-
Cohere、Google AI、Hugging Face、OpenAIおよびVertex AIの使用:
-
DBMS_VECTOR_CHAIN.CREATE_CREDENTIAL
を実行して、資格証明を作成および格納します。Cohere、Google AI、Hugging Face、OpenAIおよびVertex AIには、次の認証パラメータが必要です。
{ "access_token": "<access token>" }
後で、
UTL_TO_SUMMARY
コールのJSONパラメータを宣言するときに、この資格証明名を参照します。exec dbms_vector_chain.drop_credential('<credential name>');
declare jo json_object_t; begin jo := json_object_t(); jo.put('access_token', '<access token>'); dbms_vector_chain.create_credential( credential_name => '<credential name>', params => json(jo.to_string)); end; /
access_token
およびcredential_name
値を置き換えます。次に例を示します。declare jo json_object_t; begin jo := json_object_t(); jo.put('access_token', 'AbabA1B123aBc123AbabAb123a1a2ab'); dbms_vector_chain.create_credential( credential_name => 'HF_CRED', params => json(jo.to_string)); end; /
-
DBMS_VECTOR_CHAIN.UTL_TO_SUMMARY
を実行します。-- select example var params clob; exec :params := ' { "provider": "<REST provider>", "credential_name": "<credential name>", "url": "<REST endpoint URL for text summarization service>", "model": "<REST provider text summarization model name>" }'; select dbms_vector_chain.utl_to_summary( 'A transaction is a logical, atomic unit of work that contains one or more SQL statements. An RDBMS must be able to group SQL statements so that they are either all committed, which means they are applied to the database, or all rolled back, which means they are undone. An illustration of the need for transactions is a funds transfer from a savings account to a checking account. The transfer consists of the following separate operations: 1. Decrease the savings account. 2. Increase the checking account. 3. Record the transaction in the transaction journal. Oracle Database guarantees that all three operations succeed or fail as a unit. For example, if a hardware failure prevents a statement in the transaction from executing, then the other statements must be rolled back. Transactions set Oracle Database apart from a file system. If you perform an atomic operation that updates several files, and if the system fails halfway through, then the files will not be consistent. In contrast, a transaction moves an Oracle database from one consistent state to another. The basic principle of a transaction is "all or nothing": an atomic operation succeeds or fails as a whole.', json(:params)) from dual; -- PL/SQL example declare input clob; params clob; output clob; begin input := 'A transaction is a logical, atomic unit of work that contains one or more SQL statements. An RDBMS must be able to group SQL statements so that they are either all committed, which means they are applied to the database, or all rolled back, which means they are undone. An illustration of the need for transactions is a funds transfer from a savings account to a checking account. The transfer consists of the following separate operations: 1. Decrease the savings account. 2. Increase the checking account. 3. Record the transaction in the transaction journal. Oracle Database guarantees that all three operations succeed or fail as a unit. For example, if a hardware failure prevents a statement in the transaction from executing, then the other statements must be rolled back. Transactions set Oracle Database apart from a file system. If you perform an atomic operation that updates several files, and if the system fails halfway through, then the files will not be consistent. In contrast, a transaction moves an Oracle database from one consistent state to another. The basic principle of a transaction is "all or nothing": an atomic operation succeeds or fails as a whole.'; params := ' { "provider": "<REST provider>", "credential_name": "<credential name>", "url": "<REST endpoint URL for text summarization service>", "model": "<REST provider text summarization model name>" }'; output := dbms_vector_chain.utl_to_summary(input, json(params)); dbms_output.put_line(output); if output is not null then dbms_lob.freetemporary(output); end if; exception when OTHERS THEN DBMS_OUTPUT.PUT_LINE (SQLERRM); DBMS_OUTPUT.PUT_LINE (SQLCODE); end; /
ノート:
サポートされているすべてのRESTエンドポイントURLのリストは、「サポートされているサードパーティ・プロバイダの操作およびエンドポイント」を参照してください。provider
、credential_name
、url
およびmodel
を独自の値に置き換えます。オプションで、追加のRESTプロバイダ・パラメータを指定できます。これを次の例に示します:Cohereの例:{ "provider" : "cohere", "credential_name" : "COHERE_CRED", "url" : "https://api.cohere.ai/v1/chat", "model" : "command", "length" : "medium", "format" : "paragraph", "temperature" : 1.0 }
Google AIの例:{ "provider" : "googleai", "credential_name" : "GOOGLEAI_CRED", "url" : "https://generativelanguage.googleapis.com/v1beta/models/", "model" : "gemini-pro:generateContent", "generation_config": { "temperature" : 0.9, "topP" : 1, "candidateCount" : 1, "maxOutputTokens": 256 } }
Hugging Faceの例:{ "provider" : "huggingface", "credential_name" : "HF_CRED", "url" : "https://api-inference.huggingface.co/models/", "model" : "facebook/bart-large-cnn" }
OpenAIの例:{ "provider" : "openai", "credential_name" : "OPENAI_CRED", "url" : "https://api.openai.com/v1/chat/completions", "model" : "gpt-4o-mini", "max_tokens" : 256, "temperature" : 1.0 }
Vertex AIの例:{ "provider" : "vertexai", "credential_name" : "VERTEXAI_CRED", "url" : "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/publishers/google/models/", "model" : "gemini-1.0-pro:generateContent", "generation_config": { "temperature" : 0.9, "topP" : 1, "candidateCount" : 1, "maxOutputTokens": 256 } }
-
生成されたサマリーは次のように表示されます:
A transaction is a logical unit of work that groups one or more SQL statements that must be executed as a unit, with all statements succeeding, or all statements being rolled back. Transactions are a fundamental concept in relational database management systems (RDBMS), and Oracle Database is specifically designed to manage transactions, ensuring database consistency and integrity. Transactions differ from file systems in that they maintain atomicity, ensuring that all related operations succeed or fail as a whole, maintaining database consistency regardless of intermittent failures. Transactions move a database from one consistent state to another, and the fundamental principle is that a transaction is committed or rolled back as a whole, upholding the "all or nothing" principle. PL/SQL procedure successfully completed.
-
親トピック: サマリーの生成