Building Advanced RAG Systems
guidesnotebookscohere-developer-experienceadvanced_rag
Export
Imports
[4]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 222.4/222.4 kB 4.7 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 139.2/139.2 kB 8.4 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 44.4 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.4/76.4 kB 4.7 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.9/77.9 kB 5.5 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.5/12.5 MB 81.8 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 82.7/82.7 kB 5.0 MB/s eta 0:00:00 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 3.5 MB/s eta 0:00:00
Utils
[2]
[3]
Define Tools for the RAG Agent: a web search engine and a python interpreter
A web search engine, accessible through an API
[5]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 14.0 MB/s eta 0:00:00
[6]
[7]
A Python interpreter, which can be used by the RAG Agent to write code and/or to access a spreadsheet
[8]
[9]
[11]
Utils
[12]
[ ]
Cohere model to power Agentic RAG
[14]
Let's look at a complex user query
[15]
Get the model plan
[16]
I will first inspect the dataset to understand its structure and identify the relevant columns for the query. Then, I will write and execute Python code to filter the data for the top 3 most streamed songs on Spotify in 2023 and extract the age and citizenship of the artists.
Let the model make as many steps of (parallel) tool calling, retrieval, self-reflection, before answering
[17]
== STEP 1 The plan is: I will first inspect the dataset to understand its structure and identify the relevant columns for the query. Then, I will write and execute Python code to filter the data for the top 3 most streamed songs on Spotify in 2023 and extract the age and citizenship of the artists. The model suggests making a single tool call: python_interpreter with this code: import pandas as pd # Load the dataset df = pd.read_csv("./spotify_dataset.csv") # Check the structure of the dataset print(df.info()) print(df.head()) tool_results: [{'console_output': "<class 'pandas.core.frame.DataFrame'>\nRangeIndex: 952 entries, 0 to 951\nData columns (total 25 columns):\n # Column Non-Null Count Dtype \n--- ------ -------------- ----- \n 0 track_name 952 non-null object \n 1 artist(s)_name 952 non-null object \n 2 artist_count 952 non-null int64 \n 3 released_year 952 non-null int64 \n 4 released_month 952 non-null int64 \n 5 released_day 952 non-null int64 \n 6 in_spotify_playlists 952 non-null int64 \n 7 in_spotify_charts 952 non-null int64 \n 8 streams 952 non-null float64\n 9 in_apple_playlists 952 non-null int64 \n 10 in_apple_charts 952 non-null int64 \n 11 in_deezer_playlists 952 non-null object \n 12 in_deezer_charts 952 non-null int64 \n 13 in_shazam_charts 902 non-null object \n 14 bpm 952 non-null int64 \n 15 key 857 non-null object \n 16 mode 952 non-null object \n 17 danceability 952 non-null int64 \n 18 valence 952 non-null int64 \n 19 energy 952 non-null int64 \n 20 acousticness 952 non-null int64 \n 21 instrumentalness 952 non-null int64 \n 22 liveness 952 non-null int64 \n 23 speechiness 952 non-null int64 \n 24 release_date 952 non-null object \ndtypes: float64(1), int64(17), object(7)\nmemory usage: 186.1+ KB\nNone\n track_name artist(s)_name artist_count \\\n0 Seven (feat. Latto) (Explicit Ver.) Latto, Jung Kook 2 \n1 LALA Myke Towers 1 \n2 vampire Olivia Rodrigo 1 \n3 Cruel Summer Taylor Swift 1 \n4 WHERE SHE GOES Bad Bunny 1 \n\n released_year released_month released_day in_spotify_playlists \\\n0 2023 7 14 553 \n1 2023 3 23 1474 \n2 2023 6 30 1397 \n3 2019 8 23 7858 \n4 2023 5 18 3133 \n\n in_spotify_charts streams in_apple_playlists ... key mode \\\n0 147 141381703.0 43 ... B Major \n1 48 133716286.0 48 ... C# Major \n2 113 140003974.0 94 ... F Major \n3 100 800840817.0 116 ... A Major \n4 50 303236322.0 84 ... A Minor \n\n danceability valence energy acousticness instrumentalness liveness \\\n0 80 89 83 31 0 8 \n1 71 61 74 7 0 10 \n2 51 32 53 17 0 31 \n3 55 58 72 11 0 11 \n4 65 23 80 14 63 11 \n\n speechiness release_date \n0 4 2023-07-14 \n1 4 2023-03-23 \n2 6 2023-06-30 \n3 15 2019-08-23 \n4 6 2023-05-18 \n\n[5 rows x 25 columns]\n", 'executed_code': 'import pandas as pd\n\n# Load the dataset\ndf = pd.read_csv("./spotify_dataset.csv")\n\n# Check the structure of the dataset\nprint(df.info())\nprint(df.head())'}] == STEP 2 The plan is: The dataset contains the following relevant columns: - track_name - artist(s)_name - released_year - streams I will now write and execute Python code to filter the data for the top 3 most streamed songs on Spotify in 2023 and extract the age and citizenship of the artists. I will assume that the age and citizenship information is not available in the dataset and will use web search to find this information. The model suggests making a single tool call: python_interpreter with this code: import pandas as pd # Load the dataset df = pd.read_csv("./spotify_dataset.csv") # Filter for songs released in 2023 df_2023 = df[df["released_year"] == 2023] # Sort the data by streams in descending order and select the top 3 top_3_songs = df_2023.sort_values(by="streams", ascending=False).head(3) # Print the track names and artists print("Top 3 most streamed songs on Spotify in 2023:") for index, row in top_3_songs.iterrows(): print(f"Track: {row['track_name']}") print(f"Artist(s): {row['artist(s)_name']}") print("\n") tool_results: [{'console_output': 'Top 3 most streamed songs on Spotify in 2023:\nTrack: Flowers\nArtist(s): Miley Cyrus\n\n\nTrack: Ella Baila Sola\nArtist(s): Eslabon Armado, Peso Pluma\n\n\nTrack: Shakira: Bzrp Music Sessions, Vol. 53\nArtist(s): Shakira, Bizarrap\n\n\n', 'executed_code': 'import pandas as pd\n\n# Load the dataset\ndf = pd.read_csv("./spotify_dataset.csv")\n\n# Filter for songs released in 2023\ndf_2023 = df[df["released_year"] == 2023]\n\n# Sort the data by streams in descending order and select the top 3\ntop_3_songs = df_2023.sort_values(by="streams", ascending=False).head(3)\n\n# Print the track names and artists\nprint("Top 3 most streamed songs on Spotify in 2023:")\nfor index, row in top_3_songs.iterrows():\n print(f"Track: {row[\'track_name\']}")\n print(f"Artist(s): {row[\'artist(s)_name\']}")\n print("\\n")'}] == STEP 3 The plan is: The top 3 most streamed songs on Spotify in 2023 are: 1. Flowers by Miley Cyrus 2. Ella Baila Sola by Eslabon Armado and Peso Pluma 3. Shakira: Bzrp Music Sessions, Vol. 53 by Shakira and Bizarrap I will now use web search to find the age and citizenship of these artists. The model suggests making Parallel Queries: == Parallel Tool Call #1 web_search {'query': 'Miley Cyrus age and citizenship'} == Parallel Tool Call #2 web_search {'query': 'Eslabon Armado age and citizenship'} == Parallel Tool Call #3 web_search {'query': 'Peso Pluma age and citizenship'} == Parallel Tool Call #4 web_search {'query': 'Shakira age and citizenship'} == Parallel Tool Call #5 web_search {'query': 'Bizarrap age and citizenship'} tool_results: [{'title': 'Miley Cyrus Bio, Age, Parents, Siblings, Boyfriend ... | FamousIntel', 'url': 'https://famousintel.com/miley-cyrus/', 'content': "Miley Cyrus Age and Birthday. Cyrus is 29 years old as of 2021. She was born Miley Ray Cyrus on 23 November 1992 in Franklin, Tennessee, United States. She celebrates her birthday on 23 November every year. Miley Cyrus Real Name. Why did Miley change her name? Her parents' hopes for her future were reflected in her birth name, Destiny Hope.", 'score': 0.9721516, 'raw_content': None}, {'title': 'Miley Cyrus - Biography | IMDb', 'url': 'https://www.imdb.com/name/nm1415323/bio/', 'content': "Miley Cyrus. Actress: Hannah Montana. Miley Ray Cyrus was born Destiny Hope Cyrus on November 23, 1992 in Franklin, Tennessee and raised in Thompson's Station, Tennessee to Tish Cyrus & Billy Ray Cyrus. She has five siblings - two half-brothers, a half-sister, and a younger brother and sister. Her parents named her because they hoped she would achieve greatness. Her childhood nickname, Smiley ...", 'score': 0.32402146, 'raw_content': None}, {'title': 'Miley Cyrus | Biography, TV Shows, Songs, & Facts | Britannica', 'url': 'https://www.britannica.com/biography/Miley-Cyrus', 'content': 'Meanwhile, Cyrus continued to record under her own name for the EP The Time of Our Lives (2009), which featured the hit “Party in the U.S.A.,” and the full-length album Can’t Be Tamed (2010). She then veered away from the mainstream with Miley Cyrus & Her Dead Petz (2015), a collection of loosely psychedelic songs recorded in large part with the rock band the Flaming Lips and made available for free on the Internet. In 2005 Cyrus auditioned for the lead role in Hannah Montana, a Disney Channel series about a girl who leads a double life as a normal middle-school student and, with the help of a blonde wig, as a glamorous pop singer. Cyrus was a coach on the television singing competition The Voice in 2016–17, and she costarred with Woody Allen and Elaine May in Allen’s six-episode TV series Crisis in Six Scenes (2016). The show debuted the following year (featuring Billy Ray as her TV dad) and became an immediate sensation, scoring record ratings for cable television and turning the 13-year-old into a bona fide star.', 'score': 0.27845296, 'raw_content': None}] tool_results: [{'title': 'Pedro Tova - Age, Eslabon Armado, Song & Brother - Biography', 'url': 'https://biographyhost.com/p/pedro-tovar.html', 'content': 'Age 22 Years, 1 Months ; ... Eslabon Armado, a California-based musical band, meaning "linked chain," was initially formed in 2017. Alongside the lead vocalist Pedro Tovar, the band\'s other members include Bryan Tovar, also his brother, responsible for bass and bajoloche, and Gabriel Hidalgo, responsible for harmony and background vocals. ...', 'score': 0.9812389, 'raw_content': None}, {'title': 'Eslabon Armado - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Eslabon_Armado', 'content': 'Eslabon Armado is an American regional Mexican group from Patterson, California formed in 2017. The group consists of Pedro Tovar (lead vocals), Brian Tovar (bass), Damian Pacheco ( twelve-string guitar ), and Ulises González (acoustic guitar), with González joining in 2021 after Hidalgo left the group in 2020, with the Tovar brothers being ...', 'score': 0.9803562, 'raw_content': None}, {'title': "Eslabón Armado Helped Make Musica Mexicana History. What's Next?", 'url': 'https://www.rollingstone.com/music/music-features/eslabon-armado-new-song-la-fresa-interview-exclusive-1234838542/', 'content': 'The 21-year-old singer is the voice behind Eslabón Armado, one of the biggest bands in the booming música Mexicana scene. This year, Eslabón Armado released Desvelado, a follow up to their 2022 ...', 'score': 0.98020524, 'raw_content': None}] tool_results: [{'title': "Peso Pluma's height, age, real name, parents, nationality and net worth", 'url': 'https://www.msn.com/en-za/news/other/peso-plumas-height-age-real-name-parents-nationality-and-net-worth/ar-AA1klboL', 'content': 'Peso Pluma, whose real name is Hassan Emilio Kabande Laija, is 24 years of age as of 2023. He was born in Zapopan, just outside of Guadalajara in Mexico, on 15 June 1999, but moved to San Antonio ...', 'score': 0.9932288, 'raw_content': None}, {'title': 'Who is Peso Pluma? His real name, age, height, nationality, and more', 'url': 'https://wegotthiscovered.com/celebrities/who-is-peso-pluma-his-real-name-age-height-nationality-and-more/', 'content': 'Peso Pluma was born on June 15, 1999, so he is currently 24 years old. At such a young age, it is extremely impressive that he has gained mainstream success as an international artist.', 'score': 0.9856077, 'raw_content': None}, {'title': "Peso Pluma's height, age, real name, parents, nationality", 'url': 'https://www.legit.ng/ask-legit/biographies/1560619-peso-plumas-height-age-real-parents-nationality/', 'content': "Die Antwoord's Yolandi Visser: age, husband, children, net worth. Peso Pluma's height is 5 feet 7 inches or 170 centimetres. He is a Mexican-born singer and songwriter best known for his hit tracks, including Ella Baila Sola, LADY GAGA and El Belicon. He is the founder of Double P Records.", 'score': 0.92656994, 'raw_content': None}] tool_results: [{'title': "Shakira's Age, Height & Nationality: Background & Stats - Heavy.com", 'url': 'https://heavy.com/entertainment/2020/02/shakira-age-height-nationality-how-old/', 'content': 'Shakira was born on February 2, 1977, making her 43 years old today. The Latin pop star stands at 5-foot-2-inches tall and has been dating Gerard Piqué since 2011.', 'score': 0.684264, 'raw_content': None}, {'title': "Discover Shakira's Nationality: Colombian Citizenship And Lebanese ...", 'url': 'https://astroinsightz.com/what-is-the-nationality-of-shakira/', 'content': 'Born Shakira Isabel Mebarak Ripoll on February 2, 1977, in Barranquilla, Colombia, Shakira showed an early passion for music. Growing up in a middle-class family, she was exposed to a diverse array of musical genres, from traditional Colombian folk music to rock and roll. At the tender age of eight, Shakira wrote her first song, showcasing her ...', 'score': 0.52010024, 'raw_content': None}, {'title': 'Shakira | Biography, Songs, Full Name, & Facts | Britannica', 'url': 'https://www.britannica.com/biography/Shakira', 'content': 'At that year’s Latin Grammy Awards, she captured song-of-the-year and record-of-the-year awards for the single “La tortura,” and Fijación oral, vol. 1 was named album of the year as well as best female pop vocal album; it also won a Grammy Award for best Latin rock/alternative album. Her later albums included Shakira (2014), which featured a duet with Rihanna, and El Dorado (2017), winner of the Grammy Award for best Latin pop album and the Latin Grammy for best contemporary pop vocal album. In addition, El Dorado featured the single “La bicicleta,” a duet with Carlos Vives that won Latin Grammys for best record of the year and best song of the year. Shakira continued her crossover success in 2005 with the release of the Spanish-language Fijación oral, vol. 1 in June and the English-language Oral Fixation, Vol. 2 in November. Shakira (born February 2, 1977, Barranquilla, Colombia) Colombian musician who achieved success in both Spanish- and English-speaking markets and by the early 2000s was one of the most successful Latin American recording artists.\n', 'score': 0.2849738, 'raw_content': None}] tool_results: [{'title': 'Bizarrap Bio, Age, Height, Producer, Youtuber, Net Worth', 'url': 'https://marriedbiography.com/bizarrap-biography/', 'content': 'Bizarrap: Bio, Age, Parents, Education, Ethnicity Gonzalo Julián Conde , better known as Bizarrap, was born on August 29, 1998 , in Ramos Meja, Argentina. As of 2023, he is 25 years old and a naturalized Argentine citizen who professes Catholicism.', 'score': 0.9979888, 'raw_content': None}, {'title': 'Bizarrap - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Bizarrap', 'content': 'Bizarrap. Gonzalo Julián Conde (born 29 August 1998), known professionally as Bizarrap, is an Argentine DJ and producer. He specializes in EDM, Latin trap and Latin hip hop. He is known for his Bzrp Music Sessions, a series of independent tracks which he records with a wide variety of artists. [1] He was nominated for a Latin Grammy Award for ...', 'score': 0.9613165, 'raw_content': None}, {'title': 'Everything we know about record producer Bizarrap - HOLA.com', 'url': 'https://www.hola.com/us/celebrities/20230117341614/who-is-bizarrap/', 'content': 'Meet Bizarrap: The composer and record producer topping the charts alongside Shakira The 24-year-old artist began his musical career in 2017 in his native hometown. Shirley Gomez .', 'score': 0.8451773, 'raw_content': None}] The final answer is: Here is the age and citizenship of the artists who had the top 3 most streamed songs on Spotify in 2023: 1. Miley Cyrus: - Age: 30 (born 23 November 1992) - Citizenship: American 2. Eslabon Armado: - Age: 21-22 - Citizenship: American 3. Peso Pluma: - Age: 24 (born 15 June 1999) - Citizenship: Mexican 4. Shakira: - Age: 45 (born 2 February 1977) - Citizenship: Colombian 5. Bizarrap: - Age: 25 (born 29 August 1998) - Citizenship: Argentine
[ ]