Add equals() and hashCode() for Prompt and SearchRequest

This commit is contained in:
Craig Walls
2023-11-22 13:19:59 -07:00
committed by Mark Pollack
parent ad7af600fd
commit ffe44e24e2
2 changed files with 40 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import org.springframework.ai.prompt.messages.UserMessage;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public class Prompt {
@@ -55,4 +56,19 @@ public class Prompt {
return "Prompt{" + "messages=" + messages + '}';
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Prompt prompt = (Prompt) o;
return Objects.equals(messages, prompt.messages);
}
@Override
public int hashCode() {
return Objects.hash(messages);
}
}

View File

@@ -22,6 +22,8 @@ import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder;
import org.springframework.ai.vectorstore.filter.FilterExpressionTextParser;
import org.springframework.util.Assert;
import java.util.Objects;
/**
* Similarity search request builder. Use the {@link #query(String)}, {@link #defaults()}
* or {@link #from(SearchRequest)} factory methods to create a new {@link SearchRequest}
@@ -248,4 +250,26 @@ public class SearchRequest {
return this.filterExpression != null;
}
@Override
public String toString() {
return "SearchRequest{" + "query='" + query + '\'' + ", topK=" + topK + ", similarityThreshold="
+ similarityThreshold + ", filterExpression=" + filterExpression + '}';
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SearchRequest that = (SearchRequest) o;
return topK == that.topK && Double.compare(that.similarityThreshold, similarityThreshold) == 0
&& Objects.equals(query, that.query) && Objects.equals(filterExpression, that.filterExpression);
}
@Override
public int hashCode() {
return Objects.hash(query, topK, similarityThreshold, filterExpression);
}
}