From 3ed52b0424d75b626510bc975031c9e9505fa6dc Mon Sep 17 00:00:00 2001 From: OG T Date: Fri, 10 Apr 2026 09:00:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(rag):=20=5Frun=5Findex=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20index=5Fdocument=20=E7=B0=BD=E5=90=8D=E4=B8=8D=E7=AC=A6=20?= =?UTF-8?q?=E2=80=94=20=E8=AE=80=E6=AA=94=E5=85=A7=E5=AE=B9=E5=86=8D?= =?UTF-8?q?=E5=82=B3=20service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/api/v1/rag.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/api/src/api/v1/rag.py b/apps/api/src/api/v1/rag.py index 6aa8b1bf4..26fb1fae9 100644 --- a/apps/api/src/api/v1/rag.py +++ b/apps/api/src/api/v1/rag.py @@ -87,15 +87,19 @@ async def _run_index() -> None: for source_dir in sources: if not source_dir.exists(): continue - pattern = "*.md" - for md_file in source_dir.glob(pattern): + for md_file in source_dir.glob("*.md"): try: - count = await svc.index_document( - file_path=md_file, - source_type=source_dir.parts[0] if len(source_dir.parts) == 1 else source_dir.parts[1], + text = md_file.read_text(encoding="utf-8", errors="ignore") + source_type = source_dir.parts[-1] # e.g. "runbooks", "adr", "skills" + ok = await svc.index_document( + source=source_type, + source_id=str(md_file), + title=md_file.stem, + text=text, ) - total += count - logger.debug("rag_indexed", file=str(md_file), chunks=count) + if ok: + total += 1 + logger.debug("rag_indexed", file=str(md_file)) except Exception as e: logger.warning("rag_index_file_failed", file=str(md_file), error=str(e))