Files
lancedb/python/python
Vibhanshu Singh 3d765d3729 fix(python): skip null and empty texts in Gemini text embeddings (#5369)
## Summary

A table with a `gemini-text` embedding function can contain rows whose
source text is null or empty. `GeminiText.generate_embeddings` built a
`{"parts": [{"text": None}]}` content entry for each of them and sent it
to `embed_content`, so a single missing text could fail the request for
the whole batch.

Skip null and empty texts before building the request, as #5233 does for
Ollama and #4919 for Bedrock. Embed only the remaining texts and put
each embedding back at its original position, so a skipped row gets
`None` while the other rows keep their vectors. When every text is null
or empty, return `None` for each without calling the API. If the service
returns a different number of embeddings than texts sent, raise a
`ValueError` instead of misaligning rows.

The optional L2 normalization for truncated `gemini-embedding-001`
vectors still runs on the returned embeddings only.

## Verification

- Added `test_source_embeddings_skip_null_and_empty_texts` to
`tests/test_gemini_text_embeddings.py`, using the file's existing
`fake_genai` fixture:
- `["a", None, "", "b"]`: only `["a", "b"]` is sent, and the result is
`[vec_a, None, None, vec_b]`;
  - `[None, ""]`: no request is sent and the result is `[None, None]`.
- With `main`'s `gemini_text.py`, the new test fails and the existing 8
tests pass; with this change, all 9 pass. I ran the file against LanceDB
0.42.1 with `main`'s and then the changed `gemini_text.py` copied over
the installed module. I did not call the live Gemini API.
- Repository Ruff lint and format checks pass.
2026-12-02 19:11:36 +00:00
..