[Feat] W4 Community stub + Routing Agent (#20 + #21)#51
Merged
Conversation
W4 ์ธ ๋ฒ์งธ retrieval โ Layer C ์ stub ๊ตฌํ. ์ค์ community detection / ์์ฝ์ W5+ ์์ญ. ๋ณธ ๋ชจ๋์ Routing Agent (#21) ๊ฐ ๊ธ๋ก๋ฒ ์ง์๋ฅผ Layer C ๋ก ๋ถ๊ธฐํ์ ๋์ ์ง์ ์ ํจ์๋ง ์ ๊ณต. ์ค๊ณ ๊ฒฐ์ : - Microsoft GraphRAG ์ Global Search ๋ indexing time ์ฌ์ ์์ฑ community report ์์์ ๋์. ๋ณธ ํ๋ก์ ํธ๋ community detection ์์ฒด๊ฐ ๋ฏธ๊ตฌํ โ community ์๋ฃ ์์ด LLM ๋ง ๊ฐ์ง๊ณ ๊ธ๋ก๋ฒ ๋ต๋ณ ํ๋ด๋ด๋ ๊ฒ์ ์ ์งํ์ง ์์. - stub ์๋ต: ๊ธ๋ก๋ฒ ์ง์ ๋ถ๋ฅ ํ์ธ + Layer C ๋ฏธ๊ตฌํ ๋ช ์ + 5/24+ ETA + ๋์ ์๋ด (Layer A/B ํ์ฉ). - LLM / Neo4j ํธ์ถ ์์ โ ์ฆ์ ์๋ต. @track ์ผ๋ก Opik trace. DoD (#20): - Routing Agent (#21) ์ง์ ์ ํจ์ ์ ๊ณต โ - ์ ์งํ ๋ฏธ๊ตฌํ ์๋ด โ - ์ฆ์ ์๋ต โ ํ์: - ์ค์ Layer C ๊ตฌํ์ ๋ณ๋ ์ด์ (W5+) โ Leiden detection + ์ฌ์ community summary + map-reduce ๋ต๋ณ ํฉ์ฑ. Reference: - Microsoft GraphRAG Global Search (map-reduce) - Sotaaz blog (2026-01) โ hybrid_search() ์ elif is_global ๋ถ๊ธฐ - graphrag.com/reference/global-community-summary-retriever
W5+ ์ค์ Layer C ๊ตฌํ ์ ์ฌ์ฉํ ํ๋กฌํํธ placeholder. ํ์ฌ stub ๋จ๊ณ์์๋ LLM ํธ์ถ์ด ์์ด ๋ณธ ํ๋กฌํํธ๋ ์ค์ ๋ก ์ฌ์ฉ๋์ง ์์ผ๋, ํฅํ ํ์ฑํ ์์ ์ ๋ฐ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ๋๋ก ๊ตฌ์กฐ ๋ฏธ๋ฆฌ ์ ๋ฆฝ. ๋ด์ฉ: - Role ์ ์ (Community report ์ map-reduce ๋ต๋ณ ํฉ์ฑ๊ธฐ) - Input format (W5+ ์ community_reports ๋ฐฐ์ด ์ ๋ ฅ) - Output format (์์ฐ์ด ๋ต๋ณ) - Reference (Microsoft GraphRAG, Tomaz Bratanic) - ํ์ฌ stub ์ํ ๋ช ์
W4 ํตํฉ ์ง์ ์ โ ์ฌ์ฉ์ ์ง๋ฌธ์ ๋ฐ์ Layer A/B/C ๋ก ๋ผ์ฐํ : - t2c (Text2Cypher) โ factual / numerical / topN - local (Local Retriever) โ ๊ด๊ณ / ์ฐ๊ด / co-mention - community (Community Summary stub) โ ๊ธ๋ก๋ฒ / ํธ๋ ๋ 2๋จ๊ณ ๊ตฌ์กฐ: 1. ํค์๋ ๋งค์นญ (๊ฒฐ์ ์ , LLM ํธ์ถ ์์) โ ๋งค์นญ ์์ผ๋ฉด ์ฆ์ ๋ถ๊ธฐ 2. LLM fallback โ ํค์๋ ๋งค์นญ 0๊ฐ ์์๋ง, max_tokens=150 (์งง์) 3. graceful default โ LLM ์คํจ ์ t2c ์ค๊ณ ๊ฒฐ์ : - LangChain MultiRetrievalQAChain ์ LLM router ๋ "same query may route to different sources" (TDS, 2025) ์ผ๊ด์ฑ ๋ฌธ์ . ๊ฒฐ์ ์ 1๋จ๊ณ ์ฐ์ . - ํค์๋ ๋งค์นญ์ ํ ํฐ ๋น์ฉ 0 โ ๋จ์ factual ๋ LLM ํธ์ถ ์์ด ๋ถ๊ธฐ - LLM fallback ์ ์ดํ ํ๊ณ ๋ณด์ โ ํค์๋ ๋ชป ์ก๋ ๋ณํ ํํ ์ฒ๋ฆฌ ํค์๋ ๋งคํ: - ๊ด๊ณ / ๊ด๋ จ / ์ฐ๊ด / ์ํฅ / ํจ๊ป / ์ด์ / ์ด๋ป๊ฒ โ local - ํธ๋ ๋ / ์ ์ฒด / ํ๋ฆ / ์ฃผ์ / ํจํด / ๊ธ๋ก๋ฒ / community โ community - ๊ทธ ์ธ โ t2c (default) Tie-break: ๋ ์ ๋์ ๋งค์นญ ์ ๋ ๋ง์ ์ชฝ (๋๋ฅ ์ด๋ฉด community โ ์ ์ฒด ์๋ ๋ณดํต ๊ธ๋ก๋ฒ). Reference: - LangChain MultiRetrievalQAChain (LLM router) - LangChain EmbeddingRouterChain (semantic router โ 5/24+ ๊ฒํ ) - Neo4j ToolsRetriever (convert_to_tool ํจํด) - NeoConverse (specialized ์์ผ๋ฉด Text2Cypher fallback) - Sotaaz blog (2026-01) โ hybrid_search() if/elif/else ํจํด - Memgraph Atomic GraphRAG (2026-03) โ Analytical/Local/Global 3-way ํฅํ (5/24+): - Semantic Router (embedding) โ ํค์๋ ์ดํ ํ๊ณ ๋ณด์ - LLM fallback ์ ๋ขฐ๋ ์ ์ํ โ dual-path ํฉ์ฑ - Conversation history ๋ฐ์
ํค์๋ ๋งค์นญ 0๊ฐ ์ LLM ์ผ๋ก ๋ผ์ฐํ
๊ฒฐ์ ํ ๋ ์ฌ์ฉํ๋ system prompt.
๊ตฌ์ฑ:
- 3๊ฐ์ง retriever ์ ์ + ์์ ์ง๋ฌธ
- ๋ถ๋ฅ ๊ธฐ์ค (์์๋๋ก ํ๋จ)
- Output format (JSON: route + reasoning)
- 5๊ฐ few-shot ์์ (t2c x 2, local x 2, community x 1)
ํน์ง:
- max_tokens=150 โ ์งง์ ์๋ต๋ง ๋ฐ์
- temperature=0.0 โ ๊ฒฐ์ ์ ๋ผ์ฐํ
- response_format={"type": "json_object"} ๊ฐ์
- LLM ์คํจ / unknown route ์ caller ๊ฐ default (t2c) ๋ก fallback
, #21) ์ ๊ท export: - DEFAULT_ROUTE, Route (ํ์ ) - RouteDecision, RoutedResult (๊ฒฐ๊ณผ ๊ฐ์ฒด) - decide_route, route_and_answer (์ง์ ์ ) - CommunitySummaryResult, community_summary (stub) ๊ถ์ฅ ์ง์ ์ ์ `route_and_answer(question)` โ ์ผ๋ฐ ์ฌ์ฉ ์ ๋ผ์ฐํ ์๋. ๊ฐ๋ณ retriever ํจ์๋ ๊ทธ๋๋ก export ์ ์ง โ ๋ช ์์ ํ ์คํธ / ์ง์ ํธ์ถ ์ ์ฌ์ฉ. sha ์ถฉ๋ ๊ฐ๋ฅ์ฑ 0 (dev branch ์ __init__.py ์ ๋ค๋ฅธ ํ์ผ).
R1~R3 ํ๊ฐ ์ : - R1 (Q2 ๋์ผ) โ factual / ๊ฐ์ โ t2c ๋ผ์ฐํ ๊ธฐ๋. ํค์๋ ๋งค์นญ 0๊ฐ๋ผ LLM fallback ํธ๋ฆฌ๊ฑฐ์ ๊ฒ์ฆ ์ผ์ด์ค๋ ๊ฒธํจ. - R2 (L1 ๋ณํ) โ "๊ด๊ณ/๊ด๋ จ/์ด๋ป๊ฒ/ํจ๊ป" ํค์๋ 4์ค ๋งค์นญ โ local ๊ธฐ๋. - R3 (L5 ๋์ผ) โ "์ ์ฒด/ํธ๋ ๋/ํ๋ฆ" ํค์๋ ๋งค์นญ โ community (stub) ๊ธฐ๋. eval ์คํฌ๋ฆฝํธ ๋ณ๊ฒฝ: - EvalCase ์ expected_route ํ๋ ์ถ๊ฐ (R* ์ผ์ด์ค ์ ์ฉ) - _evaluate_router_case() ์ถ๊ฐ โ ๋ผ์ฐํ ์ ํ์ฑ + answer ์ฑ์์ง + hint ๊ฒ์ฆ - CaseEvalResult ์ router ์ ์ฉ ํ๋ (actual_route, matched_keywords, llm_used, llm_reasoning) ์ถ๊ฐ - _print_summary_table ์ Routing ๊ฒฐ๊ณผ ํ ์ถ๊ฐ (expected vs actual, match ํ์, LLM ์ฌ์ฉ ์ฌ๋ถ, ๋งค์นญ ํค์๋) - --suite router ์ต์ ์ถ๊ฐ - ๋ผ์ฐํ ํ๊ท ์๋ต ์๊ฐ + ์ ํ๋ ํ์ ์ ์ผ์ด์ค๋ฅผ ๋ณ๋ ๋ง๋ค์ง ์๊ณ Q2/L1/L5 ์ ์๋ ์ฌํ์ฉ โ ๋ฐํ ์๋ฃ ์ผ๊ด์ฑ + ๋น ๋ฅธ ๊ฒ์ฆ. R1 ์ ํค์๋ 0๊ฐ๋ผ LLM fallback / default(t2c) ๊ฒฝ๋ก ๊ฒ์ฆ ๊ฒธํจ.
Owner
Author
์ ์ฑ ๊ฒ์ฆ ๊ฒฐ๊ณผ (5/17 10:02 KST ๋ก์ปฌ ์คํ)3/3 PASS ยท ๋ผ์ฐํ ์ ํ๋ 100% ยท ์ ์ฒด 12.8s ยท Routing ํ๊ท 4.3s
R1 โ LLM fallback ํธ๋ฆฌ๊ฑฐ โ
R2 โ ํค์๋ 3์ค ๋งค์นญ + graceful fallback โ
R3 โ Community stub ์ฆ์ ์๋ต โ
Opik trace
๋ฐ์ commit
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
์์ฝ
W4 ๋ง๋ฌด๋ฆฌ. Layer C (Community Summary) stub + Layer A/B/C ํตํฉ ๋ผ์ฐํ ์์ด์ ํธ ๋ฐ์ .
Closes #20, closes #21.
PR #49 (#19 Local Retriever) ๋จธ์ง ์งํ ์งํ โ ์๋๋ฆฌ์ค A ์ 5/18 ์ผ์ ์ ํ๋ฃจ ๋น๊ฒจ 5/17 ์์ W4 ์ ์ฒด ์๋ฃ.
๋ณ๊ฒฝ ์ฌํญ
์ ๊ท (4)
retrieval/community_summary.pyโ Layer C stub ์ง์ ์ (@track, 138 lines, LLM/Neo4j ํธ์ถ 0ํ)retrieval/prompts/community_summary_v1.mdโ W5+ ์ค์ ๊ตฌํ ์ ์ฑ์ธ placeholderretrieval/router.pyโ Routing Agent (decide_route,route_and_answer, 424 lines)retrieval/prompts/router_v1.mdโ LLM fallback system prompt + 5 few-shot์์ (2)
retrieval/__init__.pyโ ์ ๊ท export 8๊ฐ (DEFAULT_ROUTE,Route,RouteDecision,RoutedResult,decide_route,route_and_answer,CommunitySummaryResult,community_summary)scripts/run_w4_eval.pyโexpected_routeํ๋ + R1~R3 ์ผ์ด์ค +--suite router+ routing ๊ฒฐ๊ณผ ํ๋ฐ์ (1)
docs/weekly-log/2026-05-17-community-router.mdโ ์์ ์ปจํ ์คํธ + ๋ ํผ๋ฐ์ค ํ + ์ค๊ณ ๊ฒฐ์ + ํ๊ฐ ์ + ๋ฐํ ์ฌ๋ผ์ด๋ 14 ์ฐ๊ฒฐ์ค๊ณ ๊ฒฐ์
#20 Community Summary โ ์์ stub
CommunitySummaryResult(answer, is_stub=True)โ ๋ฏธ๋ ์ง์ง Layer C ์ ์๊ทธ๋์ฒ ํธํ.#21 Routing Agent โ ํค์๋ ๋ถ๊ธฐ + LLM fallback
MultiRetrievalQAChain์ LLM router ๋ "the same query may route to different sources" (TDS 2025) ์ผ๊ด์ฑ ๋ฌธ์ . ๊ฒฐ์ ์ ๋ถ๊ธฐ๋ฅผ 1๋จ๊ณ๋ก ๋๋ฉด ๋๋ฒ๊น / ํ๊ฐ / ๋ฐํ ์์ฐ ๋ชจ๋ ๋ช ํ.ํค์๋ ๋งคํ:
LOCAL_KEYWORDS(11๊ฐ): ๊ด๊ณ, ๊ด๋ จ, ์ฐ๊ด, ์ํฅ, ํจ๊ป, ์ด์, ์ด๋ป๊ฒ, co-mention, ๊ด๊ณ๋, ๊ด๋ จ๋, ์ฐ๊ด๋COMMUNITY_KEYWORDS(17๊ฐ): ํธ๋ ๋, ์ ์ฒด, ํ๋ฆ, ์ฃผ์ ํธ๋ ๋, ์ฃผ์ , ํจํด, ์ฃผ์ ํ๋ฆ, ์ ๋ฐ, ๊ธ๋ก๋ฒ, community, communities, topic, topics, themes, ์ ์ฒด์ , ํตํฉ, ์ฌ์ ์ฒดํ๊ฐ ์ R1~R3
t2clocalcommunity๊ฒ์ฆ ๋ช ๋ น
DoD
#20 Community Summary stub
community_summary(question)์ง์ ์ CommunitySummaryResult์๊ทธ๋์ฒ ๋ฐ์ (is_stub=True)@trackOpik trace#21 Routing Agent
_classify_by_keywords)_classify_by_llm) โ JSON ์๋ต ๊ฐ์ , tenacity 2 attemptsroute_and_answer(@track)--suite router์ต์ ๋ฐํ ์ฌ๋ผ์ด๋ 14 (Routing ๋ช ๋ถ) ๊ฐํ
PR #49 ๊น์ง: L5 PASS ๋ง ์์์ (local_retriever ๋ด๋ถ์ "Layer C ์ ํฉ ์๋ด" fallback).
๋ณธ PR ๋จธ์ง ํ:
matched_keywords,llm_usedํ๋) + Layer C stub ์๋ตํ์ (๋ณธ PR ์ค์ฝํ ์ธ)
EmbeddingRouterChainํจํด)