{"record":{"id":"f1b162405a03ac51","repo":"spring-projects/spring-ai","slug":"keywordcount-will-be-ignored-as-keywordstemplate-i","errorCode":null,"errorMessage":"keywordCount will be ignored as keywordsTemplate is set.","messagePattern":"keywordCount will be ignored as keywordsTemplate is set\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"spring-ai-model/src/main/java/org/springframework/ai/model/transformer/KeywordMetadataEnricher.java","lineNumber":147,"sourceCode":"\t\t}\n\n\t\tpublic Builder keywordCount(int keywordCount) {\n\t\t\tAssert.isTrue(keywordCount >= 1, \"The keywordCount must be >= 1\");\n\t\t\tthis.keywordCount = keywordCount;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic Builder keywordsTemplate(PromptTemplate keywordsTemplate) {\n\t\t\tAssert.notNull(keywordsTemplate, \"The keywordsTemplate must not be null\");\n\t\t\tthis.keywordsTemplate = keywordsTemplate;\n\t\t\treturn this;\n\t\t}\n\n\t\tpublic KeywordMetadataEnricher build() {\n\t\t\tif (this.keywordsTemplate != null) {\n\n\t\t\t\tif (this.keywordCount != 0) {\n\t\t\t\t\tlogger.warn(\"keywordCount will be ignored as keywordsTemplate is set.\");\n\t\t\t\t}\n\n\t\t\t\treturn new KeywordMetadataEnricher(this.chatModel, this.keywordsTemplate);\n\t\t\t}\n\n\t\t\treturn new KeywordMetadataEnricher(this.chatModel, this.keywordCount);\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":129,"sourceCodeEnd":159,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/model/transformer/KeywordMetadataEnricher.java#L129-L159","documentation":"KeywordMetadataEnricher.Builder.build() logs this warning when both keywordsTemplate and keywordCount are set. When a custom keywordsTemplate is supplied, keywordCount has no effect because the template fully defines the prompt. The enricher is built using the template and the count is silently ignored.","triggerScenarios":"Calling builder.build() on KeywordMetadataEnricher.Builder after setting both keywordsTemplate(...) and keywordCount(n).","commonSituations":"Copy-pasting a custom template example while leaving a default keywordCount; configuring the enricher via properties where both fields get populated; upgrading from count-based to template-based configuration without removing the count.","solutions":["Remove the keywordCount(...) call when a custom keywordsTemplate is set.","Keep the count inside the template text itself (e.g. \"{\\\"keywords\\\": [no more than 10 keywords]}\").","If you want count-based behavior, drop keywordsTemplate and keep keywordCount only."],"exampleFix":"// before\nKeywordMetadataEnricher enricher = KeywordMetadataEnricher.builder()\n    .chatModel(chatModel)\n    .keywordsTemplate(\"Extract 8 keywords: {text}\")\n    .keywordCount(5)\n    .build();\n\n// after — put the count in the template, drop keywordCount\nKeywordMetadataEnricher enricher = KeywordMetadataEnricher.builder()\n    .chatModel(chatModel)\n    .keywordsTemplate(\"Extract 8 keywords from: {text}\")\n    .build();","handlingStrategy":"validation","validationCode":"KeywordMetadataEnricher.Builder b = KeywordMetadataEnricher.builder().chatModel(chatModel);\nassert (templateSet && countSet) == false : \"Set either keywordsTemplate or keywordCount, not both\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one configuration style: count OR template.","Put the desired count inside the template text when using a custom template.","Review builder calls after copy-pasting examples.","Add a unit test asserting the enricher's prompt contains the expected count."],"tags":["rag","metadata","config"],"backgroundTag":"conflicting-config-options","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}