You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-9Lines changed: 23 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,15 @@
3
3
[](https://codespaces.new/Azure-Samples/rag-postgres-openai-python)
4
4
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/rag-postgres-openai-python)
5
5
6
-
This project creates a web-based chat application with an API backend that can use OpenAI chat models to answer questions about the items in a PostgreSQL database table. The frontend is built with React and FluentUI, while the backend is written with Python and FastAPI.
6
+
This project creates a web-based chat application with an API backend that can use OpenAI chat models to answer questions about the rows in a PostgreSQL database table. The frontend is built with React and FluentUI, while the backend is written with Python and FastAPI.
7
7
8
8
This project is designed for deployment to Azure using [the Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/), hosting the app on Azure Container Apps, the database in Azure PostgreSQL Flexible Server, and the models in Azure OpenAI.
9
9
10
10
*[Features](#features)
11
11
*[Getting started](#getting-started)
12
-
*[GitHub Codespaces](#github-codespaces)
13
-
*[VS Code Dev Containers](#vs-code-dev-containers)
14
-
*[Local environment](#local-environment)
12
+
*[GitHub Codespaces](#github-codespaces)
13
+
*[VS Code Dev Containers](#vs-code-dev-containers)
14
+
*[Local environment](#local-environment)
15
15
*[Deployment](#deployment)
16
16
*[Local development](#local-development)
17
17
*[Costs](#costs)
@@ -27,7 +27,13 @@ This project provides the following features:
27
27
* OpenAI function calling to optionally convert user queries into query filter conditions, such as turning "Climbing gear cheaper than $30?" into "WHERE price < 30".
28
28
* Conversion of user queries into vectors using the OpenAI embedding API.
29
29
30
-

30
+

31
+
32
+
## Architecture diagram
33
+
34
+
The deployed app uses a user-assigned managed identity to authenticate to Azure services, and stores logs in Log Analytics.
Copy file name to clipboardExpand all lines: docs/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ page_type: sample
16
16
urlFragment: rag-postgres-openai-python
17
17
---
18
18
19
-
This project creates a web-based chat application with an API backend that can use OpenAI chat models to answer questions about the items in a PostgreSQL database table. The frontend is built with React and FluentUI, while the backend is written with Python and FastAPI.
19
+
This project creates a web-based chat application with an API backend that can use OpenAI chat models to answer questions about the rows in a PostgreSQL database table. The frontend is built with React and FluentUI, while the backend is written with Python and FastAPI.
20
20
21
21
This project is designed for deployment to Azure using [the Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/), hosting the app on Azure Container Apps, the database in Azure PostgreSQL Flexible Server, and the models in Azure OpenAI.
This guide shows you how to bring in a table with a different schema than the sample table.
4
+
For a full example of code changes needed, check out [this branch](https://github.com/Azure-Samples/rag-postgres-openai-python/compare/main...otherdata).
5
+
6
+
## Define the table schema
7
+
8
+
1. Update seed_data.json file with the new data
9
+
2. Update the SQLAlchemy models in postgres_models.py to reflect the new schema
That script will use whatever OpenAI host is defined in the `.env` file.
30
+
You may want to run it twice for multiple models, once for Azure OpenAI embedding model and another for Ollama embedding model. Change `OPENAI_EMBED_HOST` between runs.
31
+
32
+
## Add the seed data to the database
33
+
34
+
Now that you have the new table schema and `seed_data.json` populated with embeddings, you can add the seed data to the database:
3. Update the question answering prompt at `src/backend/fastapi_app/prompts/answer.txt` to reflect the new domain.
43
+
4. Update the function calling definition in `src/backend/fastapi_app/query_rewriter.py` to reflect the new schema and domain. Replace the `brand_filter` and `price_filter` with any filters that are relevant to your new schema.
44
+
5. Update the query rewriting prompt at `src/backend/fastapi_app/prompts/query.txt` to reflect the new domain and filters.
45
+
6. Update the query rewriting examples at `src/backend/fastapi_app/prompts/query_fewshots.json` to match the new domain and filters.
46
+
47
+
## Update the API
48
+
49
+
The FastAPI routes use type annotations to define the schema of the data that they accept and return, so you'll need to update the API to reflect the new schema.
50
+
51
+
1. Modify `ItemPublic`in`src/backend/fastapi_app/api_models.py` to reflect the new schema.
52
+
2. Modify `RAGContext`if your schema uses a string ID instead of integer ID.
53
+
54
+
## Update the frontend
55
+
56
+
1. Modify the Answer component in`src/frontend/src/components/Answer/Answer.tsx` to display the desired fields from the new schema.
57
+
2. Modify the examples in`/workspace/src/frontend/src/components/Example/ExampleList.tsx` to examples for the new domain.
Copy file name to clipboardExpand all lines: docs/deploy_existing.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
-
# Deploying with existing Azure resources
1
+
# RAG on PostgreSQL: Deploying with existing Azure resources
2
2
3
3
If you already have existing Azure resources, or if you want to specify the exact name of new Azure Resource, you can do so by setting `azd` environment values.
4
4
You should set these values before running `azd up`. Once you've set them, return to the [deployment steps](../README.md#deployment).
0 commit comments