-
Notifications
You must be signed in to change notification settings - Fork 55
java-client: extend LongTermMemoryService to take TagFilters as params #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lygaret
wants to merge
1
commit into
redis:main
Choose a base branch
from
lygaret:feat/java-tagfilter-searchrequest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...agent-memory-client-java/src/main/java/com/redis/agentmemory/models/common/TagFilter.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.redis.agentmemory.models.common; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Filter for tag-style string fields (user_id, session_id, namespace, topics, entities). | ||
| * Match the server-side TagFilter; supports eq, ne, any, all, and startswith operators. | ||
| * | ||
| * <p> | ||
| * Example — match any of several user IDs in one search: | ||
| * <pre>{@code | ||
| * SearchRequest.builder() | ||
| * .userId(TagFilter.any("user-123", "__account__")) | ||
| * .build() | ||
| * }</pre> | ||
| */ | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public class TagFilter { | ||
|
|
||
| @Nullable | ||
| private String eq; | ||
|
|
||
| @Nullable | ||
| private String ne; | ||
|
|
||
| @Nullable | ||
| @JsonProperty("any") | ||
| private List<String> any; | ||
|
|
||
| @Nullable | ||
| @JsonProperty("all") | ||
| private List<String> all; | ||
|
|
||
| @Nullable | ||
| private String startswith; | ||
|
|
||
| private TagFilter() {} | ||
|
|
||
| public static TagFilter eq(@NotNull String value) { | ||
| TagFilter f = new TagFilter(); | ||
| f.eq = value; | ||
| return f; | ||
| } | ||
|
|
||
| public static TagFilter ne(@NotNull String value) { | ||
| TagFilter f = new TagFilter(); | ||
| f.ne = value; | ||
| return f; | ||
| } | ||
|
|
||
| public static TagFilter any(@NotNull List<String> values) { | ||
| TagFilter f = new TagFilter(); | ||
| f.any = List.copyOf(values); | ||
| return f; | ||
| } | ||
|
|
||
| public static TagFilter any(@NotNull String... values) { | ||
| return any(Arrays.asList(values)); | ||
| } | ||
|
|
||
| public static TagFilter all(@NotNull List<String> values) { | ||
| TagFilter f = new TagFilter(); | ||
| f.all = List.copyOf(values); | ||
| return f; | ||
| } | ||
|
|
||
| public static TagFilter all(@NotNull String... values) { | ||
| return all(Arrays.asList(values)); | ||
| } | ||
|
|
||
| public static TagFilter startsWith(@NotNull String prefix) { | ||
| TagFilter f = new TagFilter(); | ||
| f.startswith = prefix; | ||
| return f; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String getEq() { return eq; } | ||
|
|
||
| @Nullable | ||
| public String getNe() { return ne; } | ||
|
|
||
| @Nullable | ||
| public List<String> getAny() { return any; } | ||
|
|
||
| @Nullable | ||
| public List<String> getAll() { return all; } | ||
|
|
||
| @Nullable | ||
| public String getStartswith() { return startswith; } | ||
| } | ||
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
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
55 changes: 55 additions & 0 deletions
55
...t-memory-client-java/src/test/java/com/redis/agentmemory/models/common/TagFilterTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.redis.agentmemory.models.common; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class TagFilterTest { | ||
|
|
||
| private ObjectMapper objectMapper; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| objectMapper = new ObjectMapper(); | ||
| } | ||
|
|
||
| @Test | ||
| void eq_serializesToEqOperator() throws Exception { | ||
| String json = objectMapper.writeValueAsString(TagFilter.eq("user-123")); | ||
| assertEquals("{\"eq\":\"user-123\"}", json); | ||
| } | ||
|
|
||
| @Test | ||
| void ne_serializesToNeOperator() throws Exception { | ||
| String json = objectMapper.writeValueAsString(TagFilter.ne("user-123")); | ||
| assertEquals("{\"ne\":\"user-123\"}", json); | ||
| } | ||
|
|
||
| @Test | ||
| void any_varargs_serializesToAnyOperator() throws Exception { | ||
| String json = objectMapper.writeValueAsString(TagFilter.any("user-123", "__account__")); | ||
| assertEquals("{\"any\":[\"user-123\",\"__account__\"]}", json); | ||
| } | ||
|
|
||
| @Test | ||
| void any_list_serializesToAnyOperator() throws Exception { | ||
| String json = objectMapper.writeValueAsString(TagFilter.any(List.of("a", "b", "c"))); | ||
| assertEquals("{\"any\":[\"a\",\"b\",\"c\"]}", json); | ||
| } | ||
|
|
||
| @Test | ||
| void all_serializesToAllOperator() throws Exception { | ||
| String json = objectMapper.writeValueAsString(TagFilter.all("x", "y")); | ||
| assertEquals("{\"all\":[\"x\",\"y\"]}", json); | ||
| } | ||
|
|
||
| @Test | ||
| void startsWith_serializesToStartswithOperator() throws Exception { | ||
| String json = objectMapper.writeValueAsString(TagFilter.startsWith("tenant-")); | ||
| assertEquals("{\"startswith\":\"tenant-\"}", json); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty any/all filters rejected
Medium Severity
TagFilter.anyandTagFilter.allaccept empty lists (including zero-arg varargs), producing JSON such as{"any":[]}. The serverTagFilterrejects emptyany/alllists, so searches built this way fail validation. List-basedSearchRequesthelpers omit empty topic/entity lists, but theTagFilterpath does not.Additional Locations (1)
agent-memory-client/agent-memory-client-java/src/main/java/com/redis/agentmemory/services/LongTermMemoryService.java#L100-L105Reviewed by Cursor Bugbot for commit 457057f. Configure here.