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))