Skip to content

Commit

Permalink
execute component notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
lfunderburk committed Nov 17, 2023
1 parent 7e05015 commit 08e991f
Showing 1 changed file with 97 additions and 19 deletions.
116 changes: 97 additions & 19 deletions ch3/jupyter-notebooks/components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Calculating embeddings: 100%|██████████| 1/1 [00:01<00:00, 1.21s/it]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.001609589671716094, 0.005959704983979464]\n",
"[0.017629027366638184, -0.022774461656808853]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"from haystack.preview import Document\n",
"from haystack.preview.components.embedders import OpenAIDocumentEmbedder\n",
Expand Down Expand Up @@ -81,9 +104,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'documents': [Document(id='2e3218009b01cfc57f865bbf81fa70de81b5ebae02c4cc7092e46ffde03f3c49', content='The quick brown fox jumps over the lazy dog.', dataframe=None, blob=None, meta={}, score=None),\n",
" Document(id='63a06e3e867cb70e52a99c00b2de17fe531431c98e7d851268be01d341ea9f20', content='To be or not to be, that is the question.', dataframe=None, blob=None, meta={}, score=None)],\n",
" 'metadata': {'model': 'text-embedding-ada-002-v2',\n",
" 'usage': {'prompt_tokens': 22, 'total_tokens': 22}}}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result"
]
Expand All @@ -97,9 +134,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'model': 'text-embedding-ada-002-v2',\n",
" 'usage': {'prompt_tokens': 22, 'total_tokens': 22}}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result['metadata']"
]
Expand All @@ -120,7 +169,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -133,19 +182,25 @@
"text_to_embed = \"I love pizza!\"\n",
"\n",
"# Embed the text and print the result\n",
"result_text= text_embedder.run(text_to_embed)\n",
"\n",
"# Output will include the embedding vector and metadata\n",
"# {'embedding': [0.017020374536514282, -0.023255806416273117, ...],\n",
"# 'metadata': {'model': 'text-embedding-ada-002',\n",
"# 'usage': {'prompt_tokens': 4, 'total_tokens': 4}}}\n"
"result_text= text_embedder.run(text_to_embed)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['embedding', 'metadata'])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result_text.keys()"
]
Expand All @@ -159,18 +214,41 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[0.017020374536514282, -0.023255806416273117]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result_text['embedding'][0:2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'model': 'text-embedding-ada-002-v2',\n",
" 'usage': {'prompt_tokens': 4, 'total_tokens': 4}}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result_text['metadata']"
]
Expand Down

0 comments on commit 08e991f

Please sign in to comment.