BUG: /videos/semantic-search query normalization and whitespace validation bypass

未关闭
#1,609 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
fastapi, python

调研方向

The behavior is implemented in backend/app/routes/videos.py; start by comparing /videos/semantic-search with /videos/semantic-search’s image counterpart in backend/app/routes/images.py. Validate that whitespace-only input returns HTTP 400, nonblank queries are stripped and lowercased before SigLIP2 inference, and video scores are rounded to four decimals. The issue author reports already implementing the fix and tests, so it is not currently a good first contribution.

由索引模型根据 Issue 内容生成。

描述

bug enhancement
Is there an existing issue for this?
  • I have searched the existing issues
What happened?
Is there an existing issue for this?
  • I have searched the existing issues
What happened?
Summary

In backend/app/routes/videos.py, the video semantic search endpoint (GET /videos/semantic-search) fails to sanitize, validate, and normalize query strings before running SigLIP2 inference.

Where and How It Occurs
  1. Validation Bypass on Whitespace Queries:
    The route parameter defines query: str = Query(..., min_length=1). FastAPI min_length only checks raw string length, so queries containing only spaces (e.g. " ") bypass validation.
  2. Missing strip() and lower() Normalization:
    Unlike /images/semantic-search (in backend/app/routes/images.py), /videos/semantic-search passes the raw query string straight into SIGLIP2_QUERY_TEMPLATE.format(query=query). Because the SigLIP2 tokenizer is case-sensitive and scoring calibration (logit_scale and logit_bias) was fitted on lowercased vocabulary, queries like "Beach" vs "beach" produce disparate token IDs and uncalibrated similarity scores.
  3. Wasted Compute:
    Submitting whitespace or clearing search input triggers full ONNX text encoding and heavy matrix multiplications against all stored video keyframe embeddings instead of immediately returning HTTP 400 Bad Request.
  4. Score Precision Inconsistency:
    Image semantic search rounds scores to 4 decimals (round(score, 4)), while video search emits raw unrounded float numbers.
Steps to Reproduce
  1. Start the backend service.
  2. Ensure at least one video keyframe embedding is indexed.
  3. Send a GET request to /videos/semantic-search with whitespace:
    GET /videos/semantic-search?query=%20%20%20
  4. Notice that the server returns HTTP 200 after executing ONNX inference and matrix multiplication instead of returning HTTP 400 Bad Request with "Query cannot be empty".
  5. Send GET /videos/semantic-search?query=Beach vs GET /videos/semantic-search?query=beach and observe different tokenizations due to lack of lowercasing.
Expected Behavior
  • Whitespace-only queries should immediately return HTTP 400 Bad Request with {"success": false, "error": "Bad Request", "message": "Query cannot be empty"}.
  • Queries should be stripped and lowercased before formatting into the template to maintain calibration parity with image search.
  • Output similarity scores should be rounded to 4 decimal places.
Maintainer Note & Assignment

cc @rohan-pandeyy

I have already diagnosed the root cause, implemented the fix with regression unit tests, and verified that all backend tests pass.

I would be working on this and will drop the pr once assigned.

Record
  • I agree to follow this project's Code of Conduct
Record
  • I agree to follow this project's Code of Conduct
主要语言
Python
星标
322
派生
793
平均合并
6 天 10 小时
30 天内合并 PR
20

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AOSSIE-Org/PictoPy 的其他 Issue

查看 AOSSIE-Org/PictoPy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。