Spaces:
Running
Running
deploy: phase 3 BYOK backend (Dockerfile.hf, FastAPI on 7860)
Browse filesFiles changed (4)
122 unmodified lines123124125126127128129130122 unmodified lines# Multi-tenant collections route BYOK session -> documents_sess_<sid>.ENV SAR_MULTI_TENANT_COLLECTIONS=true# Pipeline safetyENV SAR_REQUEST_TIMEOUT_S=120ENV SAR_FAITHFULNESS_GATE_ENABLED=true# `flag` keeps the answer text intact and lets the UI render the# faithfulness badge. `drop` would rewrite sentences out of the answer122 unmodified lines123124125126127128129130131132133122 unmodified lines# Multi-tenant collections route BYOK session -> documents_sess_<sid>.ENV SAR_MULTI_TENANT_COLLECTIONS=true# Pipeline safety -- BYOK uploads can push the candidate set up to 20# chunks (top_k=10 from base + top_k=10 from session) which the grader# scores one Groq call at a time. 180 s leaves headroom for the# reranker cold load + Groq free-tier rate-limit waits on a fresh boot.ENV SAR_REQUEST_TIMEOUT_S=180ENV SAR_FAITHFULNESS_GATE_ENABLED=true# `flag` keeps the answer text intact and lets the UI render the# faithfulness badge. `drop` would rewrite sentences out of the answer
246 unmodified lines247248249250251252246 unmodified lines# raise without a Qdrant tier upgrade.byok_upload_max_bytes: int = 5 * 1024 * 1024 # 5 MB per filebyok_upload_max_files: int = 5 # per session# Extensions allowed on the BYOK upload endpoint. .pdf parsed via PyPDF2;# .txt / .md pass through the text loader. OCR / docx / csv stay off to# avoid pulling Paddle (~700 MB) into the image.246 unmodified lines247248249250251252253254255256257258246 unmodified lines# raise without a Qdrant tier upgrade.byok_upload_max_bytes: int = 5 * 1024 * 1024 # 5 MB per filebyok_upload_max_files: int = 5 # per session# Hard chunk-count cap per uploaded file. A 50-page PDF can chunk to# 100+ pieces -- on the HF Space CPU Basic each Groq call adds ~2 s# so a single 135-chunk doc can blow past SAR_REQUEST_TIMEOUT_S.# If the parsed file exceeds this cap, the ingest endpoint cleans up# the partial points and returns 413 with a clear message.byok_upload_max_chunks_per_file: int = 60# Extensions allowed on the BYOK upload endpoint. .pdf parsed via PyPDF2;# .txt / .md pass through the text loader. OCR / docx / csv stay off to# avoid pulling Paddle (~700 MB) into the image.
618 unmodified lines619620621622623624100 unmodified lines725726727728729730618 unmodified lines"count": len(uploads),"max_files": settings.byok_upload_max_files,"max_bytes": settings.byok_upload_max_bytes,"allowed_extensions": list(settings.byok_upload_allowed_extensions),"items": uploads,}100 unmodified lines],)result = await pipeline.ingest_document(req)# Tag every newly-upserted chunk with the file_id + ingested_at# so the list and delete endpoints can group by file.if result.point_ids:618 unmodified lines619620621622623624625100 unmodified lines726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763618 unmodified lines"count": len(uploads),"max_files": settings.byok_upload_max_files,"max_bytes": settings.byok_upload_max_bytes,"max_chunks_per_file": settings.byok_upload_max_chunks_per_file,"allowed_extensions": list(settings.byok_upload_allowed_extensions),"items": uploads,}100 unmodified lines],)result = await pipeline.ingest_document(req)# Reject documents that chunk too aggressively. Without this# cap a 100-page PDF dominates the dual-collection retrieval# and the grader/faithfulness loop times out under the 180 s# SLO. Delete what we just upserted and return 413 so the# visitor knows exactly what failed.max_chunks = int(settings.byok_upload_max_chunks_per_file)if max_chunks > 0 and result.num_chunks > max_chunks:try:if result.point_ids:sess_qdrant.client.delete(collection_name=sess_qdrant.collection_name,points_selector=list(result.point_ids),)except Exception as exc:logger.warning("byok_upload_oversize_cleanup_failed",error=str(exc),chunks=result.num_chunks,)raise HTTPException(status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,detail={"reason": "too_many_chunks","chunk_count": result.num_chunks,"max_chunks": max_chunks,"hint": (f"This file chunks to {result.num_chunks} pieces "f"but the BYOK demo caps single uploads at {max_chunks}. ""Try a shorter document or a section instead."),},)# Tag every newly-upserted chunk with the file_id + ingested_at# so the list and delete endpoints can group by file.if result.point_ids:
160 unmodified lines16116216316416516616716816917017136 unmodified lines208209210211212213214160 unmodified linesextra_filter=extra_filter,)if session_qdrant is not None:try:sess_dense = session_qdrant.search_with_rbac(query_embedding=query_embedding,user_context=user_context,top_k=top_k * 2,extra_filter=extra_filter,)dense_results = list(dense_results) + list(sess_dense)36 unmodified linessess_sparse = session_qdrant.search_sparse_with_rbac(sparse_vector=sparse_vector,user_context=user_context,top_k=top_k * 2,extra_filter=extra_filter,)sparse_results.extend(sess_sparse)160 unmodified lines16116216316416516616716816917017117217317417517636 unmodified lines213214215216217218219160 unmodified linesextra_filter=extra_filter,)if session_qdrant is not None:# Session collections can be much smaller than the base, but# an aggressive PDF upload can balloon to 100+ chunks; cap# session pulls at top_k (not top_k * 2) so the candidate# explosion in the dual-collection RRF stays bounded and the# grader / faithfulness loop completes within the SLO.try:sess_dense = session_qdrant.search_with_rbac(query_embedding=query_embedding,user_context=user_context,top_k=top_k,extra_filter=extra_filter,)dense_results = list(dense_results) + list(sess_dense)36 unmodified linessess_sparse = session_qdrant.search_sparse_with_rbac(sparse_vector=sparse_vector,user_context=user_context,top_k=top_k,extra_filter=extra_filter,)sparse_results.extend(sess_sparse)
Dockerfile.hf+5-2
config/settings.py+6
interfaces/api.py+33
retrieval/hybrid_search.py+7-2