PR #521: address CodeRabbit review — consistent 401 payload; mask key prefix; accurate reranking_applied; remove unused import

This commit is contained in:
Tim Carter
2025-08-29 00:08:24 -03:00
parent c3cf1eee94
commit 2c3b8ef95b
3 changed files with 10 additions and 8 deletions

View File

@@ -33,7 +33,6 @@ from ..services.storage import DocumentStorageService
from ..utils import get_supabase_client
from ..services.embeddings.embedding_exceptions import (
EmbeddingAuthenticationError,
EmbeddingQuotaExhaustedError,
)
from ..utils.document_processing import extract_text_from_document
@@ -756,7 +755,7 @@ async def perform_rag_query(request: RagQueryRequest):
raise
except EmbeddingAuthenticationError as e:
safe_logfire_error(f"Authentication error in RAG query: {str(e)}")
raise HTTPException(status_code=401, detail="Invalid API key")
raise HTTPException(status_code=401, detail={"error": "Invalid API key"})
except Exception as e:
safe_logfire_error(
f"RAG query failed | error={str(e)} | query={request.query[:50]} | source={request.source}"
@@ -793,7 +792,7 @@ async def search_code_examples(request: RagQueryRequest):
raise
except EmbeddingAuthenticationError as e:
safe_logfire_error(f"Authentication error in code examples search: {str(e)}")
raise HTTPException(status_code=401, detail="Invalid API key")
raise HTTPException(status_code=401, detail={"error": "Invalid API key"})
except Exception as e:
safe_logfire_error(
f"Code examples search failed | error={str(e)} | query={request.query[:50]} | source={request.source}"

View File

@@ -93,9 +93,10 @@ class EmbeddingAuthenticationError(EmbeddingError):
def __init__(self, message: str, api_key_prefix: str | None = None, **kwargs):
super().__init__(message, **kwargs)
self.api_key_prefix = api_key_prefix
if api_key_prefix:
self.metadata["api_key_prefix"] = api_key_prefix
masked = f"{api_key_prefix[:4]}" if api_key_prefix else None
self.api_key_prefix = masked
if masked:
self.metadata["api_key_prefix"] = masked
class EmbeddingAPIError(EmbeddingError):

View File

@@ -339,11 +339,13 @@ class RAGService:
)
# Apply reranking if we have a strategy
reranking_applied = False
if self.reranking_strategy is not None and results:
try:
results = await self.reranking_strategy.rerank_results(
query, results, content_key="content"
)
reranking_applied = True
except Exception as e:
logger.warning(f"Code reranking failed: {e}")
@@ -367,14 +369,14 @@ class RAGService:
"query": query,
"source_filter": source_id,
"search_mode": "hybrid" if use_hybrid_search else "vector",
"reranking_applied": self.reranking_strategy is not None,
"reranking_applied": reranking_applied,
"results": formatted_results,
"count": len(formatted_results),
}
span.set_attribute("results_found", len(formatted_results))
span.set_attribute("hybrid_used", use_hybrid_search)
span.set_attribute("reranking_used", self.reranking_strategy is not None)
span.set_attribute("reranking_used", reranking_applied)
return True, response_data