fix(embedding): raise Gemini max_embedding_tokens cap from 2048 to 8192#925
fix(embedding): raise Gemini max_embedding_tokens cap from 2048 to 8192#925Stromweld wants to merge 4 commits into
Conversation
Gemini's embedding models actually support up to 8192 input tokens, not 2048. The artificial 2048 cap was truncating/chunking text more aggressively than necessary for Gemini-backed embedding configs. Added a unit test asserting the client honors the 8192 cap (and still respects a lower max_input_tokens when configured below the cap). Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughGemini embedding token limits are selected by model name: 8192 for ChangesGemini embedding token cap
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/embedding_client.py`:
- Around line 194-195: Update the EmbeddingClient initialization around
self.max_embedding_tokens to select the Gemini input-token cap by self.model:
use 2,048 for gemini-embedding-001 and 8,192 for gemini-embedding-2, while still
respecting max_input_tokens. In tests/llm/test_embedding_client.py lines 95-132,
use gemini-embedding-2 for the 8,192-token case or change the
gemini-embedding-001 expectation to 2,048.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 05cb4c26-1660-45e4-b0ae-43df406e44f6
📒 Files selected for processing (2)
src/embedding_client.pytests/llm/test_embedding_client.py
…001: 2048, gemini-embedding-2: 8192) Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/embedding_client.py (1)
199-204: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an explicit type hint for the new cap variable.
Annotate
gemini_model_token_capasintto follow the repository’s Python typing requirement.As per coding guidelines, Python code should use explicit type hints, including SQLAlchemy
mapped_columnannotations.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/embedding_client.py` around lines 199 - 204, Annotate the gemini_model_token_cap variable with an explicit int type in the model-capacity conditional, preserving the existing values and branching behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/embedding_client.py`:
- Around line 199-204: Update the model selection logic in the embedding
token-capacity path to match the known Gemini model ID exactly, rather than
using a substring check that also accepts names such as gemini-embedding-20.
Preserve the 8192-token cap only for gemini-embedding-2 and keep the
conservative 2048-token fallback for all other models, including
gemini-embedding-001.
---
Nitpick comments:
In `@src/embedding_client.py`:
- Around line 199-204: Annotate the gemini_model_token_cap variable with an
explicit int type in the model-capacity conditional, preserving the existing
values and branching behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 23837dce-a6c0-4c6b-a8aa-560ef2830fe3
📒 Files selected for processing (2)
src/embedding_client.pytests/llm/test_embedding_client.py
…l cap Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
Signed-off-by: Corey Hemminger <hemminger@hotmail.com>
|
Finn-loop review of fda1156 CI: not configured (no required checks reported) ReviewSummary: Replaces the hardcoded 2048-token cap for Gemini embedding models with a model-specific cap: 8192 for No Paperclip issue linked — reviewed against PR body as contract. 1. Must fix before merge
2. Should fix soonNone. 3. Safe to mergeNo — blocked by the stale branch-protection rule above. Code changes themselves are correct and well-tested; the block is purely a repo-configuration issue. Labels to apply
|
Summary
Gemini embedding models support up to 8192 input tokens, not 2048. The code had an artificial
min(max_input_tokens, 2048)cap that unnecessarily truncated/chunked text for Gemini-backed embedding configs even when the caller-configuredmax_input_tokenswas higher.Fix
Changed the Gemini-specific cap in
_EmbeddingClient.__init__from 2048 to 8192, matching Gemini's actual documented per-request token limit. This is a provider-specific fix (only affects the `gemini" transport branch); the OpenAI branch is untouched.Tests
Added
test_gemini_embedding_client_honors_8192_token_capintests/llm/test_embedding_client.py, verifying:max_input_tokensabove the provider cap is clamped to 8192 (previously would have been clamped to 2048)max_input_tokensbelow the cap passes through unchangedFull targeted test run (all passing):
Created with AI assistance — Hermes Agent v0.17.0, model Claude Sonnet 4.6.
Summary by CodeRabbit
Bug Fixes
gemini-embedding-2, 2,048 tokens forgemini-embedding-001, with a conservative 2,048-token fallback for unknown model IDs.Tests