Skip to content

Commit bb7cc10

Browse files
committed
fix: embedder tutorial
1 parent 7137548 commit bb7cc10

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

docs/source/tutorials/embedder.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ If we want to decreate the embedding dimension to only 256 to save memory, we ca
124124

125125
.. code-block:: python
126126
127-
from adalflow.core.types import Embedding
127+
from adalflow.core.types import Embedding, EmbedderOutput
128128
from adalflow.core.functional import normalize_vector
129129
from typing import List
130130
from adalflow.core.component import Component
@@ -139,14 +139,14 @@ If we want to decreate the embedding dimension to only 256 to save memory, we ca
139139
assert self.new_dim < self.old_dim, "new_dim should be less than old_dim"
140140
141141
def call(self, input: List[Embedding]) -> List[Embedding]:
142-
output: List[Embedding] = deepcopy(input)
143-
for embedding in output:
142+
output: EmbedderOutput = deepcopy(input)
143+
for embedding in output.data:
144144
old_embedding = embedding.embedding
145145
new_embedding = old_embedding[: self.new_dim]
146146
if self.normalize:
147147
new_embedding = normalize_vector(new_embedding)
148148
embedding.embedding = new_embedding
149-
return output
149+
return output.data
150150
151151
def _extra_repr(self) -> str:
152152
repr_str = f"old_dim={self.old_dim}, new_dim={self.new_dim}, normalize={self.normalize}"

tutorials/embedder.ipynb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,11 @@
499499
},
500500
{
501501
"cell_type": "code",
502-
"execution_count": 29,
502+
"execution_count": null,
503503
"metadata": {},
504504
"outputs": [],
505505
"source": [
506-
"from adalflow.core.types import Embedding\n",
506+
"from adalflow.core.types import Embedding, EmbedderOutput\n",
507507
"from adalflow.core.functional import normalize_vector\n",
508508
"from typing import List\n",
509509
"from adalflow.core.component import Component\n",
@@ -517,18 +517,14 @@
517517
" assert self.new_dim < self.old_dim, \"new_dim should be less than old_dim\"\n",
518518
"\n",
519519
" def call(self, input: List[Embedding]) -> List[Embedding]:\n",
520-
" output: List[Embedding] = deepcopy(input)\n",
521-
" for embedding in output:\n",
520+
" output: EmbedderOutput = deepcopy(input)\n",
521+
" for embedding in output.data:\n",
522522
" old_embedding = embedding.embedding\n",
523523
" new_embedding = old_embedding[: self.new_dim]\n",
524524
" if self.normalize:\n",
525525
" new_embedding = normalize_vector(new_embedding)\n",
526526
" embedding.embedding = new_embedding\n",
527-
" return output\n",
528-
" \n",
529-
" def _extra_repr(self) -> str:\n",
530-
" repr_str = f\"old_dim={self.old_dim}, new_dim={self.new_dim}, normalize={self.normalize}\"\n",
531-
" return repr_str"
527+
" return output.data"
532528
]
533529
},
534530
{

0 commit comments

Comments
 (0)