feat: improve knowledge sync and entity alignment
This commit is contained in:
1 parent
7dbac9cc56
commit
dea4697ea0
38 files changed
+3742
-634
No files matched your search
@@ -255,7 +255,10 @@ def _schedule_local_wiki_sync(request: Request, mapping: dict[str, Any]) -> None
|
||||
if service is not None and config.enabled and config.auto_sync and mapping.get("wiki_index_enabled", True):
|
||||
from app.gateway.llmwiki_index_scheduler import spawn_local_wiki_index_job
|
||||
|
||||
spawn_local_wiki_index_job(request.app, service.sync_mapping(mapping, force=True))
|
||||
# Event-driven refresh is incremental. Content hash + embedding
|
||||
# fingerprint decide which pages need encoding; unchanged Wiki pages
|
||||
# must retain and reuse their existing vectors.
|
||||
spawn_local_wiki_index_job(request.app, service.sync_mapping(mapping, force=False))
|
||||
|
||||
|
||||
async def _actor(request: Request) -> tuple[str, bool]:
|
||||
@@ -3058,6 +3061,7 @@ async def create_knowledge_base(request: Request, body: KnowledgeBaseCreate) ->
|
||||
except Exception:
|
||||
logger.exception("Failed to compensate orphan WeKnora knowledge base")
|
||||
raise HTTPException(status_code=500, detail="Failed to register the knowledge base") from None
|
||||
_schedule_local_wiki_sync(request, row)
|
||||
return _mapping_view(row, remote, actor_user_id=user_id, is_admin=is_admin)
|
||||
|
||||
|
||||
@@ -3345,12 +3349,14 @@ async def upload_document(request: Request, mapping_id: str, file: UploadFile =
|
||||
if not file.filename:
|
||||
raise HTTPException(status_code=422, detail="File name is required")
|
||||
try:
|
||||
return await _client_or_503().upload_document(
|
||||
result = await _client_or_503().upload_document(
|
||||
str(row["weknora_id"]),
|
||||
filename=file.filename,
|
||||
content=content,
|
||||
content_type=file.content_type or "application/octet-stream",
|
||||
)
|
||||
_schedule_local_wiki_sync(request, row)
|
||||
return result
|
||||
except WeKnoraError as exc:
|
||||
_raise_upstream(exc)
|
||||
|
||||
@@ -3362,7 +3368,9 @@ async def import_document_url(request: Request, mapping_id: str, body: Knowledge
|
||||
if not url.lower().startswith(("http://", "https://")):
|
||||
raise HTTPException(status_code=422, detail="URL must start with http:// or https://")
|
||||
try:
|
||||
return await _client_or_503().import_document_url(str(row["weknora_id"]), url=url)
|
||||
result = await _client_or_503().import_document_url(str(row["weknora_id"]), url=url)
|
||||
_schedule_local_wiki_sync(request, row)
|
||||
return result
|
||||
except WeKnoraError as exc:
|
||||
_raise_upstream(exc)
|
||||
|
||||
@@ -3371,11 +3379,13 @@ async def import_document_url(request: Request, mapping_id: str, body: Knowledge
|
||||
async def create_manual_document(request: Request, mapping_id: str, body: ManualKnowledgeCreate) -> dict[str, Any]:
|
||||
row, _, _ = await _authorized_mapping(request, mapping_id, write=True)
|
||||
try:
|
||||
return await _client_or_503().create_manual_document(
|
||||
result = await _client_or_503().create_manual_document(
|
||||
str(row["weknora_id"]),
|
||||
title=body.title.strip(),
|
||||
content=body.content,
|
||||
)
|
||||
_schedule_local_wiki_sync(request, row)
|
||||
return result
|
||||
except WeKnoraError as exc:
|
||||
_raise_upstream(exc)
|
||||
|
||||
@@ -3387,6 +3397,7 @@ async def delete_document(request: Request, mapping_id: str, document_id: str) -
|
||||
try:
|
||||
await _verify_document(client, row, document_id)
|
||||
await client.delete_document(document_id)
|
||||
_schedule_local_wiki_sync(request, row)
|
||||
except WeKnoraError as exc:
|
||||
_raise_upstream(exc)
|
||||
|
||||
@@ -3397,7 +3408,9 @@ async def reprocess_document(request: Request, mapping_id: str, document_id: str
|
||||
client = _client_or_503()
|
||||
try:
|
||||
await _verify_document(client, row, document_id)
|
||||
return await client.reprocess_document(document_id)
|
||||
result = await client.reprocess_document(document_id)
|
||||
_schedule_local_wiki_sync(request, row)
|
||||
return result
|
||||
except WeKnoraError as exc:
|
||||
_raise_upstream(exc)
|
||||
|
||||
|
||||
Reference in new issue
Block a user