Skip to content

fix: reject malformed embedding indices before lossy coercion - #14

Merged
haolpku merged 1 commit into
OpenDCAI:mainfrom
DivyamTalwar:codex/dm-05-embedding-index-validation
Sep 17, 2026
Merged

haolpku merged 1 commit into
OpenDCAI:mainfrom
DivyamTalwar:codex/dm-05-embedding-index-validation

Conversation

@DivyamTalwar

Copy link
Copy Markdown
Contributor

@haolpku

Summary

The OpenAI-compatible embedding provider now validates response indices before sorting or coercing them.

Root cause

The old path called int(row["index"]), allowing fractional values such as 0.9 and 1.9 to become 0 and 1. The completeness check then accepted a malformed response. Python booleans also passed the numeric coordinate check because bool subclasses int.

Change

  • Require response indices to be actual JSON integers and reject booleans, fractional values, and numeric strings.
  • Validate range, uniqueness, and completeness only after strict type validation.
  • Reject boolean vector coordinates.
  • Normalize non-object response bodies and malformed rows through ExternalServiceError.
  • Keep valid out-of-order rows, dimension detection, HTTP retry policy, and model/batching behavior unchanged.

Regression coverage

The focused tests cover fractional, boolean, string, negative, duplicate, and out-of-range indices; boolean coordinates; valid reordering; and the no-retry rule for deterministic schema errors.

Verification: python -m pytest -q — 202 passing, 5 optional SDK tests skipped.

No network service or embedding quality claim is made; this is response-shape validation only.

Please review and merge if CI is green.

@DivyamTalwar

Copy link
Copy Markdown
Contributor Author

@haolpku — Could you please review the strict embedding-response validation fix and merge it if CI confirms the full suite and compatibility expectations?

@haolpku
haolpku merged commit 30ff700 into OpenDCAI:main Sep 17, 2026
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.

2 participants