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
2023-03-17 18:15:19 -07:00
2025-03-10 09:01:23 -07:00

Reverie LanceDB Website Blog Discord Twitter LinkedIn

LanceDB

The Multimodal Lakehouse for AI

How to Install ✦ Detailed Documentation ✦ Tutorials and Recipes ✦ Contributors

The ultimate multimodal data platform for AI/ML applications.

LanceDB is designed for fast, scalable, and production-ready vector search. It is built on top of the Lance columnar format. You can store, index, and search over petabytes of multimodal data and vectors with ease. LanceDB is a central location where developers can build, train and analyze their AI workloads.


Demo: Multimodal Search by Keyword, Vector or with SQL

LanceDB Multimodal Search

Star LanceDB to get updates!

⭐ Click here ⭐ to see how fast we're growing!

Key Features:

  • Fast Vector Search: Search billions of vectors in milliseconds with state-of-the-art indexing.
  • Comprehensive Search: Support for vector similarity search, full-text search and SQL.
  • Multimodal Support: Store, query and filter vectors, metadata and multimodal data (text, images, videos, point clouds, and more).
  • Advanced Features: Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure. GPU support in building vector index.

Products:

  • LanceDB Embedded (open source): 100% open source, runs in your application's process; your data can live on local disk or in object storage. No vendor lock-in.
  • LanceDB Enterprise: Production-scale distributed search, indexing, and maintenance. Plus, complete data sovereignty and security.

Ecosystem:

  • Columnar Storage: Built on the Lance columnar format for efficient storage and analytics.
  • Seamless Integration: Python, Node.js, Rust, and REST APIs for easy integration. Native Python and Javascript/Typescript support.
  • Rich Ecosystem: Integrations with LangChain 🦜️🔗, LlamaIndex 🦙, Apache-Arrow, Pandas, Polars, DuckDB and more on the way.

How to Install:

Follow the Quickstart doc to set up LanceDB locally.

API & SDK: We also support Python, Typescript and Rust SDKs

Interface Documentation
Python SDK https://lancedb.github.io/lancedb/python/python/
Typescript SDK https://lancedb.github.io/lancedb/js/globals/
Rust SDK https://docs.rs/lancedb/latest/lancedb/index.html
REST API https://docs.lancedb.com/api-reference/rest

Join Us and Contribute

We welcome contributions from everyone! Whether you're a developer, researcher, or just someone who wants to help out.

If you have any suggestions or feature requests, please feel free to open an issue on GitHub or discuss it on our Discord server.

Check out the GitHub Issues if you would like to work on the features that are planned for the future. If you have any suggestions or feature requests, please feel free to open an issue on GitHub.

Contributors

Stay in Touch With Us


Website Blog Discord Twitter LinkedIn

License

See LICENSE for the project license.

S
Description
Developer-friendly OSS embedded retrieval library for multimodal AI. Search More; Manage Less.
Readme Apache-2.0
128 MiB
Languages
Rust 53.9%
Python 35.8%
TypeScript 9.4%
Java 0.6%
Shell 0.2%