AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

fix: preserve embedding batch result order

Open lxfight opened this issue 4 months ago • 0 comments

Fixes embedding batch result ordering when concurrent batches complete out of order.

Modifications / 改动点

  • Preserve the original batch order in EmbeddingProvider.get_embeddings_batch by storing batch results by index before flattening.

  • Add a regression test covering delayed first-batch completion to ensure embeddings still match the original input order.

  • [x] This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

uv run pytest tests/unit/test_faiss_vec_db.py

Result:

3 passed, 1 warning
uv run ruff format .
uv run ruff check .

Result:

480 files left unchanged
All checks passed!

Checklist / 检查清单

  • [x] 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc. / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • [x] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above. / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • [x] 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml. / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • [x] 😮 My changes do not introduce malicious code. / 我的更改没有引入恶意代码。

Summary by Sourcery

Ensure embedding batch results preserve the original input order even when concurrent batches complete out of order.

Bug Fixes:

  • Fix embedding batch aggregation in get_embeddings_batch to maintain input ordering when batches finish asynchronously.

Tests:

  • Add a regression test using a delayed embedding provider to verify batch embeddings remain aligned with the input sequence.

lxfight avatar Jul 13 '26 07:07 lxfight