alibaba/spring-ai-alibaba · error · IllegalArgumentException

regex cannot be empty

Error message

regex cannot be empty

What it means

KnowledgeBaseIndexPipeline.transform selects a TextSplitter based on the process config's ChunkType. When ChunkType.REGEX is chosen, the config's regex string must be non-blank; otherwise it throws IllegalArgumentException "regex cannot be empty" before constructing RegexTextSplitter. This prevents building a splitter with no splitting rule.

Source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/rag/indices/KnowledgeBaseIndexPipeline.java:144

		return documents;
	}

	/**
	 * Transforms documents by splitting them into chunks
	 * @param documents Documents to transform
	 * @param processConfig Configuration for the transformation process
	 * @return List of transformed documents
	 */
	public List<Document> transform(List<Document> documents, ProcessConfig processConfig) {

		// TODO now use this simple chunk splitter first
		ChunkType chunkType = processConfig.getChunkType();
		TextSplitter splitter = null;
		if (Objects.requireNonNull(chunkType) == ChunkType.REGEX) {
			String regex = processConfig.getRegex();
			if (StringUtils.isBlank(regex)) {
				throw new IllegalArgumentException("regex cannot be empty");
			}

			splitter = new RegexTextSplitter(regex, processConfig.getChunkOverlap());
		}
		else {
			splitter = new TokenTextSplitter(processConfig.getChunkSize(), processConfig.getChunkOverlap(), 1, 10000,
					false);
		}
		List<Document> transformedDocs = splitter.apply(documents);

		log.info("{} documents transformed", transformedDocs.size());
		return transformedDocs;
	}

	/**
	 * Stores document chunks in the vector store with metadata
	 * @param chunks Document chunks to store
	 * @param indexConfig Index configuration

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Set a non-blank regex on the process config, e.g. processConfig.setRegex("\\n\\n").
  2. Switch ChunkType to a non-regex option (e.g. TOKEN-based default splitter) if a regex rule isn't needed.
  3. Validate the process config (chunkType/regex/chunkSize/chunkOverlap) at API entry before starting the indexing job.

Example fix

// before
ProcessConfig config = new ProcessConfig();
config.setChunkType(ChunkType.REGEX);
// after
ProcessConfig config = new ProcessConfig();
config.setChunkType(ChunkType.REGEX);
config.setRegex("\\n\\n");
Defensive patterns

Strategy: validation

Validate before calling

// Java
if (processConfig.getChunkType() == ChunkType.REGEX && StringUtils.isBlank(processConfig.getRegex())) {
    throw new IllegalArgumentException("regex must be set when ChunkType.REGEX is selected");
}

Try / catch

try {
    pipeline.transform(documents, processConfig);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().contains("regex cannot be empty")) {
        // correct the process config before re-running indexing
    }
}

Prevention

When it happens

Trigger: Running the indexing pipeline with processConfig.setChunkType(ChunkType.REGEX) but never calling setRegex(...) (or setting it to empty/whitespace), so transform() finds a blank regex.

Common situations: Choosing REGEX chunking in the knowledge-base processing UI but leaving the regex field empty; config loaded from JSON/YAML where the regex key was omitted; programmatic pipeline setup copying a config that used a different chunk type.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/60033f1c5ab040f2. Report an issue: GitHub.