Skip to content

Commit

Permalink
[Backport 1.3]Get rid of Rachet to fix failing build (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#649)

* Get rid of Rachet to fix failing build

Signed-off-by: Naveen <[email protected]>

* Apply spotless on other files in project

Signed-off-by: Naveen <[email protected]>

Signed-off-by: Naveen <[email protected]>
  • Loading branch information
naveentatikonda authored Dec 5, 2022
1 parent c66db06 commit 55a52a8
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 129 deletions.
3 changes: 1 addition & 2 deletions gradle/formatting.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ allprojects {
project.apply plugin: "com.diffplug.spotless"
spotless {
java {
ratchetFrom 'origin/1.x'
target '**/*.java'
target 'src/**/*.java'
removeUnusedImports()
eclipse().configFile rootProject.file('buildSrc/formatterConfig.xml')
trimTrailingWhitespace()
Expand Down
146 changes: 74 additions & 72 deletions src/main/java/org/opensearch/knn/index/SpaceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,86 +21,88 @@
* nmslib calls the inner_product space "negdotprod". This translation should take place in the nmslib's jni layer.
*/
public enum SpaceType {
L2("l2") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
COSINESIMIL("cosinesimil") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
L1("l1") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
LINF("linf") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
INNER_PRODUCT("innerproduct") {
/**
* The inner product has a range of [-Float.MAX_VALUE, Float.MAX_VALUE], with a more similar result being
* represented by a more negative value. In Lucene, scores have to be in the range of [0, Float.MAX_VALUE],
* where a higher score represents a more similar result. So, we convert here.
*
* @param rawScore score returned from underlying library
* @return Lucene scaled score
*/
@Override
public float scoreTranslation(float rawScore) {
if (rawScore >= 0) {
return 1 / (1 + rawScore);
}
return -rawScore + 1;
}
},
HAMMING_BIT("hammingbit") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
};
L2("l2") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
COSINESIMIL("cosinesimil") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
L1("l1") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
LINF("linf") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
},
INNER_PRODUCT("innerproduct") {
/**
* The inner product has a range of [-Float.MAX_VALUE, Float.MAX_VALUE], with a more similar result being
* represented by a more negative value. In Lucene, scores have to be in the range of [0, Float.MAX_VALUE],
* where a higher score represents a more similar result. So, we convert here.
*
* @param rawScore score returned from underlying library
* @return Lucene scaled score
*/
@Override
public float scoreTranslation(float rawScore) {
if (rawScore >= 0) {
return 1 / (1 + rawScore);
}
return -rawScore + 1;
}
},
HAMMING_BIT("hammingbit") {
@Override
public float scoreTranslation(float rawScore) {
return 1 / (1 + rawScore);
}
};

public static SpaceType DEFAULT = L2;
public static SpaceType DEFAULT = L2;

private final String value;
private final String value;

SpaceType(String value) {
this.value = value;
}
SpaceType(String value) {
this.value = value;
}

public abstract float scoreTranslation(float rawScore);
public abstract float scoreTranslation(float rawScore);

/**
* Get space type name in engine
*
* @return name
*/
public String getValue() { return value; }
/**
* Get space type name in engine
*
* @return name
*/
public String getValue() {
return value;
}

public static Set<String> getValues() {
Set<String> values = new HashSet<>();
public static Set<String> getValues() {
Set<String> values = new HashSet<>();

for (SpaceType spaceType : SpaceType.values()) {
values.add(spaceType.getValue());
for (SpaceType spaceType : SpaceType.values()) {
values.add(spaceType.getValue());
}
return values;
}
return values;
}

public static SpaceType getSpace(String spaceTypeName) {
for (SpaceType currentSpaceType : SpaceType.values()) {
if (currentSpaceType.getValue().equalsIgnoreCase(spaceTypeName)) {
return currentSpaceType;
}
public static SpaceType getSpace(String spaceTypeName) {
for (SpaceType currentSpaceType : SpaceType.values()) {
if (currentSpaceType.getValue().equalsIgnoreCase(spaceTypeName)) {
return currentSpaceType;
}
}
throw new IllegalArgumentException("Unable to find space: " + spaceTypeName);
}
throw new IllegalArgumentException("Unable to find space: " + spaceTypeName);
}
}
Loading

0 comments on commit 55a52a8

Please sign in to comment.