[AC-AISVC-02, AC-AISVC-16] 多个需求合并 #1

Merged
MerCry merged 45 commits from feature/prompt-unification-and-logging into main 2026-02-25 17:17:35 +00:00
3 changed files with 31 additions and 3 deletions
Showing only changes of commit 02f03a3a12 - Show all commits

View File

@ -1,4 +1,5 @@
import request from '@/utils/request'
import { useTenantStore } from '@/stores/tenant'
export interface AIResponse {
content: string
@ -73,6 +74,8 @@ export function createSSEConnection(
const baseUrl = import.meta.env.VITE_APP_BASE_API || '/api'
const fullUrl = `${baseUrl}${url}`
const tenantStore = useTenantStore()
const controller = new AbortController()
fetch(fullUrl, {
@ -80,6 +83,7 @@ export function createSSEConnection(
headers: {
'Content-Type': 'application/json',
'Accept': 'text/event-stream',
'X-Tenant-Id': tenantStore.currentTenantId || '',
},
body: JSON.stringify(body),
signal: controller.signal

View File

@ -44,9 +44,16 @@ class Settings(BaseSettings):
ollama_embedding_model: str = "nomic-embed-text"
rag_top_k: int = 5
rag_score_threshold: float = 0.3
rag_score_threshold: float = 0.01
rag_min_hits: int = 1
rag_max_evidence_tokens: int = 2000
rag_two_stage_enabled: bool = True
rag_two_stage_expand_factor: int = 10
rag_hybrid_enabled: bool = True
rag_rrf_k: int = 60
rag_vector_weight: float = 0.7
rag_bm25_weight: float = 0.3
confidence_low_threshold: float = 0.5
confidence_high_threshold: float = 0.8

View File

@ -61,20 +61,31 @@ class VectorRetriever(BaseRetriever):
RetrievalResult with filtered hits.
"""
logger.info(
f"[AC-AISVC-16] Starting vector retrieval for tenant={ctx.tenant_id}, query={ctx.query[:50]}..."
f"[AC-AISVC-16] Starting vector retrieval for tenant={ctx.tenant_id}, "
f"query={ctx.query[:50]}..."
)
logger.info(
f"[AC-AISVC-16] Retrieval config: top_k={self._top_k}, "
f"score_threshold={self._score_threshold}, min_hits={self._min_hits}"
)
try:
client = await self._get_client()
logger.info(f"[AC-AISVC-16] Got Qdrant client: {type(client).__name__}")
logger.info("[AC-AISVC-16] Generating embedding for query...")
query_vector = await self._get_embedding(ctx.query)
logger.info(f"[AC-AISVC-16] Embedding generated: dim={len(query_vector)}")
logger.info(f"[AC-AISVC-16] Searching in tenant collection: tenant_id={ctx.tenant_id}")
hits = await client.search(
tenant_id=ctx.tenant_id,
query_vector=query_vector,
limit=self._top_k,
score_threshold=self._score_threshold,
)
logger.info(f"[AC-AISVC-16] Search returned {len(hits)} raw hits")
retrieval_hits = [
RetrievalHit(
@ -104,6 +115,12 @@ class VectorRetriever(BaseRetriever):
f"[AC-AISVC-17] Retrieval complete: {len(retrieval_hits)} hits, "
f"insufficient={is_insufficient}, max_score={diagnostics['max_score']:.3f}"
)
if len(retrieval_hits) == 0:
logger.warning(
f"[AC-AISVC-17] No hits found! tenant={ctx.tenant_id}, "
f"query={ctx.query[:50]}..., raw_hits={len(hits)}, threshold={self._score_threshold}"
)
return RetrievalResult(
hits=retrieval_hits,
@ -111,7 +128,7 @@ class VectorRetriever(BaseRetriever):
)
except Exception as e:
logger.error(f"[AC-AISVC-16] Retrieval error: {e}")
logger.error(f"[AC-AISVC-16] Retrieval error: {e}", exc_info=True)
return RetrievalResult(
hits=[],
diagnostics={"error": str(e), "is_insufficient": True},