GH-5670: Fix type field indexing in RedisChatMemoryRepository#5731
Open
sachinnn99 wants to merge 1 commit intospring-projects:mainfrom
Open
GH-5670: Fix type field indexing in RedisChatMemoryRepository#5731sachinnn99 wants to merge 1 commit intospring-projects:mainfrom
sachinnn99 wants to merge 1 commit intospring-projects:mainfrom
Conversation
…ository Use TagField instead of TextField for the $.type JSON path in the RediSearch index schema. TextField performs full-text tokenization which breaks exact-match filtering on message type enum values, causing get() to only return USER type messages. Also update findByType() query to use Values.tags() (tag query syntax) instead of Values.value() (text query syntax), and fix raw query strings in tests to use tag field syntax (@type:{VALUE}). Closes spring-projects#5670 Signed-off-by: Sachin <52783123+sachinnn99@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RedisChatMemoryRepositorydefines the$.typefield as aTextFieldin the RediSearch index schema.TextFieldperforms full-text tokenization (lowercasing, stemming), which breaks exact-match filtering on message type enum values likeUSER,ASSISTANT,SYSTEM, andTOOL. This causesget()to only returnUSERtype messages.Fix: Change
$.typefromTextFieldtoTagFieldfor exact-match semantics, and updatefindByType()to useValues.tags()(tag query syntax) instead ofValues.value()(text query syntax). Also update raw query strings in tests to use tag field syntax (@type:{VALUE}).Changes
RedisChatMemoryRepository.java:TextField("$.type")→TagField("$.type")in index schema;Values.value()→Values.tags()infindByType()RedisChatMemoryAdvancedQueryIT.java: Update raw query strings from@type:VALUEto@type:{VALUE}Note for existing deployments
Since
initializeSchema()skips index creation when the index already exists, existing deployments need to drop and recreate the index for this fix to take effect:Then restart the application to create the index with the corrected schema.
Closes #5670