@@ -45,7 +45,22 @@ class QueryMakerState(TypedDict):
4545
4646# 노드 함수: PROFILE_EXTRACTION 노드
4747def profile_extraction_node (state : QueryMakerState ):
48-
48+ """
49+ 자연어 쿼리로부터 질문 유형(PROFILE)을 추출하는 노드입니다.
50+
51+ 이 노드는 주어진 자연어 쿼리에서 질문의 특성을 분석하여, 해당 질문이 시계열 분석, 집계 함수 사용, 조건 필터 필요 여부,
52+ 그룹화, 정렬/순위, 기간 비교 등 다양한 특성을 갖는지 여부를 추출합니다.
53+
54+ 추출된 정보는 `QuestionProfile` 모델에 맞춰 저장됩니다. `QuestionProfile` 모델의 필드는 다음과 같습니다:
55+ - `is_timeseries`: 시계열 분석 필요 여부
56+ - `is_aggregation`: 집계 함수 필요 여부
57+ - `has_filter`: 조건 필터 필요 여부
58+ - `is_grouped`: 그룹화 필요 여부
59+ - `has_ranking`: 정렬/순위 필요 여부
60+ - `has_temporal_comparison`: 기간 비교 포함 여부
61+ - `intent_type`: 질문의 주요 의도 유형
62+
63+ """
4964 result = profile_extraction_chain .invoke ({"question" : state ["messages" ][0 ].content })
5065
5166 state ["question_profile" ] = result
@@ -70,6 +85,10 @@ def query_refiner_node(state: QueryMakerState):
7085
7186# 노드 함수: QUERY_REFINER 노드
7287def query_refiner_with_profile_node (state : QueryMakerState ):
88+ """
89+ 자연어 쿼리로부터 질문 유형(PROFILE)을 사용해 자연어 질의를 확장하는 노드입니다.
90+
91+ """
7392
7493 profile_bullets = profile_to_text (state ["question_profile" ])
7594 res = query_refiner_with_profile_chain .invoke (
@@ -90,8 +109,32 @@ def query_refiner_with_profile_node(state: QueryMakerState):
90109
91110# 노드 함수: CONTEXT_ENRICHMENT 노드
92111def context_enrichment_node (state : QueryMakerState ):
112+ """
113+ 주어진 질문과 관련된 메타데이터를 기반으로 질문을 풍부하게 만드는 노드입니다.
114+
115+ 이 함수는 `refined_question`, `profiles`, `related_tables` 정보를 이용하여 자연어 질문을 보강합니다.
116+ 보강 과정에서는 질문의 의도를 유지하면서, 추가적인 세부 정보를 제공하거나 잘못된 용어를 수정합니다.
117+
118+ 주요 작업:
119+ - 주어진 질문의 메타데이터 (`question_profile` 및 `searched_tables`)를 활용하여, 질문을 수정하거나 추가 정보를 삽입합니다.
120+ - 질문이 시계열 분석 또는 집계 함수 관련인 경우, 이를 명시적으로 강조합니다 (예: "지난 30일 동안").
121+ - 자연어에서 실제 열 이름 또는 값으로 잘못 매칭된 용어를 수정합니다 (예: ‘미국’ → ‘USA’).
122+ - 보강된 질문을 출력합니다.
93123
94- import json
124+ Args:
125+ state (QueryMakerState): 쿼리와 관련된 상태 정보를 담고 있는 객체.
126+ 상태 객체는 `refined_input`, `question_profile`, `searched_tables` 등의 정보를 포함합니다.
127+
128+ Returns:
129+ QueryMakerState: 보강된 질문이 포함된 상태 객체.
130+
131+ Example:
132+ Given the refined question "What are the total sales in the last month?",
133+ the function would enrich it with additional information such as:
134+ - Ensuring the time period is specified correctly.
135+ - Correcting any column names if necessary.
136+ - Returning the enriched version of the question.
137+ """
95138
96139 searched_tables = state ["searched_tables" ]
97140 searched_tables_json = json .dumps (searched_tables , ensure_ascii = False , indent = 2 )
@@ -131,9 +174,7 @@ def context_enrichment_node(state: QueryMakerState):
131174 enriched_text = llm .invoke (prompt .to_messages ())
132175
133176 state ["refined_input" ] = enriched_text
134- from langchain_core .messages import HumanMessage
135-
136- state ["messages" ].append (HumanMessage (content = enriched_text .content ))
177+ state ["messages" ].append (enriched_text )
137178 print ("After context enrichment : " , enriched_text .content )
138179
139180 return state
0 commit comments