jelmerk / hnswlib

Java library for approximate nearest neighbors search using Hierarchical Navigable Small World graphs
Apache License 2.0
260 stars 56 forks source link

Language Level and Working Example #8

Closed ashfaq92 closed 5 years ago

ashfaq92 commented 5 years ago

Hi! thanks for the great work. I was implementing this project in intellijIdea but it fails everytime. The error is (something) is not supported at Language Level13. Then I have to change language level (from 7,8) then the problem arises in other parts of code. These imports don't work too (in intellijIdea):

import org.eclipse.collections.api.list.primitive.MutableIntList;
import org.eclipse.collections.api.map.primitive.MutableObjectIntMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.tuple.primitive.ObjectIntPair;
import org.eclipse.collections.api.tuple.primitive.ObjectLongPair;
import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList;
import org.eclipse.collections.impl.map.mutable.primitive.ObjectIntHashMap;
import org.eclipse.collections.impl.map.mutable.primitive.ObjectLongHashMap;

Even if we open the hnswlib-core project in eclipse its pom gives error

Kindly specify in which language level this project works and give a small java interface example to algorithm (like this in python) (this in R) so that beginners may use this into their works.

A small compact working example would be highly appreciated. Thanks.

jelmerk commented 5 years ago

Hi @ashfaq92

I am not sure why you cannot open the project in intellij. It's my IDE of choice and i just tried doing a clean checkout of the project and importing it and it works just fine on my mac

By any chance did you not import it from a maven project ? That would explain why eclipse collections is not resolved

I tried importing the project in eclipse and indeed that does not seem to be straightforward (as things tend to be in eclipse land) I'll see if i can make some changes to make importing the project in eclipse easier

With regards to examples. This library actually comes with a decent amount of examples.

For java :

https://github.com/jelmerk/hnswlib/blob/master/hnswlib-examples/hnswlib-examples-java/src/main/java/com/github/jelmerk/knn/examples/FastText.java

For Scala :

https://github.com/jelmerk/hnswlib/blob/master/hnswlib-examples/hnswlib-examples-scala/src/main/scala/com/github/jelmerk/knn/examples/FastText.scala

For Pyspark :

https://github.com/jelmerk/hnswlib/blob/master/hnswlib-pyspark/tests/test_hnsw.py

ashfaq92 commented 5 years ago

@jelmerk if it works good in intellijIdea, I have no issues because it is my favorite IDE too. But is have this issue while importing hnswlib-core as project. Maybe that's because i am only opening hnswlib-core as a standalone project rather than opening whole project. Annotation 2019-11-15 115307

jelmerk commented 5 years ago

You would have to run

mvnw.cmd clean install

From the root project once in order to install the artifacts this module depends on into your local maven repository

After that it should work

I would recommend simply opening in the parent project in your idea though

ashfaq92 commented 5 years ago

@jelmerk thanks for recommendation. Opening whole project in idea worked. I am about to close this issue. It would be great if you please provide a metric space example (like this ) for the code. The examples you provided are for non-metric space but there are no guidelines how to construct HNSW Graph for metric space. It should work as follows: Construct a HNSW graph by inserting some random numbers (2 dimensional is best) in it. Generate a random query point. Find nearest neighbor(s) for that query point from Graph. Thanks again <3