Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeadie committed May 25, 2023
2 parents 4d3051e + c45bf6b commit 16858dc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 183 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Evaluated
* [PUFFINN](https://github.com/puffinn/puffinn) ![https://img.shields.io/github/stars/puffinn/puffinn?style=social](https://img.shields.io/github/stars/puffinn/puffinn?style=social)
* [N2](https://github.com/kakao/n2) ![https://img.shields.io/github/stars/kakao/n2?style=social](https://img.shields.io/github/stars/kakao/n2?style=social)
* [ScaNN](https://github.com/google-research/google-research/tree/master/scann)
* [Vearch](https://github.com/vearch/vearch) ![https://img.shields.io/github/stars/vearch/vearch?style=social](https://img.shields.io/github/stars/vearch/vearch?style=social)
* [Elasticsearch](https://github.com/elastic/elasticsearch) ![https://img.shields.io/github/stars/elastic/elasticsearch?style=social](https://img.shields.io/github/stars/elastic/elasticsearch?style=social): HNSW
* [Elastiknn](https://github.com/alexklibisz/elastiknn) ![https://img.shields.io/github/stars/alexklibisz/elastiknn?style=social](https://img.shields.io/github/stars/alexklibisz/elastiknn?style=social)
* [OpenSearch KNN](https://github.com/opensearch-project/k-NN) ![https://img.shields.io/github/stars/opensearch-project/k-NN?style=social](https://img.shields.io/github/stars/opensearch-project/k-NN?style=social)
Expand All @@ -39,9 +40,8 @@ Evaluated
* [vald](https://github.com/vdaas/vald) ![https://img.shields.io/github/stars/vdaas/vald?style=social](https://img.shields.io/github/stars/vdaas/vald?style=social)
* [Qdrant](https://github.com/qdrant/qdrant) ![https://img.shields.io/github/stars/qdrant/qdrant?style=social](https://img.shields.io/github/stars/qdrant/qdrant?style=social)
* [qsgngtlib](https://gitee.com/WPJIANG-gitee/hwtl_sdu-anns-qsgngtlib)
* [Milvus](https://github.com/milvus-io/milvus) ![https://img.shields.io/github/stars/milvus-io/milvus?style=social](https://img.shields.io/github/stars/milvus-io/milvus?style=social): [Knowhere](https://github.com/milvus-io/knowhere)
* [Milvus](https://github.com/milvus-io/milvus) ![https://img.shields.io/github/stars/milvus-io/milvus?style=social](https://img.shields.io/github/stars/milvus-io/milvus?style=social): [Knowhere](https://github.com/milvus-io/knowhere) [Glass](https://github.com/hhy3/pyglass)
* [pgvector](https://github.com/pgvector/pgvector) ![https://img.shields.io/github/stars/pgvector/pgvector?style=social](https://img.shields.io/github/stars/pgvector/pgvector?style=social)
* [Glass](https://github.com/hhy3/pyglass)

Data sets
=========
Expand Down
15 changes: 9 additions & 6 deletions ann_benchmarks/algorithms/elasticsearch/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, metric: str, dimension: int, index_options: dict):
self.num_candidates = 100

index_options_str = "-".join(sorted(f"{k}-{v}" for k, v in self.index_options.items()))
self.name = f"es-{metric}-{dimension}-{index_options_str}"
self.index_name = f"{metric}-{dimension}-{index_options_str}"
self.similarity_metric = self._vector_similarity_metric(metric)

self.client = Elasticsearch(["http://localhost:9200"])
Expand Down Expand Up @@ -72,22 +72,22 @@ def fit(self, X):
},
},
}
self.client.indices.create(index=self.name, settings=settings, mappings=mappings)
self.client.indices.create(index=self.index_name, settings=settings, mappings=mappings)

def gen():
for i, vec in enumerate(X):
yield {"_op_type": "index", "_index": self.name, "id": str(i), "vec": vec.tolist()}
yield {"_op_type": "index", "_index": self.index_name, "id": str(i), "vec": vec.tolist()}

print("Indexing ...")
(_, errors) = bulk(self.client, gen(), chunk_size=500, request_timeout=90)
if len(errors) != 0:
raise RuntimeError("Failed to index documents")

print("Force merge index ...")
self.client.indices.forcemerge(index=self.name, max_num_segments=1, request_timeout=900)
self.client.indices.forcemerge(index=self.index_name, max_num_segments=1, request_timeout=900)

print("Refreshing index ...")
self.client.indices.refresh(index=self.name, request_timeout=900)
self.client.indices.refresh(index=self.index_name, request_timeout=900)

def set_query_arguments(self, num_candidates):
self.num_candidates = num_candidates
Expand All @@ -105,7 +105,7 @@ def query(self, q, n):
}
}
res = self.client.search(
index=self.name,
index=self.index_name,
body=body,
size=n,
_source=False,
Expand All @@ -121,3 +121,6 @@ def batch_query(self, X, n):

def get_batch_results(self):
return self.batch_res

def __str__(self):
return f"Elasticsearch(index_options: {self.index_options}, num_canditates: {self.num_candidates})"
25 changes: 15 additions & 10 deletions ann_benchmarks/algorithms/opensearchknn/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def __init__(self, metric, dimension, method_param):
self.dimension = dimension
self.method_param = method_param
self.param_string = "-".join(k + "-" + str(v) for k, v in self.method_param.items()).lower()
self.name = f"os-{self.param_string}"
self.index_name = f"os-{self.param_string}"
self.client = OpenSearch(["http://localhost:9200"])
self.ef_search = None
self._wait_for_health_status()

def _wait_for_health_status(self, wait_seconds=30, status="yellow"):
Expand Down Expand Up @@ -53,37 +54,38 @@ def fit(self, X):
}
}

self.client.indices.create(self.name, body=body)
self.client.indices.put_mapping(mapping, self.name)
self.client.indices.create(self.index_name, body=body)
self.client.indices.put_mapping(mapping, self.index_name)

print("Uploading data to the Index:", self.name)
print("Uploading data to the Index:", self.index_name)

def gen():
for i, vec in enumerate(tqdm(X)):
yield {"_op_type": "index", "_index": self.name, "vec": vec.tolist(), "id": str(i + 1)}
yield {"_op_type": "index", "_index": self.index_name, "vec": vec.tolist(), "id": str(i + 1)}

(_, errors) = bulk(self.client, gen(), chunk_size=500, max_retries=2, request_timeout=10)
assert len(errors) == 0, errors

print("Force Merge...")
self.client.indices.forcemerge(self.name, max_num_segments=1, request_timeout=1000)
self.client.indices.forcemerge(self.index_name, max_num_segments=1, request_timeout=1000)

print("Refreshing the Index...")
self.client.indices.refresh(self.name, request_timeout=1000)
self.client.indices.refresh(self.index_name, request_timeout=1000)

print("Running Warmup API...")
res = urlopen(Request("http://localhost:9200/_plugins/_knn/warmup/" + self.name + "?pretty"))
res = urlopen(Request("http://localhost:9200/_plugins/_knn/warmup/" + self.index_name + "?pretty"))
print(res.read().decode("utf-8"))

def set_query_arguments(self, ef):
self.ef_search = ef
body = {"settings": {"index": {"knn.algo_param.ef_search": ef}}}
self.client.indices.put_settings(body=body)

def query(self, q, n):
body = {"query": {"knn": {"vec": {"vector": q.tolist(), "k": n}}}}

res = self.client.search(
index=self.name,
index=self.index_name,
body=body,
size=n,
_source=False,
Expand All @@ -102,4 +104,7 @@ def get_batch_results(self):
return self.batch_res

def freeIndex(self):
self.client.indices.delete(index=self.name)
self.client.indices.delete(index=self.index_name)

def __str__(self):
return f"OpenSearch(index_options: {self.method_param}, ef_search: {self.ef_search})"
165 changes: 0 additions & 165 deletions ann_benchmarks/algorithms/qdrant.py

This file was deleted.

0 comments on commit 16858dc

Please sign in to comment.