{"record":{"id":"60033f1c5ab040f2","repo":"alibaba/spring-ai-alibaba","slug":"regex-cannot-be-empty","errorCode":null,"errorMessage":"regex cannot be empty","messagePattern":"regex cannot be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/rag/indices/KnowledgeBaseIndexPipeline.java","lineNumber":144,"sourceCode":"\n\t\treturn documents;\n\t}\n\n\t/**\n\t * Transforms documents by splitting them into chunks\n\t * @param documents Documents to transform\n\t * @param processConfig Configuration for the transformation process\n\t * @return List of transformed documents\n\t */\n\tpublic List<Document> transform(List<Document> documents, ProcessConfig processConfig) {\n\n\t\t// TODO now use this simple chunk splitter first\n\t\tChunkType chunkType = processConfig.getChunkType();\n\t\tTextSplitter splitter = null;\n\t\tif (Objects.requireNonNull(chunkType) == ChunkType.REGEX) {\n\t\t\tString regex = processConfig.getRegex();\n\t\t\tif (StringUtils.isBlank(regex)) {\n\t\t\t\tthrow new IllegalArgumentException(\"regex cannot be empty\");\n\t\t\t}\n\n\t\t\tsplitter = new RegexTextSplitter(regex, processConfig.getChunkOverlap());\n\t\t}\n\t\telse {\n\t\t\tsplitter = new TokenTextSplitter(processConfig.getChunkSize(), processConfig.getChunkOverlap(), 1, 10000,\n\t\t\t\t\tfalse);\n\t\t}\n\t\tList<Document> transformedDocs = splitter.apply(documents);\n\n\t\tlog.info(\"{} documents transformed\", transformedDocs.size());\n\t\treturn transformedDocs;\n\t}\n\n\t/**\n\t * Stores document chunks in the vector store with metadata\n\t * @param chunks Document chunks to store\n\t * @param indexConfig Index configuration","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/rag/indices/KnowledgeBaseIndexPipeline.java#L126-L162","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set a non-blank regex on the process config, e.g. processConfig.setRegex(\"\\\\n\\\\n\").","Switch ChunkType to a non-regex option (e.g. TOKEN-based default splitter) if a regex rule isn't needed.","Validate the process config (chunkType/regex/chunkSize/chunkOverlap) at API entry before starting the indexing job."],"exampleFix":"// before\nProcessConfig config = new ProcessConfig();\nconfig.setChunkType(ChunkType.REGEX);\n// after\nProcessConfig config = new ProcessConfig();\nconfig.setChunkType(ChunkType.REGEX);\nconfig.setRegex(\"\\\\n\\\\n\");","handlingStrategy":"validation","validationCode":"// Java\nif (processConfig.getChunkType() == ChunkType.REGEX && StringUtils.isBlank(processConfig.getRegex())) {\n    throw new IllegalArgumentException(\"regex must be set when ChunkType.REGEX is selected\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    pipeline.transform(documents, processConfig);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"regex cannot be empty\")) {\n        // correct the process config before re-running indexing\n    }\n}","preventionTips":["Require the regex field in the UI/API when REGEX chunking is selected.","Validate the whole ProcessConfig (chunkType, regex, chunkSize, chunkOverlap) before starting index jobs.","Also compile the regex early to catch invalid patterns, not just empty ones."],"tags":["rag","chunking","regex","validation"],"backgroundTag":"empty-required-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}