This is an automated email from the ASF dual-hosted git repository.
voidmatcha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 2ee180ffab [ZEPPELIN-6465] Extract magic numbers in
EmbeddingSearch.saveIndex() into named constants
2ee180ffab is described below
commit 2ee180ffab215aa18fd167815b65bc23fcc64d1f
Author: huiseong29 <[email protected]>
AuthorDate: Sun Sep 20 11:11:47 2026 +0900
[ZEPPELIN-6465] Extract magic numbers in EmbeddingSearch.saveIndex() 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
Closes #5489 from huiseong29/ZEPPELIN-6465.
Signed-off-by: YONGJAE LEE <[email protected]>
---
.../org/apache/zeppelin/search/EmbeddingSearch.java | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git
a/zeppelin-server/src/main/java/org/apache/zeppelin/search/EmbeddingSearch.java
b/zeppelin-server/src/main/java/org/apache/zeppelin/search/EmbeddingSearch.java
index c95e6fbe70..41b9666bd2 100644
---
a/zeppelin-server/src/main/java/org/apache/zeppelin/search/EmbeddingSearch.java
+++
b/zeppelin-server/src/main/java/org/apache/zeppelin/search/EmbeddingSearch.java
@@ -96,6 +96,15 @@ public class EmbeddingSearch extends SearchService {
*/
private static final float MIN_SIMILARITY = 0.25f;
private static final int MAX_TEXT_LENGTH = 1500;
+ /**
+ * Truncation limit applied to the text field when an entry is written to
the index file.
+ * Distinct from {@link #MAX_TEXT_LENGTH}, which bounds in-memory processing
before embedding.
+ */
+ private static final int MAX_PERSISTED_TEXT_LENGTH = 2000;
+ /**
+ * Truncation limit applied to the output field when an entry is written to
the index file.
+ */
+ private static final int MAX_PERSISTED_OUTPUT_LENGTH = 1000;
static final String ID_FIELD = "id";
private static final String PARAGRAPH = "paragraph";
@@ -868,15 +877,15 @@ public class EmbeddingSearch extends SearchService {
out.writeUTF(e.getKey());
out.writeUTF(e.getValue().noteName != null ? e.getValue().noteName :
"");
String text = e.getValue().text != null ? e.getValue().text : "";
- if (text.length() > 2000) {
- text = text.substring(0, 2000);
+ if (text.length() > MAX_PERSISTED_TEXT_LENGTH) {
+ text = text.substring(0, MAX_PERSISTED_TEXT_LENGTH);
}
out.writeUTF(text);
out.writeUTF(e.getValue().title != null ? e.getValue().title : "");
out.writeUTF(e.getValue().tables != null ? e.getValue().tables : "");
String output = e.getValue().output != null ? e.getValue().output :
"";
- if (output.length() > 1000) {
- output = output.substring(0, 1000);
+ if (output.length() > MAX_PERSISTED_OUTPUT_LENGTH) {
+ output = output.substring(0, MAX_PERSISTED_OUTPUT_LENGTH);
}
out.writeUTF(output);
for (float v : e.getValue().embedding) {