Skip to content

Commit

Permalink
Change the embedding vector target
Browse files Browse the repository at this point in the history
Signed-off-by: Songkan Tang <[email protected]>
  • Loading branch information
songkant-aws committed Aug 5, 2024
1 parent 13323fc commit 1f71793
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/org/opensearch/agent/tools/RCATool.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,26 @@ public <T> void runOption1(Map<String, ?> knowledgeBase, ActionListener<T> liste

@SuppressWarnings("unchecked")
public <T> void runOption2(Map<String, ?> knowledgeBase, ActionListener<T> listener) {
// input phenomenon's embedded dense vector
String phenomenon = (String) knowledgeBase.get("phenomenon");
List<RealVector> inputVector = getEmbeddedVector(Collections.singletonList(phenomenon));

// api response embedded dense vectors
// API response embedded vectors
List<Map<String, String>> causes = (List<Map<String, String>>) knowledgeBase.get("causes");
List<String> apiResponses = causes.stream()
List<String> responses = causes.stream()
.map(cause -> cause.get("response"))
.collect(Collectors.toList());
List<RealVector> rootCauseVectors = getEmbeddedVector(apiResponses);
List<RealVector> responseVectors = getEmbeddedVector(responses);

Map<String, Double> dotProductMap = IntStream.range(0, rootCauseVectors.size())
// expected API response embedded vectors
List<String> expectedResponses = causes.stream()
.map(cause -> cause.get("expected_response"))
.collect(Collectors.toList());
List<RealVector> expectedResponseVectors = getEmbeddedVector(expectedResponses);

Map<String, Double> dotProductMap = IntStream.range(0, causes.size())
.boxed()
.collect(Collectors.toMap(
i -> causes.get(i).get("reason"),
i -> inputVector.get(0).dotProduct(rootCauseVectors.get(i))
i -> responseVectors.get(i).dotProduct(expectedResponseVectors.get(i))
));

Optional<Map.Entry<String, Double>> mapEntry =
Expand Down

0 comments on commit 1f71793

Please sign in to comment.