Skip to content

fix(python): skip OpenAI embedding requests when no valid text remains - #5195

Merged
Xuanwo merged 1 commit into
mainfrom
xuanwo/lancedb-openai-empty-batch
Nov 24, 2026
Merged

Xuanwo merged 1 commit into
mainfrom
xuanwo/lancedb-openai-empty-batch

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Follows up on #4005, which handled mixed batches in OpenAIEmbeddings.generate_embeddings. On main, when the input batch is empty ([]) or filtering leaves no valid texts (such as [None, ""]), generate_embeddings still imports the openai SDK and calls embeddings.create(input=[], ...).

  • Return [None] * len(texts) early in python/python/lancedb/embeddings/openai.py when no valid texts remain ([] for empty input, one None per item when all inputs are filtered), before importing the openai SDK or sending a request.
  • Add regression tests in python/python/tests/test_embeddings.py covering empty batches, all-filtered batches, and native-backed table.add(..., on_bad_vectors="null") verifying rows are kept with null vectors and no OpenAI request is made.

Attribution

Successor to #3152. The early return and nullable ingestion test were originally contributed by @saudademjj in #3152.

Verification

  • 3 new regression tests failed before the fix (observing embeddings.create(input=[], ...)) and passed after.
  • Related embedding test suite: 148 passed, 1 skipped, 9 deselected (mocked client only; no live OpenAI API calls).
  • Ruff check and format checks are clean for the changed python/ tree (scoped to python/ only).

Co-authored-by: saudademjj [email protected]

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added bug Something isn't working Python Python SDK labels Nov 24, 2026

@lancedb-gatekeeper lancedb-gatekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Gate recommendation: approve.

Returning immediately after filtering avoids SDK initialization and empty requests while preserving one result per input. The regression tests cover empty and all-filtered batches, plus Embedded ingestion that retains both rows with null vectors.

@lancedb-gatekeeper lancedb-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 24, 2026
@Xuanwo
Xuanwo merged commit 7a86617 into main Nov 24, 2026
21 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/lancedb-openai-empty-batch branch November 24, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance. Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants