forked from opensearch-project/neural-search
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract max chunk limit check to util class
Signed-off-by: yuye-aws <[email protected]>
- Loading branch information
Showing
3 changed files
with
48 additions
and
35 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/main/java/org/opensearch/neuralsearch/processor/chunker/ChunkerUtil.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.processor.chunker; | ||
|
||
import java.util.Locale; | ||
|
||
import static org.opensearch.neuralsearch.processor.TextChunkingProcessor.TYPE; | ||
import static org.opensearch.neuralsearch.processor.chunker.Chunker.MAX_CHUNK_LIMIT_FIELD; | ||
|
||
/** | ||
* A util class used by chunking algorithms. | ||
*/ | ||
public class ChunkerUtil { | ||
|
||
private ChunkerUtil() {} // no instance of this util class | ||
|
||
/** | ||
* Checks whether the chunking results would exceed the max chunk limit. | ||
* If exceeds, then Throw IllegalStateException | ||
* | ||
* @param chunkResultSize the size of chunking result | ||
* @param runtimeMaxChunkLimit runtime max_chunk_limit, used to check with chunkResultSize | ||
* @param nonRuntimeMaxChunkLimit non-runtime max_chunk_limit, used to keep exception message consistent | ||
*/ | ||
public static void checkRunTimeMaxChunkLimit(int chunkResultSize, int runtimeMaxChunkLimit, int nonRuntimeMaxChunkLimit) { | ||
if (chunkResultSize == runtimeMaxChunkLimit) { | ||
throw new IllegalStateException( | ||
String.format( | ||
Locale.ROOT, | ||
"The number of chunks produced by %s processor has exceeded the allowed maximum of [%s]. This limit can be set by changing the [%s] parameter.", | ||
TYPE, | ||
nonRuntimeMaxChunkLimit, | ||
MAX_CHUNK_LIMIT_FIELD | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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