diff --git a/internal/api/handlers/vectors.go b/internal/api/handlers/vectors.go index d283918..a8fadb0 100644 --- a/internal/api/handlers/vectors.go +++ b/internal/api/handlers/vectors.go @@ -176,6 +176,8 @@ func (h *VectorHandler) Insert(c *gin.Context) { // @Security BearerAuth // @Router /api/v1/vectors/search [post] func (h *VectorHandler) Search(c *gin.Context) { + const maxSearchK = 10000 + var req SearchRequest if err := c.ShouldBindJSON(&req); err != nil { response.Fail(c, http.StatusBadRequest, err.Error()) @@ -186,6 +188,10 @@ func (h *VectorHandler) Search(c *gin.Context) { response.Fail(c, http.StatusBadRequest, "k cannot be negative") return } + if *req.K > maxSearchK { + response.Fail(c, http.StatusBadRequest, "k exceeds maximum allowed value") + return + } results, err := h.Engine.Search(c.Request.Context(), req.Vector, sparseOrNone(req.SparseVector), *req.K, req.Filters) if err != nil {