Skip to content

fix(rag): use floor division for vector embedding batch count - #39376

Open
sergioperezcheco wants to merge 1 commit into
langgenius:mainfrom
sergioperezcheco:fix/vector-factory-total-batches-floor-div
Open

fix(rag): use floor division for vector embedding batch count#39376
sergioperezcheco wants to merge 1 commit into
langgenius:mainfrom
sergioperezcheco:fix/vector-factory-total-batches-floor-div

Conversation

@sergioperezcheco

Copy link
Copy Markdown
Contributor

The total_batches counter in Vector.create and Vector.create_multimodal was computed as len(texts) + batch_size - 1, which is missing the floor-division step. With a batch size of 1000, embedding 1001 documents logged "Processing batch 1/2000" instead of "Processing batch 1/2", so the progress denominator was off by ~batch_size. This only affects the info-level progress logs (the actual batching loop uses the correct range step), but it makes the logs misleading when debugging long embedding runs.

Changed both the text and multimodal paths to use ceiling division: (len(items) + batch_size - 1) // batch_size. Added a regression test that embeds 1001 docs and asserts the logged batch denominator is 2, not 2000 (verified it fails on the old formula).

The total_batches counter in Vector.create and Vector.create_multimodal
was computed as len(texts) + batch_size - 1, which yields the item count
plus an offset instead of the number of batches. The progress log lines
therefore reported a wildly inflated denominator (e.g. 1001 texts with a
batch size of 1000 printed 'Processing batch 1/2000'). Use ceiling
division so the denominator reflects the actual batch count.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-07-21 11:50:13.976564374 +0000
+++ /tmp/pyrefly_pr.txt	2026-07-21 11:49:59.520587863 +0000
@@ -4953,7 +4953,7 @@
 ERROR Class member `_Expr.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
    --> tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py:253:13
 ERROR Class member `_Field.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py:355:13
+   --> tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py:378:13
 ERROR Argument `list[str]` is not assignable to parameter `docs` with type `Sequence[Document]` in function `core.rag.docstore.dataset_docstore.DatasetDocumentStore.add_documents` [bad-argument-type]
    --> tests/unit_tests/core/rag/docstore/test_dataset_docstore.py:297:33
 ERROR Argument `None` is not assignable to parameter `orig` with type `BaseException` in function `sqlalchemy.exc.DBAPIError.__init__` [bad-argument-type]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 54.45% 54.44% -0.00%
Strict coverage 53.94% 53.93% -0.00%
Typed symbols 35,020 35,020 0
Untyped symbols 29,577 29,580 +3
Modules 3044 3044 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant