Skip to content

Commit c725d7e

Browse files
committed
Update models
1 parent eb92ecb commit c725d7e

File tree

3 files changed

+68
-38
lines changed

3 files changed

+68
-38
lines changed

text_2_sql/text_2_sql_core/src/text_2_sql_core/connectors/ai_search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ async def get_entity_schemas(
188188
"AIService__AzureSearchOptions__Text2SqlSchemaStore__SemanticConfig"
189189
],
190190
top=3,
191+
minimum_score=1.5,
191192
)
192193

193194
fqn_to_trim = ".".join(stringified_engine_specific_fields)

text_2_sql/text_2_sql_core/src/text_2_sql_core/payloads/interaction_payloads.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class DismabiguationRequest(InteractionPayloadBase):
6060
def __init__(self, **kwargs):
6161
super().__init__(**kwargs)
6262

63-
self.body = self.Body(**kwargs)
63+
body_kwargs = kwargs.get("body", kwargs)
64+
65+
self.body = self.Body(**body_kwargs)
6466

6567

6668
class AnswerWithSourcesPayload(InteractionPayloadBase):
@@ -86,7 +88,9 @@ class Source(InteractionPayloadBase):
8688
def __init__(self, **kwargs):
8789
super().__init__(**kwargs)
8890

89-
self.body = self.Body(**kwargs)
91+
body_kwargs = kwargs.get("body", kwargs)
92+
93+
self.body = self.Body(**body_kwargs)
9094

9195

9296
class ProcessingUpdatePayload(InteractionPayloadBase):
@@ -105,7 +109,9 @@ class Body(InteractionPayloadBase):
105109
def __init__(self, **kwargs):
106110
super().__init__(**kwargs)
107111

108-
self.body = self.Body(**kwargs)
112+
body_kwargs = kwargs.get("body", kwargs)
113+
114+
self.body = self.Body(**body_kwargs)
109115

110116

111117
class UserMessagePayload(InteractionPayloadBase):
@@ -123,8 +129,15 @@ def add_defaults(cls, values):
123129
"datetime": datetime.now().strftime("%d/%m/%Y, %H:%M:%S"),
124130
"unix_timestamp": int(datetime.now().timestamp()),
125131
}
126-
injected = values.get("injected_parameters", {})
127-
values["injected_parameters"] = {**defaults, **injected}
132+
injected = values.get("injected_parameters", None)
133+
134+
if injected is None:
135+
injected_by_alias = values.get("injectedParameters", {})
136+
else:
137+
injected_by_alias = injected
138+
del values["injected_parameters"]
139+
140+
values["injectedParameters"] = {**defaults, **injected_by_alias}
128141
return values
129142

130143
payload_type: Literal[PayloadType.USER_MESSAGE] = Field(
@@ -138,7 +151,9 @@ def add_defaults(cls, values):
138151
def __init__(self, **kwargs):
139152
super().__init__(**kwargs)
140153

141-
self.body = self.Body(**kwargs)
154+
body_kwargs = kwargs.get("body", kwargs)
155+
156+
self.body = self.Body(**body_kwargs)
142157

143158

144159
class InteractionPayload(RootModel):

text_2_sql/text_2_sql_core/src/text_2_sql_core/prompts/disambiguation_and_sql_query_generation_agent.yaml

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ system_message:
77
You are a helpful AI Assistant specializing in disambiguating questions about {{ use_case }} and mapping them to the relevant columns and schemas in the database.
88
Your job is to create clear mappings between the user's intent and the available database schema.
99
If all mappings are clear, generate {{ target_engine }} compliant SQL query based on the mappings.
10+
If the mappings are ambiguous or there are no possible schemas, request disambiguation from the user by asking them to rephrase the question or to answer your own question.
1011
</role_and_objective>
1112
1213
<key_concepts>
@@ -45,7 +46,8 @@ system_message:
4546
- Handle simple WHERE conditions
4647
4748
2. For Filter Conditions:
48-
- Map text filters to appropriate columns
49+
- Map text filters to appropriate columns.
50+
- If there is no clear mapping or competing values for a filter, request disambiguation.
4951
- Handle numeric comparisons correctly
5052
- Process date/time conditions
5153
- Consider multiple filter conditions
@@ -148,39 +150,51 @@ system_message:
148150
Remember: Focus on correctness first, then optimize if needed.
149151
</sql_query_generation_rules>
150152
153+
<dismabiguation_rules>
154+
When disambiguating the user's question, follow these rules:
155+
- If the schemas contain no reference to the input data or you believe the database doesn't contain it, generate a dismagiuation request that explains to the user you don't have access to that info, and requests that they should rephrase the question. Do not provide them any user choices. Only ask for a single disambiguation request for this case.
156+
- If there are multiple possible mappings for a filter with a high probability of being correct, request disambiguation from the user. You can ask the user to choose from the possible options and answer multiple disambiguation requests in this case.
157+
- If the question is unclear or ambiguous, ask the user to rephrase or provide more context. Only ask for a single disambiguation request for this case.
158+
- Always provide clear and concise options for the user to choose from. These choices should reflect the possible mappings based on the database schemas and columns in a user friendly way.
159+
160+
REMEMBER: You will use the result of this disambiguation request next time to generate the SQL query. Make sure it will provide you with the necessary information to do so.
161+
</dismabiguation_rules>
162+
151163
<output_format>
152-
If all mappings are clear:
153-
{
154-
\"filter_mapping\": {
155-
\"<filter_term>\": [{
156-
\"column\": \"<column_name>\",
157-
\"filter_value\": \"<value>\"
158-
}]
159-
},
160-
\"aggregation_mapping\": {
161-
\"<aggregation_term>\": {
162-
\"table\": \"<table_name>\", // For simple counts
163-
\"measure_column\": \"<column_name>\", // For other aggregations
164-
\"aggregation_type\": \"<type>\",
165-
\"distinct\": true/false, // Optional
166-
\"group_by_column\": \"<column_name>\" // Optional
167-
}
168-
}
169-
}
170-
171-
If disambiguation needed:
172-
{
173-
\"disambiguation_requests\": [
174-
{
175-
\"agent_question\": \"<specific_question>\",
176-
\"user_choices\": [\"<choice1>\", \"<choice2>\"]
164+
If all mappings are clear:
165+
{
166+
\"filter_mapping\": {
167+
\"<filter_term>\": [{
168+
\"column\": \"<column_name>\",
169+
\"filter_value\": \"<value>\"
170+
}]
177171
},
178-
{
179-
\"agent_question\": \"<specific_question>\",
180-
\"user_choices\": [\"<choice1>\", \"<choice2>\"]
172+
\"aggregation_mapping\": {
173+
\"<aggregation_term>\": {
174+
\"table\": \"<table_name>\", // For simple counts
175+
\"measure_column\": \"<column_name>\", // For other aggregations
176+
\"aggregation_type\": \"<type>\",
177+
\"distinct\": true/false, // Optional
178+
\"group_by_column\": \"<column_name>\" // Optional
179+
}
181180
}
182-
]
183-
}
184-
TERMINATE
181+
}
182+
183+
If disambiguation needed or no schemas could possibly match:
184+
{
185+
\"disambiguation_requests\": [
186+
{
187+
\"agent_question\": \"<specific_question>\",
188+
\"user_choices\": [\"<choice1>\", \"<choice2>\"]
189+
},
190+
{
191+
\"agent_question\": \"<specific_question>\",
192+
\"user_choices\": [\"<choice1>\", \"<choice2>\"]
193+
}
194+
]
195+
}
196+
User choices should be populated with matching options from the user's question e.g. column names, table names, filter values, etc.
197+
If you are asking the user to rephrase the question, set the user_choices to an empty list.
198+
TERMINATE
185199
</output_format>
186200
"

0 commit comments

Comments
 (0)