Skip to content

Commit 2a013d8

Browse files
Normalise environment variables (#144)
1 parent 500c130 commit 2a013d8

File tree

18 files changed

+92
-47
lines changed

18 files changed

+92
-47
lines changed

deploy_ai_search/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# AI Search Indexing Pre-built Index Setup
22

3-
The associated scripts in this portion of the repository contains pre-built scripts to deploy the skillset with Azure Document Intelligence.
3+
The associated scripts in this portion of the repository contains pre-built scripts to deploy the skillsets needed for both Text2SQL and Image Processing.
44

5-
## Steps for Rag Documents Index Deployment (For Unstructured RAG)
5+
## Steps for Rag Documents Index Deployment (For Image Processing)
66

77
1. Update `.env` file with the associated values. Not all values are required dependent on whether you are using System / User Assigned Identities or a Key based authentication.
88
2. Adjust `rag_documents.py` with any changes to the index / indexer. The `get_skills()` method implements the skills pipeline. Make any adjustments here in the skills needed to enrich the data source.
@@ -13,7 +13,7 @@ The associated scripts in this portion of the repository contains pre-built scri
1313
- `rebuild`. Whether to delete and rebuild the index.
1414
- `suffix`. Optional parameter that will apply a suffix onto the deployed index and indexer. This is useful if you want deploy a test version, before overwriting the main version.
1515

16-
## Steps for Text2SQL Index Deployment (For Structured RAG)
16+
## Steps for Text2SQL Index Deployment (For Text2SQL)
1717

1818
### Schema Store Index
1919

text_2_sql/.env.example

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Environment variables for Text2SQL
22
IdentityType=<identityType> # system_assigned or user_assigned or key
33

4+
Text2Sql__DatabaseEngine=<DatabaseEngine> # TSQL or PostgreSQL or Snowflake or Databricks
5+
Text2Sql__UseQueryCache=<Determines if the Query Cache will be used to speed up query generation. Defaults to True.> # True or False
6+
Text2Sql__PreRunQueryCache=<Determines if the results from the Query Cache will be pre-run to speed up answer generation. Defaults to True.> # True or False
7+
Text2Sql__UseColumnValueStore=<Determines if the Column Value Store will be used for schema selection Defaults to True.> # True or False
8+
49
# Open AI Connection Details
510
OpenAI__CompletionDeployment=<openAICompletionDeploymentId. Used for data dictionary creator>
611
OpenAI__MiniCompletionDeployment=<OpenAI__MiniCompletionDeploymentId. Used for agentic text2sql>
@@ -17,17 +22,20 @@ AIService__AzureSearchOptions__Text2SqlQueryCache__Index=<Query cache index name
1722
AIService__AzureSearchOptions__Text2SqlQueryCache__SemanticConfig=<Query cache semantic config. Default is created as "text-2-sql-query-cache-semantic-config">
1823
AIService__AzureSearchOptions__Text2SqlColumnValueStore__Index=<Column value store index name. Default is created as "text-2-sql-column-value-store-index">
1924

20-
# All SQL Engine specific connection details
21-
Text2Sql__DatabaseName=<databaseName>
25+
# TSQL
26+
Text2Sql__Tsql__ConnectionString=<Tsql databaseConnectionString if using Tsql Data Source>
27+
Text2Sql__Tsql__Database=<Tsql database if using Tsql Data Source>
2228

23-
# TSQL or PostgreSQL Specific Connection Details
24-
Text2Sql__DatabaseConnectionString=<databaseConnectionString>
29+
# PostgreSQL Specific Connection Details
30+
Text2Sql__Postgresql__ConnectionString=<Postgresql databaseConnectionString if using Postgresql Data Source>
31+
Text2Sql__Postgresql__Database=<Postgresql database if using Postgresql Data Source>
2532

2633
# Snowflake Specific Connection Details
2734
Text2Sql__Snowflake__User=<snowflakeUser if using Snowflake Data Source>
2835
Text2Sql__Snowflake__Password=<snowflakePassword if using Snowflake Data Source>
2936
Text2Sql__Snowflake__Account=<snowflakeAccount if using Snowflake Data Source>
3037
Text2Sql__Snowflake__Warehouse=<snowflakeWarehouse if using Snowflake Data Source>
38+
Text2Sql__Snowflake__Database=<snowflakeDatabase if using Snowflake Data Source>
3139

3240
# Databricks Specific Connection Details
3341
Text2Sql__Databricks__Catalog=<databricksCatalog if using Databricks Data Source with Unity Catalog>

text_2_sql/GETTING_STARTED.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
To get started, perform the following steps:
44

5+
**Execute the following commands in the `deploy_ai_search` directory:**
6+
57
1. Setup Azure OpenAI in your subscription with **gpt-4o-mini** & an embedding model, alongside a SQL Server sample database, AI Search and a storage account.
6-
2. Clone this repository and deploy the AI Search text2sql indexes from `deploy_ai_search`.
7-
3. Run `uv sync` within the text_2_sql directory to install dependencies.
8+
2. Create your `.env` file based on the provided sample `deploy_ai_search/.env.example`. Place this file in the same place in `deploy_ai_search/.env`.
9+
3. Clone this repository and deploy the AI Search text2sql indexes from `deploy_ai_search`. See the instructions in the **Steps for Text2SQL Index Deployment (For Structured RAG)** section of the `deploy_ai_search/README.md`.
10+
11+
**Execute the following commands in the `text_2_sql_core` directory:**
12+
13+
4. Create your `.env` file based on the provided sample `text_2_sql/.env.example`. Place this file in the same place in `text_2_sql/.env`.
14+
5. Run `uv sync` within the text_2_sql directory to install dependencies.
15+
- Install the optional dependencies if you need a database connector other than TSQL. `uv sync --extra <DATABASE ENGINE>`
16+
- See the supported connectors in `text_2_sql_core/src/text_2_sql_core/connectors`.
17+
6. Create your `.env` file based on the provided sample `text_2_sql/.env.example`. Place this file in the same place in `text_2_sql/.env`.
18+
7. Generate a data dictionary for your target server using the instructions in the **Running** section of the `data_dictionary/README.md`.
19+
8. Upload these generated data dictionaries files to the relevant containers in your storage account. Wait for them to be automatically indexed with the included skillsets.
20+
21+
**Execute the following commands in the `autogen` directory:**
22+
23+
9. Run `uv sync` within the text_2_sql directory to install dependencies.
824
- Install the optional dependencies if you need a database connector other than TSQL. `uv sync --extra <DATABASE ENGINE>`
925
- See the supported connectors in `text_2_sql_core/src/text_2_sql_core/connectors`.
10-
4. Create your `.env` file based on the provided sample `.env.example`. Place this file in the same place as the `.env.example`.
11-
5. Generate a data dictionary for your target server using the instructions in the **Running** section of the `data_dictionary/README.md`.
12-
6. Upload these generated data dictionaries files to the relevant containers in your storage account. Wait for them to be automatically indexed with the included skillsets.
13-
7. Navigate to `autogen` directory to view the AutoGen implementation. Follow the steps in `Iteration 5 - Agentic Vector Based Text2SQL.ipynb` to get started.
26+
10. Navigate to `autogen` directory to view the AutoGen implementation. Follow the steps in `Iteration 5 - Agentic Vector Based Text2SQL.ipynb` to get started.

text_2_sql/__init__.py

Whitespace-only changes.

text_2_sql/autogen/evaluate_autogen_text2sql.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@
215215
" \n",
216216
" # Update database connection string for current database\n",
217217
" db_path = DATABASE_DIR / db_id / f\"{db_id}.sqlite\"\n",
218-
" os.environ[\"Text2Sql__DatabaseConnectionString\"] = str(db_path)\n",
219-
" os.environ[\"Text2Sql__DatabaseName\"] = db_id\n",
218+
" os.environ[\"Text2Sql__Tsql__ConnectionString\"] = str(db_path)\n",
219+
" os.environ[\"Text2Sql__Database\"] = db_id\n",
220220
" \n",
221221
" sql = await generate_sql(question)\n",
222222
" predictions.append(f\"{sql}\\t{db_id}\")\n",

text_2_sql/autogen/src/autogen_text_2_sql/custom_agents/parallel_query_solving_agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ async def consume_inner_messages_from_agentic_flow(
219219

220220
# Add database connection info to injected parameters
221221
query_params = injected_parameters.copy() if injected_parameters else {}
222-
if "Text2Sql__DatabaseConnectionString" in os.environ:
222+
if "Text2Sql__Tsql__ConnectionString" in os.environ:
223223
query_params["database_connection_string"] = os.environ[
224-
"Text2Sql__DatabaseConnectionString"
224+
"Text2Sql__Tsql__ConnectionString"
225225
]
226-
if "Text2Sql__DatabaseName" in os.environ:
227-
query_params["database_name"] = os.environ["Text2Sql__DatabaseName"]
226+
if "Text2Sql__Tsql__Database" in os.environ:
227+
query_params["database_name"] = os.environ["Text2Sql__Tsql__Database"]
228228

229229
# Launch tasks for each sub-query
230230
inner_solving_generators.append(

text_2_sql/autogen/src/autogen_text_2_sql/inner_autogen_text_2_sql.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,27 @@ def __init__(self, **kwargs: dict):
4545
self.set_mode()
4646

4747
# Store original environment variables
48-
self.original_db_conn = os.environ.get("Text2Sql__DatabaseConnectionString")
49-
self.original_db_name = os.environ.get("Text2Sql__DatabaseName")
48+
self.original_db_conn = os.environ.get("Text2Sql__Tsql__ConnectionString")
49+
self.original_db_name = os.environ.get("Text2Sql__Tsql__Database")
5050

5151
def _update_environment(self, injected_parameters: dict = None):
5252
"""Update environment variables with injected parameters."""
5353
if injected_parameters:
5454
if "database_connection_string" in injected_parameters:
55-
os.environ["Text2Sql__DatabaseConnectionString"] = injected_parameters[
55+
os.environ["Text2Sql__Tsql__ConnectionString"] = injected_parameters[
5656
"database_connection_string"
5757
]
5858
if "database_name" in injected_parameters:
59-
os.environ["Text2Sql__DatabaseName"] = injected_parameters[
59+
os.environ["Text2Sql__Tsql__Database"] = injected_parameters[
6060
"database_name"
6161
]
6262

6363
def _restore_environment(self):
6464
"""Restore original environment variables."""
6565
if self.original_db_conn:
66-
os.environ["Text2Sql__DatabaseConnectionString"] = self.original_db_conn
66+
os.environ["Text2Sql__Tsql__ConnectionString"] = self.original_db_conn
6767
if self.original_db_name:
68-
os.environ["Text2Sql__DatabaseName"] = self.original_db_name
68+
os.environ["Text2Sql__Tsql__Database"] = self.original_db_name
6969

7070
def set_mode(self):
7171
"""Set the mode of the plugin based on the environment variables."""

text_2_sql/data_dictionary/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ If there is no pre-built script for your database engine, take one of the above
224224

225225
## Running
226226

227-
1. Create your `.env` file based on the provided sample `.env.example`. Place this file in the same place as the `.env.example`.
227+
To generate a data dictionary, perform the following steps:
228+
229+
1. Create your `.env` file based on the provided sample `text_2_sql/.env.example`. Place this file in the same place in `text_2_sql/.env`.
230+
231+
**Execute the following commands in the `text_2_sql_core` directory:**
228232
2. Package and install the `text_2_sql_core` library. See [build](https://docs.astral.sh/uv/concepts/projects/build/) if you want to build as a wheel and install on an agent. Or you can run from within a `uv` environment and skip packaging.
229233
- Install the optional dependencies if you need a database connector other than TSQL. `uv sync --extra <DATABASE ENGINE>`
230234
3. Run `data_dictionary <DATABASE ENGINE>`

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/postgresql_sql.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def __init__(self):
1616

1717
self.database_engine = DatabaseEngine.POSTGRESQL
1818

19+
@property
20+
def engine_specific_rules(self) -> str:
21+
"""Get the engine specific rules."""
22+
return ""
23+
1924
@property
2025
def engine_specific_fields(self) -> list[str]:
2126
"""Get the engine specific fields."""
@@ -61,10 +66,10 @@ async def query_execution(
6166
"""
6267
logging.info(f"Running query: {sql_query}")
6368
results = []
64-
connection_string = os.environ["Text2Sql__DatabaseConnectionString"]
69+
connection_string = os.environ["Text2Sql__Postgresql__ConnectionString"]
6570

6671
# Establish an asynchronous connection to the PostgreSQL database
67-
async with psycopg.AsyncConnection.connect(connection_string) as conn:
72+
async with await psycopg.AsyncConnection.connect(connection_string) as conn:
6873
# Create an asynchronous cursor
6974
async with conn.cursor() as cursor:
7075
await cursor.execute(sql_query)

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/snowflake_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def query_execution(
100100
password=os.environ["Text2Sql__Snowflake__Password"],
101101
account=os.environ["Text2Sql__Snowflake__Account"],
102102
warehouse=os.environ["Text2Sql__Snowflake__Warehouse"],
103-
database=os.environ["Text2Sql__DatabaseName"],
103+
database=os.environ["Text2Sql__Snowflake__Database"],
104104
)
105105

106106
try:

0 commit comments

Comments
 (0)