Notebooks
d
deepset
Gemma Chat Rag

Gemma Chat Rag

agentic-aiagenticagentsgenaiAIhaystack-cookbookgenai-usecaseshaystack-ainotebooksPythonragai-tools

Build with Gemma and Haystack

      

We will see what we can build with the new Google Gemma open models and the Haystack LLM framework.

Installation

[ ]

Authorization

[2]
Your Hugging Face token··········

Chat with Gemma (travel assistant) 🛩

For simplicity, we call the model using the free Hugging Face Inference API with the HuggingFaceAPIChatGenerator.

(We might also load it in Colab using the HuggingFaceLocalChatGenerator in a quantized version).

[4]
[7]
Enter your message or Q to exit
🧑  can you help me planning a trip?
🤖 **Sure, I'd be happy to help you with that. Please provide me with the following information:**

* **What you want to do:** What are your interests and what do you want to see and experience on your trip?
* **Your budget:** How much you are willing to spend on your trip.
* **Your preferred travel dates:** When you would like to travel.
* **Your preferred travel style:** Whether you prefer solo travel, group travel, or a guided tour.
* **Your preferred location:** Where you would like to go.
* **Any specific interests or activities you want to include:** For example, hiking, sightseeing, or exploring the local culture.

Once I have this information, I can help you plan a trip that is tailored to your specific interests and budget. I can also provide you with recommendations for accommodations, transportation, and activities.
Enter your message or Q to exit
🧑 I'm interested in Italy. what can I visit?
🤖 Sure, here are some ideas for places you can visit in Italy based on your interests:

**For history and culture:**
* Rome: The Eternal City, with its ancient ruins, museums, and vibrant culture.
* Florence: The "Cradle of the Renaissance," with its stunning architecture, art, and history.
* Pompeii: The ancient Roman city preserved by the eruption of Mount Vesuvius in 79 AD.
* Cinque Terre: A series of five picturesque villages along the Italian Riviera.
* Amalfi Coast: A scenic drive along the coast of the Amalfi Coast, known for its stunning views and charming towns.

**For nature and outdoor recreation:**
* Mount Vesuvius: An active volcano with a fascinating history.
* The Dolomites: A mountain range with breathtaking scenery and a variety of hiking trails.
* The Italian Alps: A mountain range with towering peaks and glaciers.
* Lake Como: A beautiful lake surrounded by mountains and villages.
* The Amalfi Coast: A scenic drive along the coast of the Amalfi Coast, known for its stunning views and charming towns.

**For food and wine:**
* Tuscany: A region known for its delicious food, wine, and olive oil.
* Piedmont: A region known for its truffles, chocolates, and red wine.
* Apulia: A region known for its olive oil, cheese, and seafood.
* Sicily: A region known for its unique cuisine and vibrant culture.
Enter your message or Q to exit
🧑 nice. can you provide me with a list of things I should take with me to Italy for the trip?
🤖 Sure, here are a few things you should pack for your trip to Italy:

* Comfortable walking shoes
* Light clothing
* Sunscreen
* Hat
* Sunglasses
* Camera
* Water bottle
* A small amount of cash
* Credit card
* A few basic Italian phrases
* A map of Italy
* A guidebook to Italy
Enter your message or Q to exit
🧑 Q

RAG with Gemma (about Rock music) 🎸

[ ]

Load data from Wikipedia

[9]
[17]
[10]

Indexing Pipeline

[11]
[12]
[13]
<haystack.pipeline.Pipeline at 0x7f7a11777490>
[19]
{'writer': {'documents_written': 1584}}
[20]
{'title': 'Audioslave',
, 'url': 'https://en.wikipedia.org/wiki/Audioslave',
, 'source_id': 'e3deff3d39ef107e8b0d69415ea61644b73175086cfbeee03d5f5d6946619fcf'}

RAG Pipeline

[29]

Here, we use the HuggingFaceAPIGenerator since it is not a chat setting and we don't envision multi-turn conversations but just RAG.

[30]
[31]
<haystack.pipeline.Pipeline at 0x7f7a10ee5180>

Let's ask some questions!

[36]
[43]
Ranking by BM25...:   0%|          | 0/1565 [00:00<?, ? docs/s]
[83]
[90]
What was the original name of Sum 41?
Ranking by BM25...:   0%|          | 0/1565 [00:00<?, ? docs/s]

This is a simple demo. We can improve the RAG Pipeline using better retrieval techniques: Embedding Retrieval, Hybrid Retrieval...

(Notebook by Stefano Fiorucci)