Skip to content

https://arxiv.org/abs/2606.28344. The end of web parsing. The beginning of scalable pixel-native search. link: https://pixelrag.ai/

fix(serve): bound n_docs to prevent unbounded-search OOM/DoS (#122)

Shubham Srivastava3688a5eaf838
diff --git a/serve/src/pixelrag_serve/api.py b/serve/src/pixelrag_serve/api.py
index a0a3008..0271ff9 100644
--- a/serve/src/pixelrag_serve/api.py
+++ b/serve/src/pixelrag_serve/api.py
@@ -52,7 +52,7 @@ from fastapi import FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, Response
from PIL import Image
-from pydantic import BaseModel
+from pydantic import BaseModel, Field
_request_id_ctx: contextvars.ContextVar[str] = contextvars.ContextVar(
"request_id",
@@ -172,7 +172,9 @@ class Query(BaseModel):
class SearchRequest(BaseModel):
queries: list[Query]
- n_docs: int = 10
+ # Bounded: fetch_k = n_docs * 10 feeds FAISS search k, so an unbounded value
+ # is a trivial OOM/DoS on the public endpoint. Largest real caller uses 10.
+ n_docs: int = Field(default=10, ge=1, le=1000)
nprobe: int | None = None # override default nprobe
min_tile_height: int | None = None # filter out small/blank chunks
instruction: str | None = None # override query embedding instruction