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

Document helpful procedures

Ouverte
#83 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
505
Forks
1.1k
Merge moyen
3 j 13 h
PR mergées (30 j)
1

Description

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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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]';
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)
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.