Skip to content

fix(lindorm): check bulk item results before counting inserts - #915

Open
Poisky wants to merge 1 commit into
zilliztech:mainfrom
Poisky:codex/fix-lindorm-bulk-item-results
Open

Poisky wants to merge 1 commit into
zilliztech:mainfrom
Poisky:codex/fix-lindorm-bulk-item-results

Conversation

@Poisky

@Poisky Poisky commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Lindorm can return HTTP 200 for a bulk request even when individual writes fail. _insert_batch_func() currently counts the whole batch as inserted as soon as bulk() returns.

We found a count discrepancy while loading the Cohere 1M dataset. VectorDBBench reported 1,000,000 inserts, but the index contained 999,794 documents after refresh. We checked the source IDs and confirmed that 206 were missing. The original run did not record per-item errors, so we couldn't determine why those particular writes failed.

Changes

Check the errors flag and require one successful index result for each submitted document before counting the batch. If an item fails or its result is missing, the existing retry loop resends the batch with the same document IDs. A successful retry counts the batch once. If retries are exhausted, the adapter returns an error and a count of zero for that batch.

Tests

Added regression tests for a partial failure followed by a successful retry, a persistent failure that exhausts retries, and a bulk response with a missing item.

pytest -q tests/test_lindorm_bulk.py — 3 passed.

Check every item in the bulk response before acknowledging a batch. On partial or incomplete responses, retry the batch using the original document IDs. Propagate the error if retries are exhausted.

Signed-off-by: 宁烁 <zhangzongning.zzn@alibaba-inc.com>
@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Poisky
To complete the pull request process, please assign jamesgao-jpg after the PR has been reviewed.
You can assign the PR to them by writing /assign @jamesgao-jpg in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Poisky

Poisky commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

/assign @jamesgao-jpg Could you please review this PR? Thanks!

@jamesgao-jpg jamesgao-jpg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking down the silent HTTP 200 bulk partial-failure issue and adding unit tests! Checking each bulk item and retrying by document ID is the right direction; left 4 inline comments covering a split-batch count/offset bug with SerialInsertRunner, permanent-error retry amplification, offline/CI test execution, and _id-based failure diagnostics.

self.client.bulk(body=insert_data)
response = self.client.bulk(body=insert_data)
self._validate_bulk_response(response, batch_metadata)
return (len(batch_embeddings), None)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Out-of-order sub-batch completion can still make SerialInsertRunner drop failed rows while reporting full inserts.

In LindormVector.insert_embeddings, inputs larger than write_vector_batch (1000) are split across concurrent sub-batches and summed in as_completed(futures) order until an error breaks the loop. With e.g. --insert-batch-size 2000 ([0:1000] and [1000:2000]), if the second sub-batch succeeds first while the first sub-batch fails item validation (returning (0, error) here), insert_embeddings returns (1000, final_error).

SerialInsertRunner.endless_insert_data then advances already_insert_count += 1000 and slices embeddings[1000:] / metadata[1000:], replaying only the already-written second sub-batch and reporting 2000 inserts even though IDs from the first sub-batch were skipped.

Could insert_embeddings return 0 retry progress on any sub-batch error ((0, final_error)) — since _id-based index operations retry idempotently — or compute a confirmed contiguous prefix from index 0, with an out-of-order regression test?

f"Bulk insert failed: errors={response.get('errors')!r}, "
f"expected_items={len(batch_metadata)}, actual_items={len(items)}, failures={failures}"
)
raise RuntimeError(msg)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Avoid 19-minute / 60-call retry cascades on permanent item errors.

Raising a plain RuntimeError for every bulk item failure causes _insert_batch_func (L237-L253) to retry 10 times (189s total backoff), and then ConcurrentInsertRunner._insert_batch_with_retry runs MAX_INSERT_RETRY = 5 additional outer retries (60 bulk calls and 1,149s total sleep) on non-transient errors such as 400 mapper_parsing_exception.

Consider raising a NonRetryableInsertError (with .non_retryable = True) for permanent 4xx / validation failures so ConcurrentInsertRunner fails fast, while preserving retries for transient failures such as 429 or 5xx.

items = response["items"]
failures = []
for position, doc_id in enumerate(batch_metadata):
item = items[position] if position < len(items) else None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Match/verify result.get("_id") when diagnosing missing or malformed items.

Matching strictly by items[position] works when responses preserve all items in order, but if an item is dropped mid-batch (e.g. submitted IDs [10, 20, 30] returning {"_id": "10"} and {"_id": "30"}), position=1 inspects _id="30" as if it were 20 and reports ID 30 as missing instead of 20. Checking result.get("_id") == str(doc_id) when _id is present keeps missing-ID diagnostics accurate.


import pytest

from vectordb_bench.backend.clients.lindorm.lindorm_search import LindormVector

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Allow offline test collection without opensearch-py and wire into make unittest.

Importing LindormVector unconditionally at module scope fails pytest tests/test_lindorm_bulk.py during collection (ModuleNotFoundError: No module named 'opensearchpy') in environments with only .[test] installed (including CI), and Makefile does not run this file.

Adding an ImportError stub for opensearchpy (like tests/test_clickhouse_client.py) and adding tests/test_lindorm_bulk.py to Makefile's unittest target will ensure CI executes these regression tests.

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.

3 participants