[ZEPPELIN-6465] Extract magic numbers in EmbeddingSearch.saveIndex() into named constants - #5489
Merged
Merged
Conversation
…into named constants ### What is this PR for? `EmbeddingSearch` declares its tuning values as named `private static final int` constants near the top of the class (`EMBEDDING_DIM`, `MAX_TEXT_LENGTH`, `MAX_INDEX_ENTRIES`), but the two truncation limits in `saveIndex()` were left as bare literals. Each value appeared twice — once in the length check and once in the `substring(0, ...)` call — so changing only one occurrence would silently let the check bound and the truncation bound drift apart. This extracts `2000` and `1000` into `MAX_PERSISTED_TEXT_LENGTH` and `MAX_PERSISTED_OUTPUT_LENGTH`, following the constant style already used in the class, and replaces all four usages. The names deliberately distinguish these persistence limits from the existing `MAX_TEXT_LENGTH` (1500), which bounds in-memory processing before embedding and is a different value for a different purpose. Javadoc on the new text constant makes that distinction explicit. Values are unchanged, so behavior and the persisted binary format are identical and `INDEX_VERSION` does not need to move. `loadIndex()` has no corresponding truncation logic and is untouched. ### What type of PR is it? Refactoring ### Todos - [x] - Extract the two truncation limits into named constants - [x] - Replace all four literal usages in saveIndex() ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-6465 ### How should this be tested? The EmbeddingSearch tests are gated behind `ZEPPELIN_EMBEDDING_TEST` and require the embedding model to be installed first: bash bin/install-search-model.sh ZEPPELIN_EMBEDDING_TEST=true ./mvnw test -pl zeppelin-server -Dtest='*EmbeddingSearch*' All 12 tests pass. `grep -n "2000\|1000" EmbeddingSearch.java` shows the values only at the two constant declarations, with no bare literals left in `saveIndex()`. ### Screenshots (if appropriate) N/A ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No
Contributor
Author
|
The three failing frontend checks appear unrelated to this change:
This PR only extracts two literals into named constants in a Java class, with no |
voidmatcha
approved these changes
Sep 18, 2026
voidmatcha
left a comment
Member
There was a problem hiding this comment.
LGTM 👍
The CI failures are known flakes, tracked as issues:
- ZEPPELIN-6711: AuthenticationIT clicks logout before the login modal closes (selenium)
- ZEPPELIN-6710: Monaco suggestions swallow Enter in NB-PARITY-003 (Playwright, already assigned)
ZEPPELIN-6711 is unassigned, so feel free to take it if you're interested.
Member
|
Merged into master (2ee180f). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR for?
EmbeddingSearchdeclares its tuning values as namedprivate static final intconstants near the top of the class (EMBEDDING_DIM,MAX_TEXT_LENGTH,MAX_INDEX_ENTRIES), but the two truncation limits insaveIndex()were left as bare literals. Each value appeared twice — once in the length check and once in thesubstring(0, ...)call — so changing only one occurrence would silently let the check bound and the truncation bound drift apart.This extracts
2000and1000intoMAX_PERSISTED_TEXT_LENGTHandMAX_PERSISTED_OUTPUT_LENGTH, following the constant style already used in the class, and replaces all four usages.The names deliberately distinguish these persistence limits from the existing
MAX_TEXT_LENGTH(1500), which bounds in-memory processing before embedding and is a different value for a different purpose. Javadoc on the new text constant makes that distinction explicit.Values are unchanged, so behavior and the persisted binary format are identical and
INDEX_VERSIONdoes not need to move.loadIndex()has no corresponding truncation logic and is untouched.What type of PR is it?
Refactoring
Todos
What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-6465
How should this be tested?
The EmbeddingSearch tests are gated behind
ZEPPELIN_EMBEDDING_TESTand require the embedding model to be installed first:All 12 tests pass.
grep -n "2000\|1000" EmbeddingSearch.javashows the values only at the two constant declarations, with no bare literals left insaveIndex().Screenshots (if appropriate)
N/A
Questions: