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

Add HNSW support to the localhost API interface #2691

Merged
merged 18 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
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
10 changes: 4 additions & 6 deletions src/main/java/io/anserini/server/ControllerV1_0.java
Original file line number Diff line number Diff line change
@@ -50,8 +50,8 @@ public Map<String, Object> searchIndex(@PathVariable(value = "index", required =
@RequestParam(value = "hits", defaultValue = "10") int hits,
@RequestParam(value = "qid", defaultValue = "") String qid,
@RequestParam(value = "efSearch", defaultValue = "100") int efSearch,
@RequestParam(value = "encoder", required = true) String encoder,
@RequestParam(value = "queryGenerator", required = true) String queryGenerator) {
@RequestParam(value = "encoder", required = false) String encoder,
@RequestParam(value = "queryGenerator", required = false) String queryGenerator) {

if (index == null) {
index = DEFAULT_INDEX;
@@ -61,10 +61,8 @@ public Map<String, Object> searchIndex(@PathVariable(value = "index", required =
throw new IllegalArgumentException("Index " + index + " not found!");
}

if (index.contains(".hnsw")) {
if (encoder == null || queryGenerator == null) {
throw new IllegalArgumentException("HNSW indexes require both 'encoder' and 'queryGenerator' parameters");
}
if (index.contains(".hnsw") && (encoder == null || queryGenerator == null)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we add a new field in the Enum in IndexInfo so we don't have to do this janky check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indexes need to be paired with generators and encoders, right? so put that in IndexInfo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we add a new field in the Enum in IndexInfo so we don't have to do this janky check?

For each enum? Or something different

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, why not? Add another field in the enum denoting indexing type, the encoder, and the query generator?

throw new IllegalArgumentException("HNSW indexes require both 'encoder' and 'queryGenerator' parameters");
}

SearchService searchService = new SearchService(index);
11 changes: 2 additions & 9 deletions src/main/java/io/anserini/server/SearchService.java
Original file line number Diff line number Diff line change
@@ -137,15 +137,8 @@ private HnswDenseSearcher.Args createHnswArgs(int efSearch, String encoder, Stri
HnswDenseSearcher.Args args = new HnswDenseSearcher.Args();
args.index = indexDir;
args.efSearch = efSearch;
args.queryGenerator = queryGenerator != null ? queryGenerator : DEFAULT_QUERY_GENERATOR;

// Attempt to get encoder from IndexInfo, or use provided encoder
if (encoder != null) {
args.encoder = encoder;
} else if (IndexInfo.contains(prebuiltIndex)) {
IndexInfo info = IndexInfo.get(prebuiltIndex);
args.encoder = info.model.substring(0, info.model.indexOf(" w/ HNSW"));
}
args.encoder = encoder;
args.queryGenerator = queryGenerator;
return args;
}