-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for IndexHnswDenseVectors (#2254)
+ Add custom log appender to intercept and verify logging output + Clean up IndexInvertedDenseVectors + Fix code coverage (wasn't running properly before) + Other light clean-up
- Loading branch information
Showing
11 changed files
with
286 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for reproducible information retrieval research | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.anserini; | ||
|
||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
|
||
public class CustomAppender extends AbstractAppender { | ||
private String lastLog = null; | ||
|
||
public CustomAppender(String name) { | ||
super(name, null, null, true, null); | ||
} | ||
|
||
public String getLastLog() { | ||
return lastLog; | ||
} | ||
|
||
@Override | ||
public void append(LogEvent event) { | ||
lastLog = event.getMessage().getFormattedMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/io/anserini/index/IndexHnswDenseVectorsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for reproducible information retrieval research | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.anserini.index; | ||
|
||
import io.anserini.CustomAppender; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.core.config.Configurator; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Tests for {@link IndexHnswDenseVectors} | ||
*/ | ||
public class IndexHnswDenseVectorsTest { | ||
private static final Logger LOGGER = LogManager.getLogger(IndexHnswDenseVectors.class); | ||
private static CustomAppender APPENDER; | ||
|
||
@BeforeClass | ||
public static void setupClass() { | ||
APPENDER = new CustomAppender("CustomAppender"); | ||
APPENDER.start(); | ||
|
||
((org.apache.logging.log4j.core.Logger) LOGGER).addAppender(APPENDER); | ||
|
||
Configurator.setLevel(IndexHnswDenseVectors.class.getName(), Level.INFO); | ||
} | ||
|
||
@Test | ||
public void test1() throws Exception { | ||
List<String> args = new LinkedList<>(); | ||
args.add("-collection"); | ||
args.add("JsonDenseVectorCollection"); | ||
args.add("-input"); | ||
args.add("src/test/resources/sample_docs/openai_ada2/json_vector"); | ||
args.add("-index"); | ||
args.add("target/idx-sample-hnsw" + System.currentTimeMillis()); | ||
args.add("-generator"); | ||
args.add("LuceneDenseVectorDocumentGenerator"); | ||
args.add("-threads"); | ||
args.add("1"); | ||
args.add("-M"); | ||
args.add("16"); | ||
args.add("-efC"); | ||
args.add("100"); | ||
|
||
IndexHnswDenseVectors.main(args.toArray(new String[0])); | ||
|
||
System.out.println(APPENDER.getLastLog()); | ||
assertTrue(APPENDER.getLastLog().contains("Total 100 documents indexed")); | ||
} | ||
|
||
@AfterClass | ||
public static void teardownClass() { | ||
((org.apache.logging.log4j.core.Logger) LOGGER).removeAppender(APPENDER); | ||
} | ||
} |
Oops, something went wrong.