refactor: migrate to httpx and remove RAGAnything/LightRAG pipeline#52
Conversation
- Add BRICKS_HTTP_TIMEOUT and Kreuzberg extraction/quality config - Extract FastAPI error handlers into dedicated module - Handle ExtractionTimeoutError in Kreuzberg adapter - Use structured error messages in MCP tools
Replace the hardcoded VLM timeout value with the new KREUZBERG_VLM_TIMEOUT config setting and refactor the adapter to read the overall extraction timeout from the config object instead of instantiating RAGConfig again.
Upgrade kreuzberg dependency to >=4.9.9 and log extraction errors before raising domain exceptions.
- Replace urllib with httpx.AsyncClient in BricksApiAdapter (persistent client with aclose in lifespan, raise_for_status, idiomatic error handling via HTTPStatusError/ConnectError/TimeoutException). - Remove RAGAnything/LightRAG (HKUDS) pipeline entirely: lightrag_adapter, kreuzberg_raganything_parser, pg_textsearch_adapter, indexing/query routes, mcp_query_tools, RAGAnything use cases, rag_engine port, rag domain errors, alembic migrations, rag_storage working dir. - Introduce KreuzbergConfig (extracted from RAGConfig) for shared Kreuzberg extraction settings used by Files/Bricks/Classical. - Rename MCP servers: RAGAnythingFiles -> Files, RAGAnythingBricks -> Bricks, RAGAnythingClassical -> ClassicalRAG. Drop /rag/mcp endpoint. - Drop alembic + mako + sqlalchemy[asyncio] (migrations handled by langchain-postgres for Classical). Drop raganything, lightrag-hku, mineru[core], torch, torchvision, aiohttp, openai, pgvector from pyproject. Remove Apache AGE build from Dockerfile.db and libgomp1 from Dockerfile. - Rewrite all tests in Arrange/Act/Assert style with inline comments. - Fix SonarQube blockers: Annotated FastAPI dependency injection, cognitive complexity, empty methods, unused variables, async handlers without await. - Bump cryptography>=48.0.1, langsmith>=0.8.18, pydantic-settings>=2.14.2 to fix Trivy HIGH/MEDIUM CVEs. Tests: 334 passed. SonarQube: 0 OPEN issues. Trivy: 0 vulnerabilities.
Resolved conflicts keeping our (httpx refactor) version for: - bricks_api_adapter.py (httpx + X-API-Key already integrated) - kreuzberg_adapter.py (helpers + timing logs already integrated) - messages.py (KREUZBERG_EXTRACTION/SERIALIZATION_DURATION already added) - test_bricks_api_adapter.py (httpx mocks + X-API-Key assertion) - pyproject.toml (kreuzberg>=4.9.9 already bumped; drop explicit idna as it stays transitive via httpx/httpcore) - uv.lock regenerated via `uv lock` (126 packages resolved) Deleted by us (kept deletion): src/infrastructure/rag/lightrag_adapter.py, tests/unit/test_lightrag_adapter.py (RAGAnything pipeline removed). Changes from main (#50 bump kreuzberg to 4.9.9 + add timing logs, #51 switch auth header to X-API-Key) were already present in this refactor branch, so the merge tree is identical to our HEAD. Verified: ruff check passed, mypy 48 pre-existing errors (no regression), 334 pytest passed.
PR Review —
|
| Critère | Note |
|---|---|
| Cohérence migration httpx | 9/10 |
| Suppression RAGAnything | 9/10 |
| SonarQube / Trivy fixes | 9/10 |
| Tests AAA + coverage | 7/10 (placement de commentaires à corriger) |
| Gestion d'erreurs httpx | 6/10 (le point #1 est important) |
| Documentation (body, .env) | 7/10 (#2 à clarifier) |
Verdict : request changes sur les points #1 et #2. Une fois corrigés + #3/#7 adressés, c'est mergeable.
Summary
Three-part refactor of the mcp-raganything service:
1. Migrate
urllib→httpxinBricksApiAdapterurllib.requestwithhttpx.AsyncClient(persistent client created at__init__, closed viaaclose()in FastAPI lifespan).raise_for_status()for idiomatic HTTP error handling (HTTPStatusError,ConnectError,TimeoutException).asyncio.to_thread(native async calls).2. Remove RAGAnything / LightRAG (HKUDS) pipeline
lightrag_adapter,kreuzberg_raganything_parser,pg_textsearch_adapter,indexing_routes,query_routes,mcp_query_tools, 4 RAGAnything use cases, DTOs,rag_engineport,ragdomain errors,alembic/migrations,rag_storage/.KreuzbergConfig(extracted fromRAGConfig) for shared Kreuzberg extraction settings used by Files / Bricks / Classical.RAGAnythingFiles->Files,RAGAnythingBricks->Bricks,RAGAnythingClassical->ClassicalRAG. Drop/rag/mcpendpoint.pyproject.toml:raganything,lightrag-hku,mineru[core],torch,torchvision,alembic,mako,sqlalchemy[asyncio],aiohttp,openai,pgvector.Dockerfile: droplibgomp1+UV_TORCH_BACKEND=cpu.Dockerfile.db: drop Apache AGE build..env.example: drop LightRAG variables.3. Rewrite tests in Arrange/Act/Assert style
# Arrange/# Act/# Assertcomments. Logic and assertions preserved.SonarQube / Trivy fixes (pre-existing issues also addressed)
S8410: FastAPIAnnotateddependency injection across all surviving routes.S3776: cognitive complexity inclassical_query_use_case,kreuzberg_adapter,bricks_api_adapter.S1186: empty methods, unused variables.S7503: 24asynchandlers withoutawaitconverted to sync.cryptography>=48.0.1,langsmith>=0.8.18,pydantic-settings>=2.14.2to fix Trivy HIGH/MEDIUM CVEs.QA tests updated
test_mcp_endpoints.py: removed/rag/mcp/tests, added/rag/mcp404 check, renamed server assertions.test_mcp_bricks_endpoints.py: updated server name assertion + session isolation tests.Verification
publish_section_versionschema mismatch, unrelated to this refactor)Breaking changes
/rag/mcpendpoint removed (RAGAnythingQuery MCP server).RAGAnythingFiles->Files,RAGAnythingBricks->Bricks,RAGAnythingClassical->ClassicalRAG.RAG_STORAGE_TYPE,COSINE_THRESHOLD,MAX_CONCURRENT_FILES,MAX_WORKERS,DOCUMENT_PARSER,ENABLE_IMAGE_PROCESSING,ENABLE_TABLE_PROCESSING,ENABLE_EQUATION_PROCESSING.