Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.3]Get rid of Rachet to fix failing build #649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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