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

Document helpful procedures

Đang mở
#83 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
505
Fork
1.1k
Merge trung bình
3 ngày 13 giờ
Pull request đã merge (30 ngày)
1

Mô tả

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,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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,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)
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.