Repository: deepset-ai/haystack

Issue:
Schema representation bug on Jupyter
**Describe the bug**
While doing tests with WeaviateDocumentStore on a JupyterHub instance, I noticed the Document schema `__repr__` has issues.

**Error message**
```
ValueError                                Traceback (most recent call last)
File /usr/local/lib/python3.9/site-packages/IPython/core/formatters.py:707, in PlainTextFormatter.__call__(self, obj)
    700 stream = StringIO()
    701 printer = pretty.RepresentationPrinter(stream, self.verbose,
    702     self.max_width, self.newline,
    703     max_seq_length=self.max_seq_length,
    704     singleton_pprinters=self.singleton_printers,
    705     type_pprinters=self.type_printers,
    706     deferred_pprinters=self.deferred_printers)
--> 707 printer.pretty(obj)
    708 printer.flush()
    709 return stream.getvalue()

File /usr/local/lib/python3.9/site-packages/IPython/lib/pretty.py:410, in RepresentationPrinter.pretty(self, obj)
    407                         return meth(obj, self, cycle)
    408                 if cls is not object \
    409                         and callable(cls.__dict__.get('__repr__')):
--> 410                     return _repr_pprint(obj, self, cycle)
    412     return _default_pprint(obj, self, cycle)
    413 finally:

File /usr/local/lib/python3.9/site-packages/IPython/lib/pretty.py:778, in _repr_pprint(obj, p, cycle)
    776 """A pprint that just redirects to the normal repr function."""
    777 # Find newlines and replace them with p.break_()
--> 778 output = repr(obj)
    779 lines = output.splitlines()
    780 with p.group():

File ~/.local/lib/python3.9/site-packages/haystack/schema.py:229, in Document.__repr__(self)
    227 def __repr__(self):
    228     values = self.to_dict()
--> 229     if values.get("embedding", False):
    230         values["embedding"] = f"<embedding of shape {values['embedding'].get('shape', '[no shape]')}>"
    231     return f"<Document: {str(self.to_dict())}>"

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```
**Expected behavior**
Schema should support correctly string representation for tests on Jupyter

**Additional context**
Add any other context about the problem here, like document types / preprocessing steps / settings of reader etc.

**To Reproduce**
```
from haystack.document_stores import WeaviateDocumentStore
from haystack.schema import Document

weaviate = WeaviateDocumentStore(host='http://weaviate.weaviate.svc.cluster.local',port=80,index='teste',embedding_dim=384)
weaviate.write_documents([
Document(
   content='teste 2'     
)])

weaviate.get_all_documents()
```

**FAQ Check**
- [x] Have you had a look at [our new FAQ page](https://haystack.deepset.ai/overview/faq)?

**System:**
 - OS: JupyterHub base-notebook docker image
 - GPU/CPU: 
 - Haystack version (commit or version number): 1.9.1
 - DocumentStore: WeaviateDocumentStore
 - Reader:
 - Retriever:



Discussion:

Resolving patch:
diff --git a/haystack/schema.py b/haystack/schema.py
--- a/haystack/schema.py
+++ b/haystack/schema.py
@@ -228,16 +228,17 @@ def __eq__(self, other):
         )
 
     def __repr__(self):
-        values = self.to_dict()
-        if values.get("embedding", None) is not None:
-            values["embedding"] = f"<embedding of shape {getattr(values['embedding'], 'shape', '[no shape]')}>"
-        return f"<Document: {str(self.to_dict())}>"
+        doc_dict = self.to_dict()
+        embedding = doc_dict.get("embedding", None)
+        if embedding is not None:
+            doc_dict["embedding"] = f"<embedding of shape {getattr(embedding, 'shape', '[no shape]')}>"
+        return f"<Document: {str(doc_dict)}>"
 
     def __str__(self):
         # In some cases, self.content is None (therefore not subscriptable)
         if self.content is None:
             return f"<Document: id={self.id}, content=None>"
-        return f"<Document: id={self.id}, content='{self.content[:100]} {'...' if len(self.content) > 100 else ''}'>"
+        return f"<Document: id={self.id}, content='{self.content[:100]}{'...' if len(self.content) > 100 else ''}'>"
 
     def __lt__(self, other):
         """Enable sorting of Documents by score"""
@@ -265,7 +266,7 @@ def __str__(self):
         # In some cases, self.content is None (therefore not subscriptable)
         if self.content is None:
             return f"<SpeechDocument: id={self.id}, content=None>"
-        return f"<SpeechDocument: id={self.id}, content='{self.content[:100]} {'...' if len(self.content) > 100 else ''}', content_audio={self.content_audio}>"
+        return f"<SpeechDocument: id={self.id}, content='{self.content[:100]}{'...' if len(self.content) > 100 else ''}', content_audio={self.content_audio}>"
 
     def to_dict(self, field_map={}) -> Dict:
         dictionary = super().to_dict(field_map=field_map)


Test patch: