mirror of
https://github.com/coleam00/Archon.git
synced 2025-12-24 02:39:17 -05:00
PR #521: address CodeRabbit review — consistent 401 payload; mask key prefix; accurate reranking_applied; remove unused import
This commit is contained in:
@@ -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}"
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user