fix(digest): multi-word ai_sub_group matching + NYT_API_KEY example

- loader.py: first-token + all-but-last-token 이중 키 매칭 (Le Monde, Der Spiegel 대응)
- chunk_worker.py: startswith 매칭 보강
- credentials.env.example: NYT_API_KEY 항목 추가

핫픽스 — 단계 3에서 news_source_id FK 정규화로 문자열 매칭 제거 예정

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-04-13 14:33:04 +09:00
parent 5038007998
commit 6b189f0d47
3 changed files with 21 additions and 4 deletions
+14 -3
View File
@@ -74,19 +74,30 @@ def _to_numpy_embedding(raw: Any) -> np.ndarray | None:
async def _load_source_country_map(session) -> dict[str, str]:
"""news_sources name → country 매핑.
"""news_sources name → country 매핑 (핫픽스).
name 은 '경향신문 문화' 형태이고 documents.ai_sub_group 은 '경향신문' (split[0]).
prefix 매칭이 가능하도록 첫 토큰 → country 로 인덱싱.
⚠ 문자열 기반 매칭 — 단계 3에서 news_source_id FK로 교체 예정.
first-token + all-but-last-token 이중 키로 multi-word source 대응.
"""
rows = await session.execute(_SOURCE_COUNTRY_SQL)
mapping: dict[str, str] = {}
for name, country in rows:
if not name or not country:
continue
# first token: "Le", "Der", "경향신문", "NYT"
prefix = name.split(" ")[0].strip()
if prefix and prefix not in mapping:
mapping[prefix] = country
# all-but-last-token: "Le Monde", "Der Spiegel" (마지막 = 카테고리)
tokens = name.split(" ")
if len(tokens) >= 3:
source_prefix = " ".join(tokens[:-1]).strip()
if source_prefix and source_prefix not in mapping:
mapping[source_prefix] = country
# 임시 디버그 — entry 수만 로그 (mapping 전체 출력은 운영 노이즈)
# 단계 3-1 news_source_id 전환 후 이 함수 자체 삭제
import logging
logging.getLogger("digest_loader").debug(f"source_country_map: {len(mapping)} entries")
return mapping
+4 -1
View File
@@ -276,7 +276,10 @@ async def _lookup_news_source(
result = await session.execute(select(NewsSource))
sources = result.scalars().all()
for src in sources:
if src.name.split(" ")[0] == source_name:
if source_name and (
src.name.split(" ")[0] == source_name
or src.name.startswith(source_name + " ")
):
return src.country, src.name, src.language
return None, source_name, None
+3
View File
@@ -45,5 +45,8 @@ KORDOC_ENDPOINT=http://kordoc-service:3100
JWT_SECRET=
TOTP_SECRET=
# ─── 뉴스 수집: NYT API ───
NYT_API_KEY=
# ─── 국가법령정보센터 (법령 모니터링) ───
LAW_OC=