Skip to content

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

Open
dex0shubham wants to merge 1 commit into
StarTrail-org:mainfrom
dex0shubham:fix/serve-n_docs-bound
Open

fix(serve): bound n_docs to prevent unbounded-search OOM/DoS#122
dex0shubham wants to merge 1 commit into
StarTrail-org:mainfrom
dex0shubham:fix/serve-n_docs-bound

Conversation

@dex0shubham

Copy link
Copy Markdown
Contributor

Problem

SearchRequest.n_docs had no bound (n_docs: int = 10), and downstream
fetch_k = req.n_docs * 10 feeds FAISS's search k. A request like
{"queries": [...], "n_docs": 100000000} forces a huge result-buffer allocation on
the public /search endpoint — a trivial OOM/DoS. Zero and negative values were also
accepted.

Fix

Constrain via pydantic: n_docs: int = Field(default=10, ge=1, le=1000). The largest
real caller (README examples, web app, eval harness) uses 10, so the 1000 cap is
generous. One line, declarative, no behavior change for valid requests; out-of-range
values now return a 422 instead of degrading the service.

n_docs had no limit and fetch_k = n_docs * 10 feeds FAISS's search k, so a request with a huge n_docs triggers a massive allocation on the public endpoint. Constrain to 1..1000 via pydantic Field (largest real caller uses 10).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

@dex0shubham is attempting to deploy a commit to the andylizf's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant