api7 / api7/aisix

[#397 audit follow-ups] LOW: batch-input embeddings e2e + null-embedding hardening

Open
#398 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
157
Forks
32
Avg merge
1h 25m
Merged PRs (30d)
145

Description

Context

PR #397 audit raised two LOW findings, filed here as follow-ups so they don't block merge:

1. No multi-input (batch) e2e coverage on the embeddings round-trip

PR #397 covers data.length === 1 only. The wire-layer enum doesn't care about batch size (the surrounding Vec<OpenAiEmbeddingObject> already deserializes any-length arrays), but a regression that mangled the data[1+] indices on the way back would only be caught by a batch case.

Fix: add a 4th subtest in tests/e2e/src/cases/openai-embeddings-base64-e2e.test.ts:

  • Request input: ["hello", "world"]
  • Mock upstream returns 2 base64 entries
  • Assert data.length === 2 and both embedding fields are strings
2. null embedding field still rejected

Pre-PR: embedding: Vec<f32> rejected null. Post-PR: embedding: EmbeddingVector (untagged enum over Vec<f32> and String) still rejects nullserde_json::from_str::<EmbeddingVector>("null") returns Err.

An out-of-spec upstream that emitted {"embedding": null} would still 502. Pre-PR did the same so this isn't a regression, but it's a wire-shape hardening opportunity.

Fix options:

  • Add Option<EmbeddingVector> wrapper at EmbeddingObject.embedding so null deserializes to None. Surface to the SDK as null per JSON pass-through.
  • OR: explicit Null variant on EmbeddingVector.

Either preserves pass-through semantics. The first is less invasive.

Tracking
  • Parent: PR #397, issue #393.
  • Severity: LOW (both are hardening, not customer-blockers).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/e2e/src/cases/openai-embeddings-base64-e2e.test.ts and the EmbeddingObject/EmbeddingVector deserialization definitions. Add the two-input round-trip coverage, then verify null embedding values deserialize without a 502 while preserving JSON pass-through. Done means the batch assertions pass and the null case is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.