Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 898 Bytes

README.md

File metadata and controls

29 lines (19 loc) · 898 Bytes

Maven Central Javadoc

hnswlib-core

Core hnsw library.

Example usage

import com.github.jelmerk.knn.*;
import com.github.jelmerk.knn.hnsw.*;

HnswIndex<String, float[], Word, Float> index = HnswIndex
    .newBuilder(DistanceFunctions.FLOAT_COSINE_DISTANCE, dimensions, words.size())
        .withM(10)
        .build();

index.addAll(words);

List<SearchResult<Word, Float>> nearest = index.findNeighbors("king", 10);

for (SearchResult<Word, Float> result : nearest) {
    System.out.println(result.item().id() + " " + result.getDistance());
}