refs #739: document DB-owned task and few-shot policy
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
-- STD-25 is a period AU metric, not the daily AU_FLAG metric.
|
||||
-- Keep the evaluation evidence explicit so the LLM judge accepts the valid
|
||||
-- weekly result shape produced by the NL2SQL tool.
|
||||
|
||||
UPDATE sg_ai_qa_question
|
||||
SET expected_focus = 'Weekly AU: use one as-of snapshot (BASE_DT=2026-07-15), '
|
||||
|| 'count DISTINCT GUID whose LAST_CONN_DT is in the inclusive seven-day window '
|
||||
|| '(2026-07-09 through 2026-07-15), with STD_USER_YN=''Y'' and EXPT_USER_YN=''N''. '
|
||||
|| 'This is one aggregate result, not daily rows. Do not substitute daily AU_FLAG=1 for the period definition.',
|
||||
baseline_sql = TO_CLOB('SELECT COUNT(DISTINCT u."GUID") AS "RECENT_7DAY_AU"' || CHR(10)
|
||||
|| 'FROM "SGMP_POC"."CZN_COMN_USER_MST" u' || CHR(10)
|
||||
|| 'WHERE u."BASE_DT" = DATE ''2026-07-15''' || CHR(10)
|
||||
|| ' AND u."LAST_CONN_DT" BETWEEN DATE ''2026-07-09'' AND DATE ''2026-07-15''' || CHR(10)
|
||||
|| ' AND u."STD_USER_YN" = ''Y''' || CHR(10)
|
||||
|| ' AND u."EXPT_USER_YN" = ''N'''),
|
||||
baseline_answer = 'RECENT_7DAY_AU=0',
|
||||
evaluation_rule_json = '{"required_sql_terms":["CZN_COMN_USER_MST","LAST_CONN_DT","STD_USER_YN","EXPT_USER_YN","COUNT"],"recommended_sql_terms":["BASE_DT"],"forbidden_sql_terms":["AU_FLAG"],"required_result_shape":"SINGLE_AGGREGATE"}',
|
||||
updated_at = SYSTIMESTAMP
|
||||
WHERE question_code = 'STD-25';
|
||||
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
/
|
||||
|
||||
SELECT question_code, expected_focus, baseline_sql, baseline_answer, evaluation_rule_json
|
||||
FROM sg_ai_qa_question
|
||||
WHERE question_code = 'STD-25';
|
||||
@@ -0,0 +1,40 @@
|
||||
-- CZN-02 customer sample marks STD_USER_YN='Y' as optional for daily
|
||||
-- standard-AU reporting. It must not turn an otherwise correct AU query into
|
||||
-- a failure merely because the condition is present.
|
||||
|
||||
UPDATE sg_ai_qa_question
|
||||
SET expected_focus = 'Daily standard AU: COUNT(DISTINCT GUID) from CZN_COMN_USER_MST '
|
||||
|| 'for BASE_DT=2026-07-15 with AU_FLAG=1 and EXPT_USER_YN=''N''. '
|
||||
|| 'STD_USER_YN=''Y'' is an allowed optional cohort filter in the customer sample; '
|
||||
|| 'its presence or absence is not a contradiction to this baseline.',
|
||||
evaluation_rule_json = '{"required_sql_terms":["CZN_COMN_USER_MST","AU_FLAG","EXPT_USER_YN","COUNT"],"recommended_sql_terms":["BASE_DT","STD_USER_YN"],"optional_sql_terms":["STD_USER_YN"]}',
|
||||
updated_at = SYSTIMESTAMP
|
||||
WHERE question_code = 'CZN-02';
|
||||
|
||||
/
|
||||
|
||||
UPDATE sg_qa_vector_example
|
||||
SET answer_text = 'Expected focus: daily standard AU uses CZN_COMN_USER_MST, BASE_DT=2026-07-15, '
|
||||
|| 'AU_FLAG=1 and EXPT_USER_YN=''N''. The customer sample permits STD_USER_YN=''Y'' '
|
||||
|| 'as an optional standard-user cohort filter; do not treat its presence as a conflicting condition. '
|
||||
|| 'Historical answer: STD_AU_COUNT=0',
|
||||
inspection_note = 'Customer sample permits optional STD_USER_YN filtering for daily standard AU; AU_FLAG and excluded-user filtering remain mandatory.',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-02'
|
||||
AND reference_status = 'APPROVED';
|
||||
|
||||
/
|
||||
|
||||
COMMIT;
|
||||
|
||||
/
|
||||
|
||||
SELECT q.question_code, q.expected_focus, q.evaluation_rule_json,
|
||||
e.example_id, e.answer_text
|
||||
FROM sg_ai_qa_question q
|
||||
LEFT JOIN sg_qa_vector_example e
|
||||
ON e.source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND e.source_case_id = q.question_code
|
||||
WHERE q.question_code = 'CZN-02';
|
||||
90
database/adb/131_sgmp_independent_au_comparison_pattern.sql
Normal file
90
database/adb/131_sgmp_independent_au_comparison_pattern.sql
Normal file
@@ -0,0 +1,90 @@
|
||||
-- Reusable SINGLE-scope pattern: two AU populations must be aggregated
|
||||
-- independently before comparison. A user-master LEFT JOIN may erase valid
|
||||
-- business-user rows and must not define the business population.
|
||||
|
||||
UPDATE sg_ai_qa_question
|
||||
SET expected_focus = 'Compare standard AU and business AU as two independent single-row aggregates for the same as-of date. '
|
||||
|| 'Standard AU uses the resolved game user master with AU_FLAG=1 and EXPT_USER_YN=''N''. '
|
||||
|| 'Business AU uses the resolved game business-user fact with BIZ_AU_FLAG=1 and EXPT_USER_YN=''N''. '
|
||||
|| 'Do not make the business count depend on a LEFT JOIN from the user-master population. '
|
||||
|| 'STD_USER_YN=''Y'' is an allowed optional cohort filter, not a reason to reject the result.',
|
||||
evaluation_rule_json = '{"required_sql_terms":["CZN_COMN_USER_MST","CZN_CUSTOM_BIZ_USER_TXN","AU_FLAG","BIZ_AU_FLAG","EXPT_USER_YN","COUNT"],"recommended_sql_terms":["BASE_DT","STD_USER_YN"],"optional_sql_terms":["STD_USER_YN"],"required_result_shape":"SINGLE_COMPARISON"}',
|
||||
updated_at = SYSTIMESTAMP
|
||||
WHERE question_code = 'CZN-03';
|
||||
|
||||
/
|
||||
|
||||
DECLARE
|
||||
v_input CLOB;
|
||||
v_embedding VECTOR;
|
||||
v_exists NUMBER;
|
||||
BEGIN
|
||||
v_input := TO_CLOB('Question pattern: compare daily standard active users and business active users for one resolved game and one business date.')
|
||||
|| CHR(10) || 'Question pattern Korean: 한 게임의 기준일 일간 표준 AU와 사업 AU를 비교해줘.'
|
||||
|| CHR(10) || 'Logical object role: USER_BUSINESS_AU_COMPARISON'
|
||||
|| CHR(10) || 'Required result shape: one row with two independent aggregate metrics.'
|
||||
|| CHR(10) || 'Business population must be aggregated independently; a LEFT JOIN from the user-master population may not define it.';
|
||||
v_embedding := DBMS_VECTOR.UTL_TO_EMBEDDING(
|
||||
v_input, JSON(sg_qa_vector_params('search_document'))
|
||||
);
|
||||
|
||||
SELECT COUNT(*) INTO v_exists
|
||||
FROM sg_qa_vector_example
|
||||
WHERE source_type = 'POLICY_TEMPLATE'
|
||||
AND source_case_id = 'STD_BIZ_AU_COMPARE';
|
||||
|
||||
IF v_exists = 0 THEN
|
||||
INSERT INTO sg_qa_vector_example (
|
||||
question, answer_sql, answer_text, embedding_input, embedding, embedding_model,
|
||||
reference_status, reference_kind, target_type, object_role,
|
||||
inspection_status, inspection_note, verified_at, verified_by,
|
||||
source_case_id, source_type
|
||||
) VALUES (
|
||||
'한 게임의 기준일 일간 표준 AU와 사업 AU를 비교해줘.',
|
||||
TO_CLOB('SELECT' || CHR(10)
|
||||
|| ' (SELECT COUNT(DISTINCT u."GUID")' || CHR(10)
|
||||
|| ' FROM <RESOLVED_GAME_USER_MASTER> u' || CHR(10)
|
||||
|| ' WHERE u."BASE_DT" = <BUSINESS_DATE>' || CHR(10)
|
||||
|| ' AND u."AU_FLAG" = 1' || CHR(10)
|
||||
|| ' AND u."EXPT_USER_YN" = ''N'') AS "STANDARD_AU_COUNT",' || CHR(10)
|
||||
|| ' (SELECT COUNT(DISTINCT b."GUID")' || CHR(10)
|
||||
|| ' FROM <RESOLVED_GAME_BUSINESS_USER> b' || CHR(10)
|
||||
|| ' WHERE b."BASE_DT" = <BUSINESS_DATE>' || CHR(10)
|
||||
|| ' AND b."BIZ_AU_FLAG" = 1' || CHR(10)
|
||||
|| ' AND b."EXPT_USER_YN" = ''N'') AS "BUSINESS_AU_COUNT"' || CHR(10)
|
||||
|| 'FROM DUAL'),
|
||||
'Applicable metric reference: for this daily AU comparison, the standard metric must use AU_FLAG=1 and EXPT_USER_YN=''N''; do not replace it with LAST_CONN_DT period logic or STD_USER_YN alone. The business metric must use BIZ_AU_FLAG=1 and EXPT_USER_YN=''N''. Produce one row from two independent aggregate subqueries, and do not count business users through a LEFT JOIN from the standard-user population. STD_USER_YN may be added only as an optional cohort filter.',
|
||||
v_input, v_embedding, 'cohere.embed-v4.0',
|
||||
'APPROVED', 'SQL_TEMPLATE', 'SINGLE', 'USER_BUSINESS_AU_COMPARISON',
|
||||
'VERIFIED',
|
||||
'Reusable comparison pattern with logical placeholders only; no customer game, date, result, or physical object is embedded.',
|
||||
SYSTIMESTAMP, 'SGMP_POC_METADATA_REVIEW',
|
||||
'STD_BIZ_AU_COMPARE', 'POLICY_TEMPLATE'
|
||||
);
|
||||
ELSE
|
||||
UPDATE sg_qa_vector_example
|
||||
SET question = '한 게임의 기준일 일간 표준 AU와 사업 AU를 비교해줘.',
|
||||
answer_sql = TO_CLOB('SELECT' || CHR(10)
|
||||
|| ' (SELECT COUNT(DISTINCT u."GUID")' || CHR(10)
|
||||
|| ' FROM <RESOLVED_GAME_USER_MASTER> u' || CHR(10)
|
||||
|| ' WHERE u."BASE_DT" = <BUSINESS_DATE>' || CHR(10)
|
||||
|| ' AND u."AU_FLAG" = 1' || CHR(10)
|
||||
|| ' AND u."EXPT_USER_YN" = ''N'') AS "STANDARD_AU_COUNT",' || CHR(10)
|
||||
|| ' (SELECT COUNT(DISTINCT b."GUID")' || CHR(10)
|
||||
|| ' FROM <RESOLVED_GAME_BUSINESS_USER> b' || CHR(10)
|
||||
|| ' WHERE b."BASE_DT" = <BUSINESS_DATE>' || CHR(10)
|
||||
|| ' AND b."BIZ_AU_FLAG" = 1' || CHR(10)
|
||||
|| ' AND b."EXPT_USER_YN" = ''N'') AS "BUSINESS_AU_COUNT"' || CHR(10)
|
||||
|| 'FROM DUAL'),
|
||||
answer_text = 'Applicable metric reference: for this daily AU comparison, the standard metric must use AU_FLAG=1 and EXPT_USER_YN=''N''; do not replace it with LAST_CONN_DT period logic or STD_USER_YN alone. The business metric must use BIZ_AU_FLAG=1 and EXPT_USER_YN=''N''. Produce one row from two independent aggregate subqueries, and do not count business users through a LEFT JOIN from the standard-user population. STD_USER_YN may be added only as an optional cohort filter.',
|
||||
embedding_input = v_input,
|
||||
embedding = v_embedding,
|
||||
reference_status = 'APPROVED', inspection_status = 'VERIFIED',
|
||||
verified_at = SYSTIMESTAMP, verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'POLICY_TEMPLATE'
|
||||
AND source_case_id = 'STD_BIZ_AU_COMPARE';
|
||||
END IF;
|
||||
COMMIT;
|
||||
END;
|
||||
|
||||
/
|
||||
58
database/adb/132_sgmp_country_daily_au_pattern.sql
Normal file
58
database/adb/132_sgmp_country_daily_au_pattern.sql
Normal file
@@ -0,0 +1,58 @@
|
||||
-- Reusable SINGLE-scope pattern for country-grouped daily AU.
|
||||
|
||||
UPDATE sg_ai_qa_question
|
||||
SET expected_focus = 'Country-grouped daily standard AU uses the resolved game user master with BASE_DT, AU_FLAG=1 and EXPT_USER_YN=''N''. '
|
||||
|| 'Group by LAST_CONN_COUNTRY_CD and use the approved country dimension only for display/classification. '
|
||||
|| 'STD_USER_YN is optional and cannot replace AU_FLAG for the daily metric.',
|
||||
evaluation_rule_json = '{"required_sql_terms":["CZN_COMN_USER_MST","AU_FLAG","EXPT_USER_YN","LAST_CONN_COUNTRY_CD","COUNT"],"recommended_sql_terms":["BASE_DT","COMN_COUNTRY_BAS","STD_USER_YN"],"optional_sql_terms":["STD_USER_YN"],"required_result_shape":"COUNTRY_GROUPED"}',
|
||||
updated_at = SYSTIMESTAMP
|
||||
WHERE question_code = 'CZN-06';
|
||||
|
||||
/
|
||||
|
||||
DECLARE
|
||||
v_input CLOB;
|
||||
v_embedding VECTOR;
|
||||
v_exists NUMBER;
|
||||
BEGIN
|
||||
v_input := TO_CLOB('Question pattern: show daily active-user counts by country for one resolved game and one business date.')
|
||||
|| CHR(10) || 'Question pattern Korean: 한 게임의 기준일 주요 국가별 표준 AU 수를 알려줘.'
|
||||
|| CHR(10) || 'Logical object role: COUNTRY_GROUPED_DAILY_AU'
|
||||
|| CHR(10) || 'Required metric: AU_FLAG=1 and excluded-user filtering; group by the last connection country.';
|
||||
v_embedding := DBMS_VECTOR.UTL_TO_EMBEDDING(v_input, JSON(sg_qa_vector_params('search_document')));
|
||||
SELECT COUNT(*) INTO v_exists FROM sg_qa_vector_example
|
||||
WHERE source_type = 'POLICY_TEMPLATE' AND source_case_id = 'COUNTRY_DAILY_AU';
|
||||
IF v_exists = 0 THEN
|
||||
INSERT INTO sg_qa_vector_example (
|
||||
question, answer_sql, answer_text, embedding_input, embedding, embedding_model,
|
||||
reference_status, reference_kind, target_type, object_role,
|
||||
inspection_status, inspection_note, verified_at, verified_by, source_case_id, source_type
|
||||
) VALUES (
|
||||
'한 게임의 기준일 주요 국가별 표준 AU 수를 알려줘.',
|
||||
TO_CLOB('SELECT u."LAST_CONN_COUNTRY_CD" AS "COUNTRY_CD",' || CHR(10)
|
||||
|| ' c."COUNTRY_KR_NM" AS "COUNTRY_NAME",' || CHR(10)
|
||||
|| ' COUNT(DISTINCT u."GUID") AS "STANDARD_AU_COUNT"' || CHR(10)
|
||||
|| 'FROM <RESOLVED_GAME_USER_MASTER> u' || CHR(10)
|
||||
|| 'LEFT JOIN <APPROVED_COUNTRY_DIMENSION> c' || CHR(10)
|
||||
|| ' ON c."COUNTRY_2CHAR_CD" = u."LAST_CONN_COUNTRY_CD"' || CHR(10)
|
||||
|| 'WHERE u."BASE_DT" = <BUSINESS_DATE>' || CHR(10)
|
||||
|| ' AND u."AU_FLAG" = 1' || CHR(10)
|
||||
|| ' AND u."EXPT_USER_YN" = ''N''' || CHR(10)
|
||||
|| 'GROUP BY u."LAST_CONN_COUNTRY_CD", c."COUNTRY_KR_NM"'),
|
||||
'Applicable metric reference: country-grouped daily AU must use AU_FLAG=1 and EXPT_USER_YN=''N''; do not replace AU_FLAG with STD_USER_YN alone. Group by LAST_CONN_COUNTRY_CD. Use an approved country dimension for country display or a current approved major-country classification when the request requires it.',
|
||||
v_input, v_embedding, 'cohere.embed-v4.0',
|
||||
'APPROVED', 'SQL_TEMPLATE', 'SINGLE', 'COUNTRY_GROUPED_DAILY_AU',
|
||||
'VERIFIED', 'Reusable country-grouped daily-AU pattern; no customer game, date, result, or physical object is embedded.',
|
||||
SYSTIMESTAMP, 'SGMP_POC_METADATA_REVIEW', 'COUNTRY_DAILY_AU', 'POLICY_TEMPLATE'
|
||||
);
|
||||
ELSE
|
||||
UPDATE sg_qa_vector_example
|
||||
SET embedding_input = v_input, embedding = v_embedding,
|
||||
reference_status = 'APPROVED', inspection_status = 'VERIFIED',
|
||||
verified_at = SYSTIMESTAMP, verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'POLICY_TEMPLATE' AND source_case_id = 'COUNTRY_DAILY_AU';
|
||||
END IF;
|
||||
COMMIT;
|
||||
END;
|
||||
|
||||
/
|
||||
17
database/adb/133_sgmp_restore_czn06_exact_fewshot.sql
Normal file
17
database/adb/133_sgmp_restore_czn06_exact_fewshot.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- CZN-06 is a verified, exact customer question/SQL pair. It must be a
|
||||
-- runtime Few-shot when approved; RETIRED is the DB switch that excludes it.
|
||||
-- This is a single-game reference, so keep the retrieval scope explicit.
|
||||
UPDATE sg_qa_vector_example
|
||||
SET reference_status = 'APPROVED',
|
||||
reference_kind = 'SQL_TEMPLATE',
|
||||
target_type = 'SINGLE',
|
||||
object_role = 'COUNTRY_GROUPED_DAILY_AU',
|
||||
inspection_status = 'VERIFIED',
|
||||
inspection_note = 'Verified exact CZN-06 Few-shot restored for runtime retrieval. Daily country AU requires AU_FLAG=1 and EXPT_USER_YN=''N''; STD_USER_YN alone is insufficient.',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-06'
|
||||
/
|
||||
|
||||
COMMIT
|
||||
69
database/adb/135_sgmp_semantic_fewshot_retrieval.sql
Normal file
69
database/adb/135_sgmp_semantic_fewshot_retrieval.sql
Normal file
@@ -0,0 +1,69 @@
|
||||
-- Runtime Few-shots remain semantic vector retrieval. Customer examples are
|
||||
-- governed by their DB approval state, not restricted to exact text matches.
|
||||
|
||||
UPDATE sg_qa_vector_example
|
||||
SET reference_status = 'APPROVED',
|
||||
reference_kind = 'SQL_TEMPLATE',
|
||||
target_type = 'SINGLE',
|
||||
object_role = 'GAME_GOODS_HOLDINGS',
|
||||
inspection_status = 'VERIFIED',
|
||||
inspection_note = 'Verified CZN-07 semantic Few-shot. Use goods holdings, crystal dimension, RU_FLAG=1, excluded-user filter, nonzero holdings, and daily grouping.',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-07'
|
||||
/
|
||||
|
||||
CREATE OR REPLACE FUNCTION sg_qa_vector_search(
|
||||
p_question IN CLOB,
|
||||
p_top_k IN PLS_INTEGER DEFAULT 3,
|
||||
p_target_type IN VARCHAR2 DEFAULT 'ANY'
|
||||
) RETURN SYS_REFCURSOR AUTHID DEFINER
|
||||
IS
|
||||
v_query_vector VECTOR;
|
||||
v_results SYS_REFCURSOR;
|
||||
v_target_type VARCHAR2(16) := UPPER(TRIM(NVL(p_target_type, 'ANY')));
|
||||
v_max_cosine_distance NUMBER;
|
||||
BEGIN
|
||||
IF p_question IS NULL THEN RAISE_APPLICATION_ERROR(-20003, 'question is required.'); END IF;
|
||||
IF p_top_k IS NULL OR p_top_k < 1 OR p_top_k > 20 THEN
|
||||
RAISE_APPLICATION_ERROR(-20004, 'top_k must be between 1 and 20.');
|
||||
END IF;
|
||||
IF v_target_type NOT IN ('NONE', 'SINGLE', 'MULTI', 'ALL', 'ANY') THEN
|
||||
RAISE_APPLICATION_ERROR(-20005, 'invalid target type.');
|
||||
END IF;
|
||||
|
||||
SELECT number_value INTO v_max_cosine_distance
|
||||
FROM sg_game_scope_policy
|
||||
WHERE policy_key = 'QA_VECTOR_MAX_COSINE_DISTANCE'
|
||||
AND active_yn = 'Y'
|
||||
AND number_value IS NOT NULL;
|
||||
|
||||
v_query_vector := DBMS_VECTOR.UTL_TO_EMBEDDING(
|
||||
p_question, JSON(sg_qa_vector_params('search_query'))
|
||||
);
|
||||
|
||||
OPEN v_results FOR
|
||||
SELECT example_id, question, answer_sql, answer_text, embedding_model,
|
||||
reference_kind, target_type, object_role, source_case_id, source_type,
|
||||
cosine_distance
|
||||
FROM (
|
||||
SELECT example_id, question, answer_sql, answer_text, embedding_model,
|
||||
reference_kind, target_type, object_role, source_case_id, source_type,
|
||||
VECTOR_DISTANCE(embedding, v_query_vector, COSINE) AS cosine_distance
|
||||
FROM sg_qa_vector_example
|
||||
WHERE reference_status = 'APPROVED'
|
||||
AND inspection_status = 'VERIFIED'
|
||||
AND answer_sql IS NOT NULL
|
||||
AND (source_type = 'POLICY_TEMPLATE'
|
||||
OR NOT REGEXP_LIKE(answer_sql, '<[A-Z][A-Z0-9_]*>', 'i'))
|
||||
AND (target_type = 'ANY' OR v_target_type = 'ANY' OR target_type = v_target_type)
|
||||
)
|
||||
WHERE cosine_distance <= v_max_cosine_distance
|
||||
ORDER BY cosine_distance, example_id
|
||||
FETCH FIRST p_top_k ROWS ONLY;
|
||||
RETURN v_results;
|
||||
END;
|
||||
/
|
||||
|
||||
COMMIT
|
||||
87
database/adb/136_sgmp_fewshot_neighbor_margin.sql
Normal file
87
database/adb/136_sgmp_fewshot_neighbor_margin.sql
Normal file
@@ -0,0 +1,87 @@
|
||||
-- Keep semantic vector retrieval, but do not inject weak trailing neighbours
|
||||
-- when a materially stronger example has already been found.
|
||||
MERGE INTO sg_game_scope_policy t
|
||||
USING (
|
||||
SELECT 'QA_VECTOR_NEIGHBOR_DISTANCE_MARGIN' AS policy_key,
|
||||
0.120000 AS number_value,
|
||||
'Maximum additional cosine distance from the best runtime Few-shot candidate.' AS description
|
||||
FROM dual
|
||||
) s
|
||||
ON (t.policy_key = s.policy_key)
|
||||
WHEN MATCHED THEN UPDATE SET
|
||||
t.number_value = s.number_value,
|
||||
t.description = s.description,
|
||||
t.active_yn = 'Y',
|
||||
t.updated_at = SYSTIMESTAMP
|
||||
WHEN NOT MATCHED THEN INSERT (
|
||||
policy_key, number_value, text_value, description, active_yn
|
||||
) VALUES (
|
||||
s.policy_key, s.number_value, NULL, s.description, 'Y'
|
||||
)
|
||||
/
|
||||
|
||||
CREATE OR REPLACE FUNCTION sg_qa_vector_search(
|
||||
p_question IN CLOB,
|
||||
p_top_k IN PLS_INTEGER DEFAULT 3,
|
||||
p_target_type IN VARCHAR2 DEFAULT 'ANY'
|
||||
) RETURN SYS_REFCURSOR AUTHID DEFINER
|
||||
IS
|
||||
v_query_vector VECTOR;
|
||||
v_results SYS_REFCURSOR;
|
||||
v_target_type VARCHAR2(16) := UPPER(TRIM(NVL(p_target_type, 'ANY')));
|
||||
v_max_cosine_distance NUMBER;
|
||||
v_neighbor_margin NUMBER;
|
||||
BEGIN
|
||||
IF p_question IS NULL THEN RAISE_APPLICATION_ERROR(-20003, 'question is required.'); END IF;
|
||||
IF p_top_k IS NULL OR p_top_k < 1 OR p_top_k > 20 THEN
|
||||
RAISE_APPLICATION_ERROR(-20004, 'top_k must be between 1 and 20.');
|
||||
END IF;
|
||||
IF v_target_type NOT IN ('NONE', 'SINGLE', 'MULTI', 'ALL', 'ANY') THEN
|
||||
RAISE_APPLICATION_ERROR(-20005, 'invalid target type.');
|
||||
END IF;
|
||||
|
||||
SELECT number_value INTO v_max_cosine_distance
|
||||
FROM sg_game_scope_policy
|
||||
WHERE policy_key = 'QA_VECTOR_MAX_COSINE_DISTANCE'
|
||||
AND active_yn = 'Y'
|
||||
AND number_value IS NOT NULL;
|
||||
|
||||
SELECT number_value INTO v_neighbor_margin
|
||||
FROM sg_game_scope_policy
|
||||
WHERE policy_key = 'QA_VECTOR_NEIGHBOR_DISTANCE_MARGIN'
|
||||
AND active_yn = 'Y'
|
||||
AND number_value IS NOT NULL;
|
||||
|
||||
v_query_vector := DBMS_VECTOR.UTL_TO_EMBEDDING(
|
||||
p_question, JSON(sg_qa_vector_params('search_query'))
|
||||
);
|
||||
|
||||
OPEN v_results FOR
|
||||
SELECT example_id, question, answer_sql, answer_text, embedding_model,
|
||||
reference_kind, target_type, object_role, source_case_id, source_type,
|
||||
cosine_distance
|
||||
FROM (
|
||||
SELECT c.*,
|
||||
MIN(c.cosine_distance) OVER () AS best_cosine_distance
|
||||
FROM (
|
||||
SELECT example_id, question, answer_sql, answer_text, embedding_model,
|
||||
reference_kind, target_type, object_role, source_case_id, source_type,
|
||||
VECTOR_DISTANCE(embedding, v_query_vector, COSINE) AS cosine_distance
|
||||
FROM sg_qa_vector_example
|
||||
WHERE reference_status = 'APPROVED'
|
||||
AND inspection_status = 'VERIFIED'
|
||||
AND answer_sql IS NOT NULL
|
||||
AND (source_type = 'POLICY_TEMPLATE'
|
||||
OR NOT REGEXP_LIKE(answer_sql, '<[A-Z][A-Z0-9_]*>', 'i'))
|
||||
AND (target_type = 'ANY' OR v_target_type = 'ANY' OR target_type = v_target_type)
|
||||
) c
|
||||
WHERE c.cosine_distance <= v_max_cosine_distance
|
||||
)
|
||||
WHERE cosine_distance <= best_cosine_distance + v_neighbor_margin
|
||||
ORDER BY cosine_distance, example_id
|
||||
FETCH FIRST p_top_k ROWS ONLY;
|
||||
RETURN v_results;
|
||||
END;
|
||||
/
|
||||
|
||||
COMMIT
|
||||
@@ -0,0 +1,16 @@
|
||||
-- CZN-08 is the reviewed semantic reference for daily standard-AU crystal
|
||||
-- total and per-user average holdings.
|
||||
UPDATE sg_qa_vector_example
|
||||
SET reference_status = 'APPROVED',
|
||||
reference_kind = 'SQL_TEMPLATE',
|
||||
target_type = 'SINGLE',
|
||||
object_role = 'GAME_GOODS_HOLDINGS',
|
||||
inspection_status = 'VERIFIED',
|
||||
inspection_note = 'Verified CZN-08 Few-shot. Standard-AU crystal holdings require AU_FLAG=1, excluded-user filtering, and per-user average as SUM(HAVE_CNT) / COUNT(DISTINCT GUID), not AVG(HAVE_CNT).',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-08'
|
||||
/
|
||||
|
||||
COMMIT
|
||||
11
database/adb/138_sgmp_tighten_fewshot_neighbor_margin.sql
Normal file
11
database/adb/138_sgmp_tighten_fewshot_neighbor_margin.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Calibrate the semantic-neighbour window using reviewed CZN patterns:
|
||||
-- retain close paraphrases, exclude adjacent metric shapes.
|
||||
UPDATE sg_game_scope_policy
|
||||
SET number_value = 0.100000,
|
||||
description = 'Maximum additional cosine distance from the best runtime Few-shot candidate.',
|
||||
active_yn = 'Y',
|
||||
updated_at = SYSTIMESTAMP
|
||||
WHERE policy_key = 'QA_VECTOR_NEIGHBOR_DISTANCE_MARGIN'
|
||||
/
|
||||
|
||||
COMMIT
|
||||
@@ -0,0 +1,15 @@
|
||||
-- CZN-05 is the reviewed reference for country-grouped business AU.
|
||||
UPDATE sg_qa_vector_example
|
||||
SET reference_status = 'APPROVED',
|
||||
reference_kind = 'SQL_TEMPLATE',
|
||||
target_type = 'SINGLE',
|
||||
object_role = 'COUNTRY_GROUPED_BUSINESS_AU',
|
||||
inspection_status = 'VERIFIED',
|
||||
inspection_note = 'Verified CZN-05 Few-shot. Join business-user data to user master on GUID and BASE_DT before grouping by user country; filter BIZ_AU_FLAG=1 and EXPT_USER_YN=''N''.',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-05'
|
||||
/
|
||||
|
||||
COMMIT
|
||||
95
database/adb/140_sgmp_hybrid_fewshot_reranking.sql
Normal file
95
database/adb/140_sgmp_hybrid_fewshot_reranking.sql
Normal file
@@ -0,0 +1,95 @@
|
||||
-- Hybrid retrieval remains database-driven: dense vector similarity handles
|
||||
-- paraphrases, while lexical similarity distinguishes decisive request terms.
|
||||
MERGE INTO sg_game_scope_policy t
|
||||
USING (
|
||||
SELECT 'QA_VECTOR_LEXICAL_WEIGHT' AS policy_key, 0.350000 AS number_value,
|
||||
'Weight of normalized lexical question similarity in runtime Few-shot reranking.' AS description
|
||||
FROM dual
|
||||
UNION ALL
|
||||
SELECT 'QA_VECTOR_HYBRID_SCORE_MARGIN', 0.050000,
|
||||
'Maximum hybrid-score difference from the best runtime Few-shot candidate.'
|
||||
FROM dual
|
||||
) s
|
||||
ON (t.policy_key = s.policy_key)
|
||||
WHEN MATCHED THEN UPDATE SET
|
||||
t.number_value = s.number_value,
|
||||
t.description = s.description,
|
||||
t.active_yn = 'Y',
|
||||
t.updated_at = SYSTIMESTAMP
|
||||
WHEN NOT MATCHED THEN INSERT (
|
||||
policy_key, number_value, text_value, description, active_yn
|
||||
) VALUES (
|
||||
s.policy_key, s.number_value, NULL, s.description, 'Y'
|
||||
)
|
||||
/
|
||||
|
||||
CREATE OR REPLACE FUNCTION sg_qa_vector_search(
|
||||
p_question IN CLOB,
|
||||
p_top_k IN PLS_INTEGER DEFAULT 3,
|
||||
p_target_type IN VARCHAR2 DEFAULT 'ANY'
|
||||
) RETURN SYS_REFCURSOR AUTHID DEFINER
|
||||
IS
|
||||
v_query_vector VECTOR;
|
||||
v_results SYS_REFCURSOR;
|
||||
v_target_type VARCHAR2(16) := UPPER(TRIM(NVL(p_target_type, 'ANY')));
|
||||
v_max_cosine_distance NUMBER;
|
||||
v_lexical_weight NUMBER;
|
||||
v_hybrid_margin NUMBER;
|
||||
BEGIN
|
||||
IF p_question IS NULL THEN RAISE_APPLICATION_ERROR(-20003, 'question is required.'); END IF;
|
||||
IF p_top_k IS NULL OR p_top_k < 1 OR p_top_k > 20 THEN
|
||||
RAISE_APPLICATION_ERROR(-20004, 'top_k must be between 1 and 20.');
|
||||
END IF;
|
||||
IF v_target_type NOT IN ('NONE', 'SINGLE', 'MULTI', 'ALL', 'ANY') THEN
|
||||
RAISE_APPLICATION_ERROR(-20005, 'invalid target type.');
|
||||
END IF;
|
||||
|
||||
SELECT number_value INTO v_max_cosine_distance FROM sg_game_scope_policy
|
||||
WHERE policy_key = 'QA_VECTOR_MAX_COSINE_DISTANCE' AND active_yn = 'Y';
|
||||
SELECT number_value INTO v_lexical_weight FROM sg_game_scope_policy
|
||||
WHERE policy_key = 'QA_VECTOR_LEXICAL_WEIGHT' AND active_yn = 'Y';
|
||||
SELECT number_value INTO v_hybrid_margin FROM sg_game_scope_policy
|
||||
WHERE policy_key = 'QA_VECTOR_HYBRID_SCORE_MARGIN' AND active_yn = 'Y';
|
||||
|
||||
v_query_vector := DBMS_VECTOR.UTL_TO_EMBEDDING(
|
||||
p_question, JSON(sg_qa_vector_params('search_query'))
|
||||
);
|
||||
|
||||
OPEN v_results FOR
|
||||
SELECT example_id, question, answer_sql, answer_text, embedding_model,
|
||||
reference_kind, target_type, object_role, source_case_id, source_type,
|
||||
cosine_distance
|
||||
FROM (
|
||||
SELECT s.*,
|
||||
MAX(s.hybrid_score) OVER () AS best_hybrid_score
|
||||
FROM (
|
||||
SELECT c.*,
|
||||
((1 - v_lexical_weight) * (1 - c.cosine_distance)
|
||||
+ v_lexical_weight * c.lexical_similarity) AS hybrid_score
|
||||
FROM (
|
||||
SELECT example_id, question, answer_sql, answer_text, embedding_model,
|
||||
reference_kind, target_type, object_role, source_case_id, source_type,
|
||||
VECTOR_DISTANCE(embedding, v_query_vector, COSINE) AS cosine_distance,
|
||||
UTL_MATCH.JARO_WINKLER_SIMILARITY(
|
||||
DBMS_LOB.SUBSTR(question, 4000, 1),
|
||||
DBMS_LOB.SUBSTR(p_question, 4000, 1)
|
||||
) / 100 AS lexical_similarity
|
||||
FROM sg_qa_vector_example
|
||||
WHERE reference_status = 'APPROVED'
|
||||
AND inspection_status = 'VERIFIED'
|
||||
AND answer_sql IS NOT NULL
|
||||
AND (source_type = 'POLICY_TEMPLATE'
|
||||
OR NOT REGEXP_LIKE(answer_sql, '<[A-Z][A-Z0-9_]*>', 'i'))
|
||||
AND (target_type = 'ANY' OR v_target_type = 'ANY' OR target_type = v_target_type)
|
||||
) c
|
||||
WHERE c.cosine_distance <= v_max_cosine_distance
|
||||
) s
|
||||
)
|
||||
WHERE hybrid_score >= best_hybrid_score - v_hybrid_margin
|
||||
ORDER BY hybrid_score DESC, cosine_distance, example_id
|
||||
FETCH FIRST p_top_k ROWS ONLY;
|
||||
RETURN v_results;
|
||||
END;
|
||||
/
|
||||
|
||||
COMMIT
|
||||
15
database/adb/141_sgmp_restore_czn13_ether_usage_fewshot.sql
Normal file
15
database/adb/141_sgmp_restore_czn13_ether_usage_fewshot.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- CZN-13 is the reviewed reference for Ether usage and distinct users.
|
||||
UPDATE sg_qa_vector_example
|
||||
SET reference_status = 'APPROVED',
|
||||
reference_kind = 'SQL_TEMPLATE',
|
||||
target_type = 'SINGLE',
|
||||
object_role = 'GAME_GOODS_CHANGE',
|
||||
inspection_status = 'VERIFIED',
|
||||
inspection_note = 'Verified CZN-13 Few-shot. Ether usage requires goods-change data joined to the goods dimension and user master by GUID and BASE_DT, CHANGE_TYPE_CD=''USE'', active Ether dimension, excluded-user filter, and GOODS_CHANGE_CNT aggregation.',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-13'
|
||||
/
|
||||
|
||||
COMMIT
|
||||
@@ -0,0 +1,15 @@
|
||||
-- CZN-16 is the reviewed reference for purchasers of a named package.
|
||||
UPDATE sg_qa_vector_example
|
||||
SET reference_status = 'APPROVED',
|
||||
reference_kind = 'SQL_TEMPLATE',
|
||||
target_type = 'SINGLE',
|
||||
object_role = 'SALES_PRODUCT_PURCHASER',
|
||||
inspection_status = 'VERIFIED',
|
||||
inspection_note = 'Verified CZN-16 Few-shot. Join sales transactions to product display by GAME_ID and PRODUCT_ID, filter the resolved package name and excluded users, and use the payment business date when counting distinct purchasers.',
|
||||
verified_at = SYSTIMESTAMP,
|
||||
verified_by = 'SGMP_POC_METADATA_REVIEW'
|
||||
WHERE source_type = 'CUSTOMER_QA_BENCHMARK'
|
||||
AND source_case_id = 'CZN-16'
|
||||
/
|
||||
|
||||
COMMIT
|
||||
Reference in New Issue
Block a user