-
Notifications
You must be signed in to change notification settings - Fork 92
refactor(backend): remove local RAG mode and use knowledge_runtime exclusively #1013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7575b11
0216e1c
6f8a37b
254ad33
92193e5
1fd834b
44fc8ea
58e573f
f043c64
64c20d5
0b71f96
1de10be
bf2053a
2205a1a
88f36d5
c9a47b7
6598317
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,18 +15,11 @@ | |||||||||||||||||
| from app.schemas.kind import Retriever | ||||||||||||||||||
| from app.services.adapters.retriever_kinds import retriever_kinds_service | ||||||||||||||||||
| from app.services.rag.gateway_factory import get_query_gateway | ||||||||||||||||||
| from app.services.rag.local_gateway import LocalRagGateway | ||||||||||||||||||
| from app.services.rag.remote_gateway import RemoteRagGatewayError | ||||||||||||||||||
| from app.services.rag.remote_gateway import RemoteRagGateway, RemoteRagGatewayError | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the gateway factory and map remote storage-type failures. Directly constructing Proposed update-from app.services.rag.remote_gateway import RemoteRagGateway, RemoteRagGatewayError
+from app.services.rag.remote_gateway import RemoteRagGatewayError
@@
def _check_rag_available():
@@
)
+
+
+async def _get_storage_types_or_503():
+ """Fetch storage types from knowledge_runtime or map failures to 503."""
+ try:
+ return await get_query_gateway().get_storage_types()
+ except RemoteRagGatewayError as exc:
+ logger.warning(
+ "Failed to fetch storage types from knowledge_runtime",
+ extra={"error_type": type(exc).__name__},
+ )
+ raise HTTPException(
+ status_code=503,
+ detail="RAG knowledge runtime is unavailable",
+ ) from exc
@@
- gateway = RemoteRagGateway()
- response = await gateway.get_storage_types()
+ response = await _get_storage_types_or_503()
@@
- gateway = RemoteRagGateway()
- response = await gateway.get_storage_types()
+ response = await _get_storage_types_or_503()Also applies to: 58-59, 93-94 🤖 Prompt for AI Agents |
||||||||||||||||||
| from app.services.rag.runtime_specs import ConnectionTestRuntimeSpec | ||||||||||||||||||
| from knowledge_engine.storage.factory import ( | ||||||||||||||||||
| create_storage_backend_from_config, | ||||||||||||||||||
| get_all_storage_retrieval_methods, | ||||||||||||||||||
| get_supported_retrieval_methods, | ||||||||||||||||||
| get_supported_storage_types, | ||||||||||||||||||
| ) | ||||||||||||||||||
| from shared.models import RuntimeRetrieverConfig | ||||||||||||||||||
|
|
||||||||||||||||||
| # RAG module is heavy (llama_index, scipy, pandas, grpc) - skip in standalone mode | ||||||||||||||||||
| # RAG requires knowledge_runtime service - skip in standalone mode | ||||||||||||||||||
|
|
||||||||||||||||||
| router = APIRouter() | ||||||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||||||
|
|
@@ -43,7 +36,7 @@ def _check_rag_available(): | |||||||||||||||||
|
|
||||||||||||||||||
| # Static routes must be defined before dynamic routes to avoid conflicts | ||||||||||||||||||
| @router.get("/storage-types/retrieval-methods") | ||||||||||||||||||
| def get_storage_retrieval_methods(): | ||||||||||||||||||
| async def get_storage_retrieval_methods(): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Get supported retrieval methods for all storage types. | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -61,14 +54,25 @@ def get_storage_retrieval_methods(): | |||||||||||||||||
| } | ||||||||||||||||||
| """ | ||||||||||||||||||
| _check_rag_available() | ||||||||||||||||||
|
|
||||||||||||||||||
| gateway = RemoteRagGateway() | ||||||||||||||||||
| response = await gateway.get_storage_types() | ||||||||||||||||||
|
|
||||||||||||||||||
| # Convert StorageTypesResponse to the expected format | ||||||||||||||||||
| data = { | ||||||||||||||||||
| type_info.type: type_info.retrieval_methods | ||||||||||||||||||
| for type_info in response.storage_types | ||||||||||||||||||
| } | ||||||||||||||||||
| storage_types = [type_info.type for type_info in response.storage_types] | ||||||||||||||||||
|
|
||||||||||||||||||
| return { | ||||||||||||||||||
| "data": get_all_storage_retrieval_methods(), | ||||||||||||||||||
| "storage_types": get_supported_storage_types(), | ||||||||||||||||||
| "data": data, | ||||||||||||||||||
| "storage_types": storage_types, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| @router.get("/storage-types/{storage_type}/retrieval-methods") | ||||||||||||||||||
| def get_storage_type_retrieval_methods(storage_type: str): | ||||||||||||||||||
| async def get_storage_type_retrieval_methods(storage_type: str): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Get supported retrieval methods for a specific storage type. | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -86,14 +90,22 @@ def get_storage_type_retrieval_methods(storage_type: str): | |||||||||||||||||
| """ | ||||||||||||||||||
| _check_rag_available() | ||||||||||||||||||
|
|
||||||||||||||||||
| try: | ||||||||||||||||||
| methods = get_supported_retrieval_methods(storage_type) | ||||||||||||||||||
| return { | ||||||||||||||||||
| "storage_type": storage_type, | ||||||||||||||||||
| "retrieval_methods": methods, | ||||||||||||||||||
| } | ||||||||||||||||||
| except ValueError as e: | ||||||||||||||||||
| raise HTTPException(status_code=400, detail=str(e)) | ||||||||||||||||||
| gateway = RemoteRagGateway() | ||||||||||||||||||
| response = await gateway.get_storage_types() | ||||||||||||||||||
|
|
||||||||||||||||||
| # Find the storage type in the response (case-insensitive comparison) | ||||||||||||||||||
| for type_info in response.storage_types: | ||||||||||||||||||
| if type_info.type.casefold() == storage_type.casefold(): | ||||||||||||||||||
| return { | ||||||||||||||||||
| "storage_type": type_info.type, # Return normalized form from registry | ||||||||||||||||||
| "retrieval_methods": type_info.retrieval_methods, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| raise HTTPException( | ||||||||||||||||||
| status_code=400, | ||||||||||||||||||
| detail=f"Unsupported storage type: {storage_type}. " | ||||||||||||||||||
| f"Supported types: {[t.type for t in response.storage_types]}", | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| @router.get("") | ||||||||||||||||||
|
|
@@ -259,15 +271,6 @@ async def test_retriever_connection( | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| try: | ||||||||||||||||||
| create_storage_backend_from_config( | ||||||||||||||||||
| storage_type=storage_type, | ||||||||||||||||||
| url=url, | ||||||||||||||||||
| username=username, | ||||||||||||||||||
| password=password, | ||||||||||||||||||
| api_key=api_key, | ||||||||||||||||||
| index_strategy={"mode": "per_dataset"}, | ||||||||||||||||||
| ext={}, | ||||||||||||||||||
| ) | ||||||||||||||||||
| runtime_spec = ConnectionTestRuntimeSpec( | ||||||||||||||||||
| retriever_config=RuntimeRetrieverConfig( | ||||||||||||||||||
| name="connection-test", | ||||||||||||||||||
|
|
@@ -284,14 +287,15 @@ async def test_retriever_connection( | |||||||||||||||||
| ) | ||||||||||||||||||
| ) | ||||||||||||||||||
| gateway = get_query_gateway() | ||||||||||||||||||
| try: | ||||||||||||||||||
| return await gateway.test_connection(runtime_spec) | ||||||||||||||||||
| except RemoteRagGatewayError: | ||||||||||||||||||
| return await LocalRagGateway().test_connection(runtime_spec) | ||||||||||||||||||
| return await gateway.test_connection(runtime_spec) | ||||||||||||||||||
|
|
||||||||||||||||||
| except ValueError as e: | ||||||||||||||||||
| return {"success": False, "message": str(e)} | ||||||||||||||||||
|
|
||||||||||||||||||
| except RemoteRagGatewayError as e: | ||||||||||||||||||
| logger.error(f"Retriever connection test failed: {str(e)}") | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify Ruff no longer reports RUF010 for this file.
uv run ruff check backend/app/api/endpoints/adapter/retrievers.py --select RUF010Repository: wecode-ai/Wegent Length of output: 102 🏁 Script executed: # First, examine the specific file and line
cat -n backend/app/api/endpoints/adapter/retrievers.py | sed -n '290,305p'Repository: wecode-ai/Wegent Length of output: 618 🏁 Script executed: # Check if ruff is available as a direct command
which ruff && ruff --versionRepository: wecode-ai/Wegent Length of output: 105 🏁 Script executed: # If ruff is available, check for RUF010 violations in the file
ruff check backend/app/api/endpoints/adapter/retrievers.py --select RUF010 2>&1 || echo "Command failed or no violations found"Repository: wecode-ai/Wegent Length of output: 1868 🏁 Script executed: # Get more context around line 301 to understand the fix needed
cat -n backend/app/api/endpoints/adapter/retrievers.py | sed -n '299,302p'Repository: wecode-ai/Wegent Length of output: 252 Fix the Ruff RUF010 logging warnings. Use lazy logging for logger calls instead of f-string interpolation. Line 301 requires a different approach since it's not a logger call. Proposed updates except RemoteRagGatewayError as e:
- logger.error(f"Retriever connection test failed: {str(e)}")
+ logger.error("Retriever connection test failed: %s", e)
return {"success": False, "message": str(e)}
except Exception as e:
- logger.error(f"Retriever connection test failed: {str(e)}")
- return {"success": False, "message": f"Connection failed: {str(e)}"}
+ logger.error("Retriever connection test failed: %s", e)
+ return {"success": False, "message": f"Connection failed: {e!s}"}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.15.10)[warning] 296-296: Use explicit conversion flag Replace with conversion flag (RUF010) 🤖 Prompt for AI Agents |
||||||||||||||||||
| return {"success": False, "message": str(e)} | ||||||||||||||||||
|
|
||||||||||||||||||
| except Exception as e: | ||||||||||||||||||
| logger.error(f"Retriever connection test failed: {str(e)}") | ||||||||||||||||||
| return {"success": False, "message": f"Connection failed: {str(e)}"} | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.