Skip to content

Commit

Permalink
Fix OpenSearchDocumentStore's __init__ (#2498)
Browse files Browse the repository at this point in the history
* Move super in OpenSearchDocumentStore and add small test

* Update Documentation & Code Style

* Add Opensearch container to the CI

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ZanSara and github-actions[bot] authored May 5, 2022
1 parent c7e39e5 commit f3e0ba4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/linux_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ jobs:
- name: Run Elasticsearch
run: docker run -d -p 9200:9200 -e "discovery.type=single-node" -e "ES_JAVA_OPTS=-Xms128m -Xmx128m" elasticsearch:7.9.2

- name: Run Opensearch
run: docker run -d -p 9201:9200 -p 9600:9600 -e "discovery.type=single-node" opensearchproject/opensearch:1.2.4

- name: Run Milvus
run: |
cd ../../ # Avoid causing permission issues on hashFiles later by creating unreadable folders like "volumes"
Expand Down
6 changes: 3 additions & 3 deletions haystack/document_stores/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,9 @@ def __init__(
Synonym or Synonym_graph to handle synonyms, including multi-word synonyms correctly during the analysis process.
More info at https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-graph-tokenfilter.html
"""
self.embeddings_field_supports_similarity = False
self.similarity_to_space_type = {"cosine": "cosinesimil", "dot_product": "innerproduct", "l2": "l2"}
self.space_type_to_similarity = {v: k for k, v in self.similarity_to_space_type.items()}
super().__init__(
scheme=scheme,
username=username,
Expand Down Expand Up @@ -1759,9 +1762,6 @@ def __init__(
synonym_type=synonym_type,
use_system_proxy=use_system_proxy,
)
self.embeddings_field_supports_similarity = False
self.similarity_to_space_type = {"cosine": "cosinesimil", "dot_product": "innerproduct", "l2": "l2"}
self.space_type_to_similarity = {v: k for k, v in self.similarity_to_space_type.items()}

def query_by_embedding(
self,
Expand Down
12 changes: 11 additions & 1 deletion test/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
DC_TEST_INDEX,
SAMPLES_PATH,
)
from haystack.document_stores import WeaviateDocumentStore, DeepsetCloudDocumentStore, InMemoryDocumentStore
from haystack.document_stores import (
OpenSearchDocumentStore,
WeaviateDocumentStore,
DeepsetCloudDocumentStore,
InMemoryDocumentStore,
)
from haystack.document_stores.base import BaseDocumentStore
from haystack.document_stores.es_converter import elasticsearch_index_to_document_store
from haystack.errors import DuplicateDocumentError
Expand Down Expand Up @@ -89,6 +94,11 @@ def test_init_elastic_client():
_ = ElasticsearchDocumentStore(host=["localhost"], port=[9200], api_key="test", api_key_id="test")


@pytest.mark.elasticsearch
def test_init_opensearch_client():
OpenSearchDocumentStore(index="test_index", port=9201)


@pytest.mark.elasticsearch
def test_init_elastic_doc_store_with_index_recreation():
index_name = "test_index_recreation"
Expand Down

0 comments on commit f3e0ba4

Please sign in to comment.