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

Document helpful procedures

Abierto
#83 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
505
Forks
1.1k
Merge medio
3 d 13 h
PR fusionados (30 d)
1

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.