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

fix: support long texts for labels in ElasticsearchDocumentStore #3346

Merged
merged 16 commits into from
Nov 2, 2022
Merged
4 changes: 2 additions & 2 deletions haystack/document_stores/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ def _create_label_index(self, index_name: str, headers: Optional[Dict[str, str]]
"mappings": {
"properties": {
"query": {"type": "text"},
"answer": {"type": "flattened"}, # light-weight but less search options than full object
"document": {"type": "flattened"},
"answer": {"type": "nested"},
"document": {"type": "nested"},
"is_correct_answer": {"type": "boolean"},
"is_correct_document": {"type": "boolean"},
"origin": {"type": "keyword"}, # e.g. user-feedback or gold-label
Expand Down
24 changes: 24 additions & 0 deletions test/document_stores/test_document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,30 @@ def test_labels(document_store: BaseDocumentStore):
assert len(labels) == 0


@pytest.mark.parametrize("document_store", ["elasticsearch", "opensearch"], indirect=True)
def test_labels_with_long_texts(document_store: BaseDocumentStore):
document_store.delete_index("label")
label = Label(
query="question1",
answer=Answer(
answer="answer",
type="extractive",
score=0.0,
context="something " * 10_000,
offsets_in_document=[Span(start=12, end=14)],
offsets_in_context=[Span(start=12, end=14)],
),
is_correct_answer=True,
is_correct_document=True,
document=Document(content="something " * 10_000, id="123"),
origin="gold-label",
)
document_store.write_labels(labels=[label], index="label")
labels = document_store.get_all_labels(index="label")
assert len(labels) == 1
assert label == labels[0]


# exclude weaviate because it does not support storing labels
@pytest.mark.parametrize("document_store", ["elasticsearch", "faiss", "memory", "milvus1", "pinecone"], indirect=True)
def test_multilabel(document_store: BaseDocumentStore):
Expand Down