diff --git a/examples/Talk_to_documents_with_embeddings.ipynb b/examples/Talk_to_documents_with_embeddings.ipynb index c4e1288c5..858b3f119 100644 --- a/examples/Talk_to_documents_with_embeddings.ipynb +++ b/examples/Talk_to_documents_with_embeddings.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "cellView": "form", "id": "tuOe1ymfHZPu" @@ -95,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "id": "YD6urJjWGVDf" }, @@ -143,28 +143,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "id": "J76TNa3QDwCc" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "embeddings=[ContentEmbedding(\n", - " values=[\n", - " -0.019380787,\n", - " 0.015025399,\n", - " 0.006310311,\n", - " -0.057478663,\n", - " 0.011998727,\n", - " <... 3067 more items ...>,\n", - " ]\n", - ")] metadata=None\n" - ] - } - ], + "outputs": [], "source": [ "from google.genai import types\n", "\n", @@ -181,7 +164,7 @@ " model=EMBEDDING_MODEL_ID,\n", " contents=sample_text,\n", " config=types.EmbedContentConfig(\n", - " task_type=\"retrieval_document\",\n", + " task_type=\"RETRIEVAL_DOCUMENT\",\n", " title=title\n", " ))\n", "\n", @@ -201,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "id": "XvLRIbpq4vNN" }, @@ -231,73 +214,11 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "id": "GJKLIW9Z31Vf" }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
TitleText
0Operating the Climate Control SystemYour Googlecar has a climate control system th...
1TouchscreenYour Googlecar has a large touchscreen display...
2Shifting GearsYour Googlecar has an automatic transmission. ...
\n", - "
" - ], - "text/plain": [ - " Title \\\n", - "0 Operating the Climate Control System \n", - "1 Touchscreen \n", - "2 Shifting Gears \n", - "\n", - " Text \n", - "0 Your Googlecar has a climate control system th... \n", - "1 Your Googlecar has a large touchscreen display... \n", - "2 Your Googlecar has an automatic transmission. ... " - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import pandas as pd\n", "\n", @@ -317,82 +238,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "id": "4SOhy0lNBhfN" }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
TitleTextEmbeddings
0Operating the Climate Control SystemYour Googlecar has a climate control system th...[0.02483931, -0.003871694, 0.013593362, -0.031...
1TouchscreenYour Googlecar has a large touchscreen display...[0.008149438, -0.0013574613, -0.0029458047, -0...
2Shifting GearsYour Googlecar has an automatic transmission. ...[0.009464946, 0.022619268, -0.0036155856, -0.0...
\n", - "
" - ], - "text/plain": [ - " Title \\\n", - "0 Operating the Climate Control System \n", - "1 Touchscreen \n", - "2 Shifting Gears \n", - "\n", - " Text \\\n", - "0 Your Googlecar has a climate control system th... \n", - "1 Your Googlecar has a large touchscreen display... \n", - "2 Your Googlecar has an automatic transmission. ... \n", - "\n", - " Embeddings \n", - "0 [0.02483931, -0.003871694, 0.013593362, -0.031... \n", - "1 [0.008149438, -0.0013574613, -0.0029458047, -0... \n", - "2 [0.009464946, 0.022619268, -0.0036155856, -0.0... " - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Get the embeddings of each text and add to an embeddings column in the dataframe\n", "def embed_fn(title, text):\n", @@ -400,7 +250,7 @@ " model=EMBEDDING_MODEL_ID,\n", " contents=text,\n", " config=types.EmbedContentConfig(\n", - " task_type=\"retrieval_document\",\n", + " task_type=\"RETRIEVAL_DOCUMENT\",\n", " title=title\n", " )\n", " )\n", @@ -425,7 +275,7 @@ "\n", "The values of the dot product can range between -1 and 1, inclusive. If the dot product between two vectors is 1, then the vectors are in the same direction. If the dot product value is 0, then these vectors are orthogonal, or unrelated, to each other. Lastly, if the dot product is -1, then the vectors point in the opposite direction and are not similar to each other.\n", "\n", - "Note, with the new embeddings model (`gemini-embedding-001`), specify the task type as `QUERY` for user query and `DOCUMENT` when embedding a document text.\n", + "Note, with the new embeddings model (`gemini-embedding-001`), specify the task type as `RETRIEVAL_QUERY` for user queries and `RETRIEVAL_DOCUMENT` when embedding document text.\n", "\n", "Task Type | Description\n", "--- | ---\n", @@ -435,7 +285,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "id": "80w2VQQ9JWcU" }, @@ -463,7 +313,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "id": "am36P3J9M6Zv" }, @@ -480,7 +330,7 @@ " model=EMBEDDING_MODEL_ID,\n", " contents=query,\n", " config=types.EmbedContentConfig(\n", - " task_type=\"retrieval_document\",\n", + " task_type=\"RETRIEVAL_QUERY\",\n", " )\n", " )\n", "\n", @@ -503,25 +353,11 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": { "id": "1I5lAqdH9zWL" }, - "outputs": [ - { - "data": { - "text/markdown": [ - "Your Googlecar has an automatic transmission. To shift gears, simply move the shift lever to the desired position. Park: This position is used when you are parked. The wheels are locked and the car cannot move. Reverse: This position is used to back up. Neutral: This position is used when you are stopped at a light or in traffic. The car is not in gear and will not move unless you press the gas pedal. Drive: This position is used to drive forward. Low: This position is used for driving in snow or other slippery conditions." - ], - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "from IPython.display import Markdown\n", "\n", @@ -542,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "id": "pqf-OsT3auTm" }, @@ -579,38 +415,11 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "id": "mlpDRG3cVvQE" }, - "outputs": [ - { - "data": { - "text/markdown": [ - "\n", - "You are a helpful and informative bot that answers questions using text\n", - "from the reference passage included below. Be sure to respond in a\n", - "complete sentence, being comprehensive, including all relevant\n", - "background information.\n", - "\n", - "However, you are talking to a non-technical audience, so be sure to\n", - "break down complicated concepts and strike a friendly and conversational\n", - "tone. If the passage is irrelevant to the answer, you may ignore it.\n", - "\n", - "QUESTION: 'How to shift gears in the Google car?'\n", - "PASSAGE: 'Your Googlecar has an automatic transmission. To shift gears, simply move the shift lever to the desired position. Park: This position is used when you are parked. The wheels are locked and the car cannot move. Reverse: This position is used to back up. Neutral: This position is used when you are stopped at a light or in traffic. The car is not in gear and will not move unless you press the gas pedal. Drive: This position is used to drive forward. Low: This position is used for driving in snow or other slippery conditions.'\n", - "\n", - "ANSWER:\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "prompt = make_prompt(query, passage)\n", "Markdown(prompt)" @@ -627,7 +436,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": { "id": "m30avD9cfQQ-" }, @@ -642,25 +451,11 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": { "id": "COBhn6J9S_xI" }, - "outputs": [ - { - "data": { - "text/markdown": [ - "Good news! Your Googlecar actually has an automatic transmission, which means shifting gears is super simple – you just move the shift lever to the spot you need! For instance, if you're parked and want the car to stay put, you'll put it in 'Park' because that locks the wheels. When you need to back up, you'll choose 'Reverse.' If you're stopped at a traffic light or in slow traffic and don't want the car to roll, 'Neutral' is the spot; the car won't move unless you press the gas pedal. To drive forward, you'll simply select 'Drive.' And for those times when you're driving in snow or really slippery conditions, there's a 'Low' position to help you out." - ], - "text/plain": [ - "" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "Markdown(answer.text)" ] @@ -695,6 +490,18 @@ "kernelspec": { "display_name": "Python 3", "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" } }, "nbformat": 4,