Skip to content

[ZEPPELIN-6465] Extract magic numbers in EmbeddingSearch.saveIndex() into named constants - #5489

Merged
voidmatcha merged 1 commit into
apache:masterfrom
huiseong29:ZEPPELIN-6465
Sep 20, 2026
Merged

voidmatcha merged 1 commit into
apache:masterfrom
huiseong29:ZEPPELIN-6465

Conversation

@huiseong29

@huiseong29 huiseong29 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

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

  • Extract the two truncation limits into named constants
  • 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

…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
@huiseong29 huiseong29 changed the title [ZEPPELIN-6465] Extract magic numbers in EmbeddingSearch.saveIndex() … [ZEPPELIN-6465] Extract magic numbers in EmbeddingSearch.saveIndex() into named constants Sep 18, 2026
@huiseong29

Copy link
Copy Markdown
Contributor Author

The three failing frontend checks appear unrelated to this change:

  • test-selenium-with-spark-module: AuthenticationIT.testSimpleAuthentication
    fails in logoutUser with ElementClickIntercepted — the login modal is still
    fading in and receives the click intended for the user menu.
  • run-playwright-e2e-tests (auth): one failure in the paragraph spec on firefox;
    the sibling test in the same file was reported flaky on chromium and passed on retry.
  • run-playwright-e2e-tests (anonymous): cancelled as a result of the above.

This PR only extracts two literals into named constants in a Java class, with no
behavior change.

@voidmatcha voidmatcha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@ParkGyeongTae ParkGyeongTae left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@voidmatcha
voidmatcha merged commit 2ee180f into apache:master Sep 20, 2026
25 of 28 checks passed
@voidmatcha

Copy link
Copy Markdown
Member

Merged into master (2ee180f).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants