Functions have been implemented:
Minimum installation requirements: SQL Server 2022, Visual Studio 2022 (SSDT needs to be installed)
use SQLRAG
sp_configure ' show advanced options ' , 1 ;
RECONFIGURE;
sp_configure ' clr enabled ' , 1 ;
RECONFIGURE; There are several ways to install:
If you want to use OpenaiFunction, the previous approach was to enter your actual OPENAI_API_KEY in OpenaiFunction.cs. This approach cannot ensure the security of API KEY. In this version, I added the dbo.EncryptedKeys data table to the SqlRAG database, where the KeyValue part is encrypted through credentials. It looks complicated, but I have already processed the automatic call part. The developer only needs to encrypt the API KEY and write it into the data table through the following SQL syntax.
use SQLRAG
Declare @cleartext varchar ( 512 ) = ' sk-輸入你的OPENAI_API_KEYAPI KEY '
Declare @encrytext varbinary( 4000 ) = EncryptByCert(Cert_ID( ' SqlRAGCertificate ' ), @cleartext)
INSERT INTO [SQLRAG].[dbo].[EncryptedKeys]
VALUES ( N ' OPENAI_API_KEY ' , N '調用OPENAI所用之API KEY ' ,@encrytext ); Then, you need to decrypt it by explicitly declaring which credential and the corresponding password:
DecryptByCert(Cert_ID( ' SqlRAGCertificate ' ), EncryptByCert(Cert_ID( ' SqlRAGCertificate ' ), @cleartext) , ' P@ssw0rd ' )
If you are an Azure Openai Service user, you need to encrypt the API key and endpoint and save it in
use SQLRAG
Declare @cleartext varchar ( 512 ) = ' *** '
Declare @encrytext varbinary( 4000 ) = EncryptByCert(Cert_ID( ' SqlRAGCertificate ' ), @cleartext)
Declare @cleartext2 varchar ( 512 ) = ' https://***.openai.azure.com '
Declare @encrytext2 varbinary( 4000 ) = EncryptByCert(Cert_ID( ' SqlRAGCertificate ' ), @cleartext2)
Declare @cleartext3 varchar ( 512 ) = ' *** '
Declare @encrytext3 varbinary( 4000 ) = EncryptByCert(Cert_ID( ' SqlRAGCertificate ' ), @cleartext3)
INSERT INTO [SQLRAG].[dbo].[EncryptedKeys]
VALUES ( N ' AZURE_OPENAI_API_KEY ' , N '調用Azure Openai Service 所用之API KEY ' ,@encrytext );
INSERT INTO [SQLRAG].[dbo].[EncryptedKeys]
VALUES ( N ' AZURE_OPENAI_ENDPOINT ' , N '調用Azure Openai Service 所用之endpoint ' ,@encrytext2 );
INSERT INTO [SQLRAG].[dbo].[EncryptedKeys]
VALUES ( N ' OPENAI_API_VERSION ' , N '調用Azure Openai Service 所用之API Version ' ,@encrytext3 );

