-
Notifications
You must be signed in to change notification settings - Fork 2
Bsb/py catch up #24
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
Bsb/py catch up #24
Changes from all commits
899d7cd
09968fd
7b4966d
d1221bb
975b6b4
b983a9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package com.redis.vl.extensions.messagehistory; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Enumeration of valid chat message roles. | ||
| * | ||
| * <p>Ported from Python: redisvl/extensions/message_history/schema.py (commit 23ecc77) | ||
| * | ||
| * <p>This enum serves as the single source of truth for valid roles in chat message history. The | ||
| * deprecated "llm" role is accepted for backward compatibility but is not a member of this enum. | ||
| */ | ||
| public enum ChatRole { | ||
| USER("user"), | ||
| ASSISTANT("assistant"), | ||
| SYSTEM("system"), | ||
| TOOL("tool"); | ||
|
|
||
| /** Deprecated role values that are accepted for backward compatibility. */ | ||
| private static final Set<String> DEPRECATED_ROLES = Set.of("llm"); | ||
|
|
||
| private final String value; | ||
|
|
||
| ChatRole(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| /** | ||
| * Get the string value of this role. | ||
| * | ||
| * @return The role string value | ||
| */ | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Coerce a string to a ChatRole enum value. | ||
| * | ||
| * @param role The role string | ||
| * @return The matching ChatRole, or null if not a standard role | ||
| */ | ||
| public static ChatRole fromString(String role) { | ||
| if (role == null || role.isEmpty()) { | ||
| return null; | ||
| } | ||
| for (ChatRole chatRole : values()) { | ||
| if (chatRole.value.equals(role)) { | ||
| return chatRole; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Check if a string is a valid role (including deprecated roles). | ||
| * | ||
| * @param role The role string to check | ||
| * @return true if the role is valid (either standard or deprecated) | ||
| */ | ||
| public static boolean isValidRole(String role) { | ||
| return fromString(role) != null || isDeprecatedRole(role); | ||
| } | ||
|
|
||
| /** | ||
| * Check if a string is a deprecated role value. | ||
| * | ||
| * @param role The role string to check | ||
| * @return true if the role is deprecated | ||
| */ | ||
| public static boolean isDeprecatedRole(String role) { | ||
| return DEPRECATED_ROLES.contains(role); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return value; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,9 +69,6 @@ | |
| @Getter | ||
| public final class MultiVectorQuery extends AggregationQuery { | ||
|
|
||
| /** Distance threshold for VECTOR_RANGE (hardcoded at 2.0 to include all eligible documents) */ | ||
| private static final double DISTANCE_THRESHOLD = 2.0; | ||
|
|
||
| private final List<Vector> vectors; | ||
| private final Filter filterExpression; | ||
| private final List<String> returnFields; | ||
|
|
@@ -111,8 +108,8 @@ public static Builder builder() { | |
| /** | ||
| * Build the Redis query string for multi-vector search. | ||
| * | ||
| * <p>Format: {@code @field1:[VECTOR_RANGE 2.0 $vector_0]=>{$YIELD_DISTANCE_AS: distance_0} | | ||
| * @field2:[VECTOR_RANGE 2.0 $vector_1]=>{$YIELD_DISTANCE_AS: distance_1}} | ||
| * <p>Format: {@code @field1:[VECTOR_RANGE max_dist $vector_0]=>{$YIELD_DISTANCE_AS: distance_0} AND | ||
| * @field2:[VECTOR_RANGE max_dist $vector_1]=>{$YIELD_DISTANCE_AS: distance_1}} | ||
| * | ||
| * @return Query string | ||
| */ | ||
|
|
@@ -123,8 +120,8 @@ public String toQueryString() { | |
| /** | ||
| * Build the Redis query string for multi-vector search. | ||
| * | ||
| * <p>Format: {@code @field1:[VECTOR_RANGE 2.0 $vector_0]=>{$YIELD_DISTANCE_AS: distance_0} | | ||
| * @field2:[VECTOR_RANGE 2.0 $vector_1]=>{$YIELD_DISTANCE_AS: distance_1}} | ||
| * <p>Format: {@code @field1:[VECTOR_RANGE max_dist $vector_0]=>{$YIELD_DISTANCE_AS: distance_0} AND | ||
| * @field2:[VECTOR_RANGE max_dist $vector_1]=>{$YIELD_DISTANCE_AS: distance_1}} | ||
| * | ||
| * @return Query string | ||
| */ | ||
|
|
@@ -136,12 +133,12 @@ public String buildQueryString() { | |
| Vector v = vectors.get(i); | ||
| String rangeQuery = | ||
| String.format( | ||
| "@%s:[VECTOR_RANGE %.1f $vector_%d]=>{$YIELD_DISTANCE_AS: distance_%d}", | ||
| v.getFieldName(), DISTANCE_THRESHOLD, i, i); | ||
| "@%s:[VECTOR_RANGE %s $vector_%d]=>{$YIELD_DISTANCE_AS: distance_%d}", | ||
| v.getFieldName(), v.getMaxDistance(), i, i); | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scientific notation in query string for small maxDistanceMedium Severity Using |
||
| rangeQueries.add(rangeQuery); | ||
| } | ||
|
|
||
| String baseQuery = String.join(" | ", rangeQueries); | ||
| String baseQuery = String.join(" AND ", rangeQueries); | ||
|
|
||
| // Add filter expression if present | ||
| if (filterExpression != null) { | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.