Skip to content

[Fix] Reject non-positive embedding dimensions - #3614

Open
Asp-irin wants to merge 1 commit into
mlc-ai:mainfrom
Asp-irin:fix/embedding-dimensions-validation
Open

Asp-irin wants to merge 1 commit into
mlc-ai:mainfrom
Asp-irin:fix/embedding-dimensions-validation

Conversation

@Asp-irin

@Asp-irin Asp-irin commented Nov 23, 2026 •

Copy link
Copy Markdown

Fixes

Fixes #3594.

Summary

Non-positive dimension values can produce malformed embedding outputs: 0 can return an empty vector, while negative values can truncate dimensions from the end.

This PR rejects dimension values below 1 before embedding inference and adds tests for 0 and negative values.

Testing

I added regression tests but haven't run them yet. I’ll test this locally and update the PR with the results. Any additional testing suggestions are welcome.

@paolo-perrone

Copy link
Copy Markdown

I read through it, haven't run it. The check itself looks right. The new test will fail though: the error body gets JSON-encoded twice, so expect_error(resp.text, ...) hits a TypeError. test_server.py passes response.json(), so expect_error(resp.json(), ...) should do it. Also, most of the diff is reformatting to 88 columns. The repo uses ruff at 100, so pre-commit run -a should take most of that back out.

@Asp-irin

Copy link
Copy Markdown
Author

cool @paolo-perrone will try to make the respective changes and would appreciate your help on setting this locally couldn't find any docs :)

This branch has not been deployed

No deployments
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.

[Bug] /v1/embeddings accepts dimensions of 0 or a negative number and returns 200

2 participants