From 5c7e1b74e58ddb7943999a8f0ca24cfb0d834884 Mon Sep 17 00:00:00 2001 From: Chris Knight Date: Fri, 3 May 2024 10:53:45 +0100 Subject: [PATCH] fix: Weaviate schema class name conversion which preserves PascalCase (#707) * fix: Weaviate schema class name conversion which preserves PascalCase * adding a test case for schema name conversion * linting * formatting --------- Co-authored-by: David S. Batista --- .../document_stores/weaviate/document_store.py | 4 +++- .../weaviate/tests/test_document_store.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py index ec66e07c3..1b6e95155 100644 --- a/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py +++ b/integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py @@ -166,7 +166,9 @@ def __init__( } else: # Set the class if not set - collection_settings["class"] = collection_settings.get("class", "default").capitalize() + _class_name = collection_settings.get("class", "Default") + _class_name = _class_name[0].upper() + _class_name[1:] + collection_settings["class"] = _class_name # Set the properties if they're not set collection_settings["properties"] = collection_settings.get("properties", DOCUMENT_COLLECTION_PROPERTIES) diff --git a/integrations/weaviate/tests/test_document_store.py b/integrations/weaviate/tests/test_document_store.py index cc76923f6..59a6ed2e3 100644 --- a/integrations/weaviate/tests/test_document_store.py +++ b/integrations/weaviate/tests/test_document_store.py @@ -664,3 +664,18 @@ def test_filter_documents_over_default_limit(self, document_store): document_store.write_documents(docs) with pytest.raises(DocumentStoreError): document_store.filter_documents({"field": "content", "operator": "==", "value": "This is some content"}) + + def test_schema_class_name_conversion_preserves_pascal_case(self): + collection_settings = {"class": "CaseDocument"} + doc_score = WeaviateDocumentStore( + url="http://localhost:8080", + collection_settings=collection_settings, + ) + assert doc_score._collection_settings["class"] == "CaseDocument" + + collection_settings = {"class": "lower_case_name"} + doc_score = WeaviateDocumentStore( + url="http://localhost:8080", + collection_settings=collection_settings, + ) + assert doc_score._collection_settings["class"] == "Lower_case_name"