Azure-Samples / Azure-Samples/rag-postgres-openai-python

Document helpful procedures

オープン
#83 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
505
フォーク
1.1k
平均マージ
3日 13時間
マージ済み PR(30日)
1

説明

From Emmanuel:

```
GRANT pg_read_all_data TO YOURACCOUNT;
GRANT pg_write_all_data TO YOURACCOUNT;
enable the Azure AI extension
[https://learn.microsoft.com/en-gb/azure/postgresql/flexible-server/generative-ai-azure-overview#enable-the-azure_ai-extension](https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Flearn.microsoft.com%2Fen-gb%2Fazure%2Fpostgresql%2Fflexible-server%2Fgenerative-ai-azure-overview%23enable-the-azure_ai-extension&data=05%7C02%7Cedeletang%40microsoft.com%7C32817772f3724712c73008dcd6753f4d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638621046309783323%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=uSpg0f0yoTCtd9X7u0jOcvf7tawQqng%2FDXHq%2Fvg%2FprQ%3D&reserved=0)

CREATE EXTENSION azure_ai;
CREATE EXTENSION pgvector;

connect to your Open AI enpoint
select azure_ai.set_setting('azure_openai.endpoint','https://.openai.azure.com');
select azure_ai.set_setting('azure_openai.subscription_key', '');

to simplify the insert of data
create a function for nomic insert part :

CREATE FUNCTION nomic() RETURNS Vector AS $$
BEGIN
RETURN '[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]';
END;
$$ LANGUAGE plpgsql;

select nomic()

create a function get the id

CREATE FUNCTION id1() RETURNS INTEGER AS $$
DECLARE passed iNTEGER;
BEGIN
SELECT MAX(id)+1 FROM public.items INTO passed;
RETURN passed;
END;
$$ LANGUAGE plpgsql;

select id1()

create a procedure to insert the data with your model name , for me 'text-embedding-ada-002'

CREATE PROCEDURE insert_data(type TEXT, brand TEXT, name TEXT , description TEXT , price INTEGER)
LANGUAGE SQL
AS $$

INSERT INTO items (id, type, brand,name,description, price,embedding_ada002,embedding_nomic)
VALUES(id1(),type,brand,name ,description,price, azure_openai.create_embeddings('text-embedding-ada-002', description),nomic());
$$;

call the procedure to insert your data
ex :
Call insert_data('Chablis','Bourgogne','chablisienne','la chablisienne est un producteur de chablis qui a plusieurs cru',15)
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。