feat: export reproducible retrieval history snapshots
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from fastapi.responses import Response
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.session import get_db
|
||||
from app.models import RetrievalRun
|
||||
from app.schemas.catalog import Page
|
||||
from app.schemas.exports import ExportHistory
|
||||
from app.schemas.hybrid import (
|
||||
ChunkKeywordRequest,
|
||||
ChunkKeywordResponse,
|
||||
@@ -17,6 +19,7 @@ from app.schemas.retrieval import RetrievalRequest, RetrievalResponse
|
||||
from app.schemas.vectors import VectorRetrievalResponse
|
||||
from app.services.auth import require_admin
|
||||
from app.services.embedding_runtime import get_embedding_provider
|
||||
from app.services.exports import export_history
|
||||
from app.services.hybrid import retrieve_chunks, retrieve_hybrid
|
||||
from app.services.retrieval import retrieve
|
||||
|
||||
@@ -25,6 +28,26 @@ router = APIRouter(prefix="/retrieval", tags=["retrieval"])
|
||||
RunResponse = RetrievalResponse | VectorRetrievalResponse | ChunkKeywordResponse | HybridResponse
|
||||
|
||||
|
||||
@router.post(
|
||||
"/exports",
|
||||
response_class=Response,
|
||||
responses={200: {"content": {"application/x-ndjson": {}}, "description": "JSONL 历史快照"}},
|
||||
dependencies=[Depends(require_admin)],
|
||||
)
|
||||
def download_history(payload: ExportHistory, db: Session = Depends(get_db)):
|
||||
"""管理员按明确编号导出历史;沿用 Origin/CSRF,失败不返回部分文件。"""
|
||||
content, export_id, digest = export_history(db, payload)
|
||||
return Response(
|
||||
content,
|
||||
media_type="application/x-ndjson; charset=utf-8",
|
||||
headers={
|
||||
"Content-Disposition": f'attachment; filename="nalati-retrieval-{export_id}.jsonl"',
|
||||
"X-Records-SHA256": digest,
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.post("", response_model=RetrievalResponse)
|
||||
def keyword_retrieval(payload: RetrievalRequest, db: Session = Depends(get_db)):
|
||||
"""只检索已核验知识;保存原始检索结果供复核,不调用大模型。"""
|
||||
|
||||
Reference in New Issue
Block a user