fix: harden wiki delivery and leaderboard performance
This commit is contained in:
1 parent
4b86106a24
commit
e053b36b6e
28 files changed
+616
-68
No files matched your search
@@ -245,6 +245,33 @@ async def knowledge_base_wiki_index_status(request: Request, mapping_id: str) ->
|
||||
raise HTTPException(status_code=503, detail={"code": "WIKI_INDEX_UNAVAILABLE"})
|
||||
states = await index_store.list_index_status([mapping_id])
|
||||
state = states[0] if states else {"knowledge_base_mapping_id": mapping_id, "state": "not_synced", "index_revision": 0}
|
||||
if (
|
||||
state.get("state") == "idle"
|
||||
and int(state.get("index_revision") or 0) == 0
|
||||
and not state.get("last_completed_at")
|
||||
and not state.get("last_success_at")
|
||||
):
|
||||
state = {**state, "state": "not_synced"}
|
||||
pages = await index_store.list_page_index_status(mapping_id)
|
||||
active_sync_id = str(state.get("active_sync_id") or "")
|
||||
is_running = str(state.get("state") or "") in {"running", "rebuilding"}
|
||||
for page in pages:
|
||||
page["vectorized"] = page.get("index_status") == "ready" and int(page.get("vector_count") or 0) > 0
|
||||
page["processed_in_current_sync"] = bool(active_sync_id) and page.get("last_seen_sync_id") == active_sync_id
|
||||
total_pages = max(int(state.get("remote_page_count") or 0), len(pages))
|
||||
processed_pages = (
|
||||
sum(bool(page["processed_in_current_sync"]) for page in pages)
|
||||
if is_running
|
||||
else total_pages if str(state.get("state") or "") in {"idle", "partial"} else 0
|
||||
)
|
||||
completion_percent = (
|
||||
min(100, round((processed_pages / total_pages) * 100))
|
||||
if total_pages
|
||||
else 100
|
||||
if str(state.get("state") or "") in {"idle", "partial"}
|
||||
and bool(state.get("last_completed_at") or state.get("last_success_at"))
|
||||
else 0
|
||||
)
|
||||
embedding = getattr(request.app.state, "llmwiki_embedding", None)
|
||||
fingerprint = embedding.fingerprint if embedding is not None else None
|
||||
fully_vectorized = bool(mapping.get("wiki_index_enabled", True)) and is_fully_vectorized(state, fingerprint)
|
||||
@@ -255,6 +282,15 @@ async def knowledge_base_wiki_index_status(request: Request, mapping_id: str) ->
|
||||
"wiki_index_enabled": mapping.get("wiki_index_enabled", True),
|
||||
"fully_vectorized": fully_vectorized,
|
||||
"retrieval_mode": "vector" if fully_vectorized else "wiki_api",
|
||||
"progress": {
|
||||
"total_pages": total_pages,
|
||||
"processed_pages": processed_pages,
|
||||
"vectorized_pages": sum(bool(page["vectorized"]) for page in pages),
|
||||
"failed_pages": sum(bool(page.get("last_error")) or page.get("index_status") in {"failed", "stale"} for page in pages),
|
||||
"vector_count": sum(int(page.get("vector_count") or 0) for page in pages),
|
||||
"completion_percent": completion_percent,
|
||||
},
|
||||
"pages": pages,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user