dev-yuje commited on
Commit
fd7f235
Β·
1 Parent(s): 76d8844

fix: resolve mypy type error in LazyGraphRAG and Gradio caching crash

Browse files
Files changed (3) hide show
  1. AGENTS.md +17 -0
  2. app.py +2 -1
  3. src/retrieval/finRetrieval.py +1 -0
AGENTS.md CHANGED
@@ -46,6 +46,23 @@ FinGraph/
46
  - 'src/references/' 파일 μˆ˜μ • κΈˆμ§€(참고자료)
47
  - Neo4j λ“œλΌμ΄λ²„ μ—°κ²° μ‹œ `NEO4J_USERNAME`, `NEO4J_PASSWORD`λ§Œμ„ μš”κ΅¬ν•˜κ±°λ‚˜ μ‚¬μš©ν•˜λŠ” λ°©μ‹μ˜ μ˜›λ‚  μ½”λ“œ μž‘μ„± μ ˆλŒ€ κΈˆμ§€ (Connection Client Credentials 병행 λ§€ν•‘ ν•„μˆ˜)
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ## COMMIT κ·œμΉ™
50
  - 컀밋 λ©”μ‹œμ§€: 'feat:', 'fix:', 'refactor:' 접두사 μ‚¬μš©
51
  - push ν•˜λ‚˜μ— ν•˜λ‚˜μ˜ λ³€κ²½λ§Œ
 
46
  - 'src/references/' 파일 μˆ˜μ • κΈˆμ§€(참고자료)
47
  - Neo4j λ“œλΌμ΄λ²„ μ—°κ²° μ‹œ `NEO4J_USERNAME`, `NEO4J_PASSWORD`λ§Œμ„ μš”κ΅¬ν•˜κ±°λ‚˜ μ‚¬μš©ν•˜λŠ” λ°©μ‹μ˜ μ˜›λ‚  μ½”λ“œ μž‘μ„± μ ˆλŒ€ κΈˆμ§€ (Connection Client Credentials 병행 λ§€ν•‘ ν•„μˆ˜)
48
 
49
+ ## 🚨 재발 λ°©μ§€ 및 치λͺ…적 μ•ˆν‹° νŒ¨ν„΄ κΈˆμ§€ (Recurring Issues Prevention)
50
+ 이 ν”„λ‘œμ νŠΈμ—μ„œ 3회 이상 반볡적으둜 λ°œμƒν•˜μ—¬ 전체 νŒŒμ΄ν”„λΌμΈ(둜컬, CI, ν”„λ‘œλ•μ…˜)을 λΆ•κ΄΄μ‹œμΌ°λ˜ 핡심 μž₯애듀을 영ꡬ적으둜 μ°¨λ‹¨ν•˜κΈ° μœ„ν•œ ν•„μˆ˜ κ·œμΉ™ 및 λ°©μ–΄ ν…ŒμŠ€νŠΈμž…λ‹ˆλ‹€.
51
+
52
+ - **1. Import-Time DB Connection μ ˆλŒ€ κΈˆμ§€ (CI ν¬λž˜μ‹œ λ°©μ§€)**
53
+ - **원인**: λͺ¨λ“ˆ μ „μ—­ λ²”μœ„(Global Scope)μ—μ„œ λ°μ΄ν„°λ² μ΄μŠ€λ₯Ό μ¦‰μ‹œ μ—°κ²°(`driver = get_neo4j_driver()`)ν•˜μ—¬, GitHub Actions(CI)λ‚˜ `pytest`κ°€ ν…ŒμŠ€νŠΈλ₯Ό μˆ˜μ§‘(`import`)ν•˜κΈ°λ§Œ 해도 접속 λΆˆκ°€ μ—λŸ¬(`Connection refused`)둜 λ»—μ–΄λ²„λ¦¬λŠ” 문제 3회 이상 λ°œμƒ.
54
+ - **κ·œμΉ™**: λͺ¨λ“ˆ μž„ν¬νŠΈ μ‹œμ μ—λŠ” μ ˆλŒ€ DB와 ν†΅μ‹ ν•˜μ§€ 말 것. RAG μΈμŠ€ν„΄μŠ€λŠ” λ°˜λ“œμ‹œ `LazyGraphRAG` ν”„λ‘μ‹œ νŒ¨ν„΄μ„ μ‚¬μš©ν•˜μ—¬ μ‹€μ œ 쿼리(`search`) 호좜 μ‹œμ μ— 단 1회 μ§€μ—° μ΄ˆκΈ°ν™”(`_init_once()`) λ˜λ„λ‘ 섀계해야 함. `finGraph.py` μ—­μ‹œ 전역이 μ•„λ‹Œ `main()` λ‚΄λΆ€μ—μ„œ λ“œλΌμ΄λ²„λ₯Ό λŸ°νƒ€μž„ μ΄ˆκΈ°ν™”ν•  것.
55
+ - **λ°©μ–΄ ν…ŒμŠ€νŠΈ**: `python -c "import src.retrieval.finRetrieval"` 및 `python -c "import src.graphBuilder.neo4j.finGraph"` λͺ…령을 μ‹€ν–‰ν–ˆμ„ λ•Œ, DB μ—°κ²° μ‹œλ„ 없이 즉각 0.1초 λ§Œμ— 정상 μ’…λ£Œλ˜λŠ”μ§€ 점검 ν›„ 컀밋할 것.
56
+
57
+ - **2. ν”„λ‘œλ•μ…˜ Fail-Fast μžκ°€ 진단 ν•„μˆ˜ (침묡의 λŸ°νƒ€μž„ μ—λŸ¬ λ°©μ§€)**
58
+ - **원인**: ν—ˆκΉ…νŽ˜μ΄μŠ€(HF Spaces) 배포 μ‹œ DB μ—°κ²° ν™˜κ²½ λ³€μˆ˜κ°€ λˆ„λ½λ˜μ—ˆμŒμ—λ„ λΆˆκ΅¬ν•˜κ³  μ›Ή 앱은 μ •μƒμ μœΌλ‘œ μΌœμ§„ μ²™(Running) ν•˜λ‹€κ°€, μ‚¬μš©μžκ°€ 처음 μ§ˆλ¬Έμ„ λ˜μ§„ μˆœκ°„ 500 λ‚΄λΆ€ μ—λŸ¬λ₯Ό 뿜으며 λ»—μ–΄λ²„λ¦¬λŠ” μ‹¬κ°ν•œ 운영 μž₯μ•  λ°œμƒ.
59
+ - **κ·œμΉ™**: 배포 μ§„μž…μ (`app.py`) ꡬ동 μ‹œμ μ—λŠ” μ§€μ—° μ΄ˆκΈ°ν™”λ₯Ό λ¬΄μ‹œν•˜κ³  κ°•μ œλ‘œ μ¦‰μ‹œ μ—°κ²°(`graphrag._init_once()`)을 μ‹œλ„ν•˜μ—¬, μ‹€νŒ¨ μ‹œ μ•± ꡬ동 자체λ₯Ό μ‹€νŒ¨μ‹œν‚€λŠ” `Fail-Fast` μžκ°€ 진단 μ½”λ“œλ₯Ό `app.py` 상단에 λ°˜λ“œμ‹œ μœ μ§€ν•  것.
60
+
61
+ - **3. νŒ¨ν‚€μ§€ μ˜μ‘΄μ„± 및 νƒ€μž… 엄격 검증 (Hugging Face λΉŒλ“œ ν¬λž˜μ‹œ λ°©μ§€)**
62
+ - **원인**: λ‘œμ»¬μ—μ„œλŠ” 잘 λŒμ•„κ°€λŠ”λ°, ν—ˆκΉ…νŽ˜μ΄μŠ€ ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œ `audioop`, `huggingface_hub` λ“± λͺ¨λ“ˆ λˆ„λ½μ΄λ‚˜ MyPy νƒ€μž… μ—λŸ¬(`Format Error`)둜 λŸ°νƒ€μž„ ν¬λž˜μ‹œκ°€ 3회 이상 λ°œμƒ.
63
+ - **κ·œμΉ™**: μƒˆλ‘œμš΄ λΌμ΄λΈŒλŸ¬λ¦¬λ‚˜ κΈ°λŠ₯ μΆ”κ°€ μ‹œ 무쑰건 `requirements.txt`에 λͺ…μ‹œν•  것. 컀밋 직전 `mypy src tests --ignore-missing-imports` 및 `ruff check .`λ₯Ό 돌렀 단 1개의 경고도 남기지 말 것.
64
+ - **λ°©μ–΄ ν…ŒμŠ€νŠΈ**: 컀밋 μ „ 무쑰건 ν„°λ―Έλ„μ—μ„œ `python -c "import app"`을 μ‹€ν–‰ν•˜μ—¬ Gradio λΉŒλ“œ 단계 및 μ˜μ‘΄μ„± μ—λŸ¬κ°€ μ—†λŠ”μ§€ ν˜„μž₯ 점검 ν›„ ν‘Έμ‹œν•  것.
65
+
66
  ## COMMIT κ·œμΉ™
67
  - 컀밋 λ©”μ‹œμ§€: 'feat:', 'fix:', 'refactor:' 접두사 μ‚¬μš©
68
  - push ν•˜λ‚˜μ— ν•˜λ‚˜μ˜ λ³€κ²½λ§Œ
app.py CHANGED
@@ -150,10 +150,11 @@ with gr.Blocks(
150
  "μ–΄λ–€ 기업이 LLM κΈ°μˆ μ„ κ°œλ°œν•˜λ‚˜μš”?",
151
  "졜근 AI κ΄€λ ¨ λ‰΄μŠ€ 기사λ₯Ό μš”μ•½ν•΄μ€˜",
152
  ],
 
153
  retry_btn=None,
154
  undo_btn="↩️ 되돌리기",
155
  clear_btn="πŸ—‘οΈ λŒ€ν™” μ΄ˆκΈ°ν™”",
156
  )
157
 
158
  if __name__ == "__main__":
159
- demo.launch()
 
150
  "μ–΄λ–€ 기업이 LLM κΈ°μˆ μ„ κ°œλ°œν•˜λ‚˜μš”?",
151
  "졜근 AI κ΄€λ ¨ λ‰΄μŠ€ 기사λ₯Ό μš”μ•½ν•΄μ€˜",
152
  ],
153
+ cache_examples=False,
154
  retry_btn=None,
155
  undo_btn="↩️ 되돌리기",
156
  clear_btn="πŸ—‘οΈ λŒ€ν™” μ΄ˆκΈ°ν™”",
157
  )
158
 
159
  if __name__ == "__main__":
160
+ demo.launch(server_name="0.0.0.0", server_port=7860)
src/retrieval/finRetrieval.py CHANGED
@@ -240,6 +240,7 @@ class LazyGraphRAG:
240
 
241
  def search(self, *args: Any, **kwargs: Any) -> Any:
242
  self._init_once()
 
243
  return self._graphrag.search(*args, **kwargs)
244
 
245
  def __getattr__(self, name: str) -> Any:
 
240
 
241
  def search(self, *args: Any, **kwargs: Any) -> Any:
242
  self._init_once()
243
+ assert self._graphrag is not None
244
  return self._graphrag.search(*args, **kwargs)
245
 
246
  def __getattr__(self, name: str) -> Any: