반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[900] Java High Level REST Client Query 본문

900gle shopping/api

[900] Java High Level REST Client Query

닉의네임 2022. 1. 24. 21:48
반응형

https://ldh-6019.tistory.com/201

 

[es] 검색결과를 검증해보자

True Positive(TP) : 실제 True인 정답을 True라고 예측 (정답) False Positive(FP) : 실제 False인 정답을 True라고 예측 (오답) False Negative(FN) : 실제 True인 정답을 False라고 예측 (오답) True Negative(..

ldh-6019.tistory.com

여기서 작업한 쿼리를 High Level REST Client 로 변경해보자

 

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

Vector<Double> vectors = TextEmbedding.getVector(
        TextEmbeddingDTO.builder()
                .tensorApiUrl("http://localhost:5000/vectors")
                .keyword(searchWord).build()
);

String[] includeFields = new String[]{"name", "category"};
String[] excludeFields = new String[]{"feature_vector"};
searchSourceBuilder.fetchSource(includeFields, excludeFields);

Map<String, Object> map = new HashMap<>();
map.put("query_vector", vectors);

ScriptScoreQueryBuilder functionScoreQueryBuilder = new ScriptScoreQueryBuilder(
        QueryBuilders.multiMatchQuery(searchWord, "name", "category"),
        new Script(
                Script.DEFAULT_SCRIPT_TYPE,
                Script.DEFAULT_SCRIPT_LANG,
                "cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['populr'].value / doc['name'].length + doc['category'].length", map)
);
searchSourceBuilder.query(
        functionScoreQueryBuilder
);
searchSourceBuilder.size(8);
searchRequest.source(searchSourceBuilder);

 

 

{
   "size":8,
   "query":{
      "script_score":{
         "query":{
            "multi_match":{
               "query":"나이키",
               "fields":[
                  "name, category^1.0"
               ],
               "type":"best_fields",
               "operator":"OR",
               "slop":0,
               "prefix_length":0,
               "max_expansions":50,
               "zero_terms_query":"NONE",
               "auto_generate_synonyms_phrase_query":true,
               "fuzzy_transpositions":true,
               "boost":1.0
            }
         },
         "script":{
            "source":"cosineSimilarity(params.query_vector, 'feature_vector') * doc['weight'].value * doc['populr'].value / doc['name'].length + doc['category'].length",
            "lang":"painless",
            "params":{
               "query_vector":[
                  8.812982123345137E-4,
                  0.026942647993564606,
                  -0.05886850133538246,
                  0.0026577573735266924,
                  -0.04516655206680298,
                  ........ 
                
               ]
            }
         },
         "boost":1.0
      }
   },
   "_source":{
      "includes":[
         "name",
         "category"
      ],
      "excludes":[
         "feature_vector"
      ]
   }
}

와.. 씨.. 이거 안되네 

템플릿으로 변경 해야것네

반응형

'900gle shopping > api' 카테고리의 다른 글

[900] Java High Level REST Client Query 3  (0) 2022.01.27
[900gle] Java High Level REST Client Query 2  (0) 2022.01.26
[900gle] Search Template  (0) 2022.01.25
[900] Search API  (0) 2022.01.19
[900gle] Text embedding API  (0) 2022.01.19
Comments