com.dingtalk.baymax.framework.sdk.mercury.domain.Document Maven / Gradle / Ivy
package com.dingtalk.baymax.framework.sdk.mercury.domain;
import com.dingtalk.baymax.framework.sdk.mercury.util.VectorUtils;
import java.io.Serializable;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
/**
* 文档类
*
* @author xiaoxuan.lp
*/
public class Document implements Serializable {
private String uniqueId;
private String pageContent;
private Map metadata;
private List embedding;
private Integer index;
public static Comparator cosineSimilarityComparator(List target) {
return (d1, d2) -> {
double d = VectorUtils.cosineSimilarity(d1.getEmbedding(), target) - VectorUtils.cosineSimilarity(d2.getEmbedding(), target);
return d > 0 ? 1 : d < 0 ? -1 : 0;
};
}
public String getUniqueId() {
return uniqueId;
}
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
public String getPageContent() {
return pageContent;
}
public void setPageContent(String pageContent) {
this.pageContent = pageContent;
}
public Map getMetadata() {
return metadata;
}
public void setMetadata(Map metadata) {
this.metadata = metadata;
}
public List getEmbedding() {
return embedding;
}
public void setEmbedding(List embedding) {
this.embedding = embedding;
}
public Integer getIndex() {
return index;
}
public void setIndex(Integer index) {
this.index = index;
}
}