Skip to content

Commit 611b391

Browse files
committed
fix(document): fix embedding display with rich
1 parent 0cae644 commit 611b391

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

docarray/document/mixins/plot.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ def __rich_console__(self, console, options):
1717
my_table = Table('Attribute', 'Value', width=80, box=box.ROUNDED)
1818
for f in self.non_empty_fields:
1919
if f in ('embedding', 'tensor'):
20-
from .rich_embedding import ColorBoxEmbedding
20+
from ...math.ndarray import to_numpy_array
2121

22-
my_table.add_row(f, ColorBoxEmbedding(getattr(self, f)))
22+
v = to_numpy_array(getattr(self, f))
23+
if v.squeeze().ndim == 1:
24+
from .rich_embedding import ColorBoxEmbedding
25+
26+
v = ColorBoxEmbedding(v.squeeze())
27+
else:
28+
v = str(getattr(self, f))
29+
my_table.add_row(f, v)
2330
elif f not in ('id', 'chunks', 'matches'):
2431
my_table.add_row(f, str(getattr(self, f)))
2532
if my_table.rows:

docarray/document/mixins/rich_embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class ColorBoxEmbedding:
1515
def __init__(self, array):
16-
self._array = minmax_normalize(to_numpy_array(array).reshape(-1), (0, 5))
16+
self._array = minmax_normalize(array, (0, 5))
1717

1818
def __rich_console__(
1919
self, console: Console, options: ConsoleOptions

0 commit comments

Comments
 (0)