Skip to content

Keep indexed embedding responses paired with their input texts - #784

Merged
WaylandYang merged 2 commits into
devfrom
land/embedding-index-order
Sep 19, 2026
Merged

WaylandYang merged 2 commits into
devfrom
land/embedding-index-order

Conversation

@WaylandYang

Copy link
Copy Markdown
Contributor

Maya-Kid's #767, rebased onto dev after #764 moved the streaming buffer, plus one fix from the review.

Their change. LlmClient::embed scatters response entries by their index when the response carries one, with errors for a missing, out-of-range or duplicate index and for an unfilled slot, and keeps the positional path untouched for responses that carry none. Callers zip these vectors against input texts and only check the count, so a reordered batch would store a vector against the wrong text with nothing to notice it.

The fix on top. The index-presence probe was item.get("index").is_some(), which is true for "index": null — get returns Some(Value::Null) — and then as_u64() fails and the whole call errors. Three response shapes that work today became hard failures: a null index, a string index, a float index. The probe now reads the value rather than the key, so anything that is not a number falls back to position, which is what their own comment said the goal was.

A test covers all three shapes and fails on the old predicate:

[{"embedding":[1.0],"index":null},{"embedding":[2.0],"index":null}] 该按位置配对,却报错:
  Embedding response has a missing or invalid index

The English comment was rewritten in Chinese, which is the language for comments in this repository.

Their branch could not be updated from here (no permission on the fork's branch), so this carries their commit with authorship intact and #767 closes with it.

30 utopia-llm tests pass, fmt clean.

🤖 Generated with Claude Code

Maya-Kid and others added 2 commits September 19, 2026 15:42
Signed-off-by: dada-yan <BinjunYann@gmail.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: WaylandYang <wayland0916@gmail.com>
@WaylandYang
WaylandYang merged commit b9fed54 into dev Sep 19, 2026
@WaylandYang
WaylandYang deleted the land/embedding-index-order branch September 19, 2026 07:54
This was referenced Sep 19, 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