Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 99 additions & 181 deletions notebooks/Vanilla_RAG.ipynb

Large diffs are not rendered by default.

97 changes: 53 additions & 44 deletions notebooks/agents/agentic-RAG/agentic_multi_stage_rag_native.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -52,14 +52,14 @@
},
{
"cell_type": "code",
"execution_count": 161,
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cohere version: 5.5.1\n"
"cohere version: 5.14.0\n"
]
}
],
Expand All @@ -77,12 +77,12 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"COHERE_API_KEY = os.environ.get(\"CO_API_KEY\")\n",
"COHERE_MODEL = 'command-r-plus'\n",
"COHERE_MODEL = 'command-a-03-2025'\n",
"co = cohere.Client(api_key=COHERE_API_KEY)"
]
},
Expand All @@ -97,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": 279,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -162,7 +162,7 @@
},
{
"cell_type": "code",
"execution_count": 329,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -198,28 +198,28 @@
" <td>Bicycle law</td>\n",
" <td>\\n Traffic Infractions and fees - For a...</td>\n",
" <td>Title: Bicycle law\\nBody: \\n Traffic In...</td>\n",
" <td>[-0.024673462, -0.034729004, 0.0418396, 0.0121...</td>\n",
" <td>[-0.025314331, -0.034729004, 0.041778564, 0.01...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Bicycle helmet requirement</td>\n",
" <td>Currently, there is no state law requiring hel...</td>\n",
" <td>Title: Bicycle helmet requirement\\nBody: Curre...</td>\n",
" <td>[-0.019180298, -0.037384033, 0.0027389526, -0....</td>\n",
" <td>[-0.019699097, -0.03793335, 0.0017843246, -0.0...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Section 21a</td>\n",
" <td>helmet rules by location: These are city and c...</td>\n",
" <td>Title: Section 21a\\nBody: helmet rules by loca...</td>\n",
" <td>[0.031097412, 0.0007619858, -0.023010254, -0.0...</td>\n",
" <td>[0.030639648, 0.0008893013, -0.0231781, -0.051...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Section 3b</td>\n",
" <td>Traffic infraction - A person operating a bicy...</td>\n",
" <td>Title: Section 3b\\nBody: Traffic infraction - ...</td>\n",
" <td>[0.015602112, -0.016143799, 0.032958984, 0.000...</td>\n",
" <td>[0.012466431, -0.0129852295, 0.030075073, 0.00...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
Expand All @@ -245,13 +245,13 @@
"3 Title: Section 3b\\nBody: Traffic infraction - ... \n",
"\n",
" embeddings \n",
"0 [-0.024673462, -0.034729004, 0.0418396, 0.0121... \n",
"1 [-0.019180298, -0.037384033, 0.0027389526, -0.... \n",
"2 [0.031097412, 0.0007619858, -0.023010254, -0.0... \n",
"3 [0.015602112, -0.016143799, 0.032958984, 0.000... "
"0 [-0.025314331, -0.034729004, 0.041778564, 0.01... \n",
"1 [-0.019699097, -0.03793335, 0.0017843246, -0.0... \n",
"2 [0.030639648, 0.0008893013, -0.0231781, -0.051... \n",
"3 [0.012466431, -0.0129852295, 0.030075073, 0.00... "
]
},
"execution_count": 329,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -271,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 220,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -323,7 +323,7 @@
},
{
"cell_type": "code",
"execution_count": 237,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -351,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count": 325,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -443,7 +443,7 @@
},
{
"cell_type": "code",
"execution_count": 179,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -459,7 +459,7 @@
},
{
"cell_type": "code",
"execution_count": 180,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -468,7 +468,7 @@
"text": [
"top_matched_document 1 Title: Bicycle helmet requirement\\nBody: Curre...\n",
"Name: combined, dtype: object\n",
"There is currently no state law requiring the use of helmets when riding a bicycle. However, some cities and counties do require helmet use.\n"
"Currently, there is no state law requiring helmet use. However, some cities and counties do require helmet use with bicycles. For specific information along with location for bicycle helmet law please reference to section 21a.\n"
]
}
],
Expand All @@ -486,7 +486,7 @@
},
{
"cell_type": "code",
"execution_count": 183,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -495,15 +495,15 @@
"text": [
"\n",
"running 0th step.\n",
"I will search for 'state level law for wearing helmets' in the documents provided and write an answer based on what I find.\n",
"I will search for 'state level law for wearing helmets'.\n",
"\n",
"running 1th step.\n",
"= running tool retrieve_documents, with parameters: \n",
"{'query': 'state level law for wearing helmets'}\n",
"== tool results:\n",
"{'top_matched_document': 1 Title: Bicycle helmet requirement\\nBody: Curre...\n",
"Name: combined, dtype: object}\n",
"There is currently no state law requiring helmet use. However, some cities and counties do require helmet use with bicycles.\n"
"There is no state law requiring helmet use. However, some cities and counties do require helmet use with bicycles.\n"
]
}
],
Expand Down Expand Up @@ -532,7 +532,7 @@
},
{
"cell_type": "code",
"execution_count": 188,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -548,7 +548,7 @@
},
{
"cell_type": "code",
"execution_count": 189,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -557,7 +557,7 @@
"text": [
"top_matched_document 1 Title: Bicycle helmet requirement\\nBody: Curre...\n",
"Name: combined, dtype: object\n",
"In the state of Washington, there is no law requiring you to wear a helmet when riding a bike. However, some cities and counties do require helmet use, so it is worth checking your local laws.\n"
"There is no state law requiring helmet use. However, some cities and counties do require helmet use with bicycles. For specific information along with location for bicycle helmet law please reference to section 21a.\n"
]
}
],
Expand All @@ -577,7 +577,7 @@
},
{
"cell_type": "code",
"execution_count": 190,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -586,15 +586,15 @@
"text": [
"\n",
"running 0th step.\n",
"I will search for 'helmet with a bike' and then write an answer.\n",
"I will search for 'do I need to wear a helmet with a bike in orting?'\n",
"\n",
"running 1th step.\n",
"= running tool retrieve_documents, with parameters: \n",
"{'query': 'helmet with a bike'}\n",
"{'query': 'do I need to wear a helmet with a bike in orting'}\n",
"== tool results:\n",
"{'top_matched_document': 1 Title: Bicycle helmet requirement\\nBody: Curre...\n",
"Name: combined, dtype: object}\n",
"There is no state law requiring helmet use, however, some cities and counties do require helmet use with bicycles. I cannot find any information about Orting specifically, but you should check with your local authority.\n"
"There is no state law requiring helmet use. However, some cities and counties do require helmet use with bicycles. I'm afraid I don't have any information on whether Orting is one of those cities.\n"
]
}
],
Expand All @@ -620,7 +620,7 @@
},
{
"cell_type": "code",
"execution_count": 247,
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -688,7 +688,7 @@
},
{
"cell_type": "code",
"execution_count": 249,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -697,25 +697,27 @@
"text": [
"\n",
"running 0th step.\n",
"I will search for 'Orting' and 'bike helmet' to find the relevant information.\n",
"I will use the 'retrieve_documents' tool to find out if the user needs to wear a helmet with a bike in Orting.\n",
"\n",
"running 1th step.\n",
"= running tool retrieve_documents, with parameters: \n",
"{'query': 'Orting bike helmet'}\n",
"{'query': 'do I need to wear a helmet with a bike in orting'}\n",
"== tool results:\n",
"{'other_references_to_query': 'Section 21a, Section 3b',\n",
" 'top_matched_document': 0 Title: Bicycle law\\nBody: \\n Riding on ...\n",
"{'other_references_to_query': 'The reference document mentions another '\n",
" 'document: **section 21a**.',\n",
" 'top_matched_document': 1 Title: Bicycle helmet requirement\\nBody: Curre...\n",
"Name: combined, dtype: object}\n",
"I have found that there is no state law requiring helmet use, but some cities and counties do require helmets. I will now search for 'Section 21a' to find out if Orting is one of these cities or counties.\n",
"I have found that there is no state law requiring helmet use. However, some cities and counties do require helmet use with bicycles. I will now use the 'retrieve_documents' tool to find out if Orting is one of the cities or counties that require helmet use with bicycles.\n",
"\n",
"running 2th step.\n",
"= running tool retrieve_documents, with parameters: \n",
"{'query': 'Section 21a'}\n",
"{'query': 'section 21a'}\n",
"== tool results:\n",
"{'other_references_to_query': '- Section 3b',\n",
"{'other_references_to_query': 'The reference document mentions **Section 3b of '\n",
" 'the law**.',\n",
" 'top_matched_document': 2 Title: Section 21a\\nBody: helmet rules by loca...\n",
"Name: combined, dtype: object}\n",
"Yes, you do need to wear a helmet when riding a bike in Orting if you are under 17.\n"
"Yes, you need to wear a helmet with a bike in Orting if you are under 17.\n"
]
}
],
Expand All @@ -732,13 +734,20 @@
"\n",
"output = cohere_agent(question2, preamble2, tools, verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
"name": "base"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -750,7 +759,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Loading