pull/1/head
liu 11 months ago
parent ee03e03591
commit 083cd38c29

@ -26,16 +26,16 @@ public class VectorSimilarityConfiguration {
.withURI(redisVectorProperties.getUri())
.withPrefix(redisVectorProperties.getPrefix())
.withIndexName(redisVectorProperties.getIndexName())
// 定义搜索过滤器使用的元数据字段
// 定义搜索过滤器使用的元数据字段(!!!!!!!!千万重要,数据类型一定和实际插入的一致,否则会导致查询不到!!!!!!!!)
.withMetadataFields(
// 问题的ID
RedisVectorStore.MetadataField.tag("questionId"),
// 关联字典ID
//关联字典ID
RedisVectorStore.MetadataField.tag("dictId"),
// 标准问ID
RedisVectorStore.MetadataField.tag("standardQuestionId"),
// 类型 1标准问 2相似问 3自定义
RedisVectorStore.MetadataField.tag("type"))
RedisVectorStore.MetadataField.numeric("type"))
.build();
return new RedisVectorStore(config, vectorEmbeddingClient);
}

@ -82,16 +82,18 @@ public class TestController {
List<AskTemplateQuestionLibrary> list = askTemplateQuestionLibraryService.list();
for (AskTemplateQuestionLibrary askTemplateQuestionLibrary : list) {
String description = askTemplateQuestionLibrary.getDescription();
redisVectorStore.add(List.of(new Document(description, Map.of("type", "1",
"standardQuestionId", askTemplateQuestionLibrary.getId(),
"questionId", askTemplateQuestionLibrary.getId(),
"dictId", askTemplateQuestionLibrary.getDictId()))));
redisVectorStore.add(List.of(new Document(description,
Map.of("type", "1",
"standardQuestionId", askTemplateQuestionLibrary.getId(),
"questionId", askTemplateQuestionLibrary.getId(),
"dictId", askTemplateQuestionLibrary.getDictId()))));
List<String> question = askTemplateQuestionLibrary.getQuestion();
for (String s : question) {
redisVectorStore.add(List.of(new Document(s, Map.of("type", "2",
"standardQuestionId", askTemplateQuestionLibrary.getId(),
"questionId", askTemplateQuestionLibrary.getId(),
"dictId", askTemplateQuestionLibrary.getDictId()))));
redisVectorStore.add(List.of(new Document(s,
Map.of("type", "2",
"standardQuestionId", askTemplateQuestionLibrary.getId(),
"questionId", askTemplateQuestionLibrary.getId(),
"dictId", askTemplateQuestionLibrary.getDictId()))));
}
}
}
@ -101,7 +103,7 @@ public class TestController {
public List<Document> testQuestion(String question) {
List<Document> documents = redisVectorStore.similaritySearch(SearchRequest
.query(question)
.withTopK(5).withSimilarityThreshold(0.5));
.withTopK(5));
// return documents.stream().map(document -> Map.of("content", document.getContent(), "id", document.getId())).collect(Collectors.toList());
documents.forEach(e -> {
double v = Double.parseDouble(String.valueOf(e.getMetadata().get("vector_score")));

Loading…
Cancel
Save