diff --git a/examples/README.md b/examples/README.md index 62b22dea5..c55f22565 100644 --- a/examples/README.md +++ b/examples/README.md @@ -24,5 +24,9 @@ Folders * [Prompting examples](https://github.com/google-gemini/cookbook/tree/main/examples/prompting): A directory with examples of various prompting techniques. * [JSON Capabilities](https://github.com/google-gemini/cookbook/blob/main/quickstarts/Tuning.ipynb): A directory with guides containing different types of tasks you can do with JSON schemas. * [Automate Google Workspace tasks with the Gemini API](https://github.com/google-gemini/cookbook/tree/main/examples/Apps_script_and_Workspace_codelab): This codelabs shows you how to connect to the Gemini API using Apps Script, and uses the function calling, vision and text capabilities to automate Google Workspace tasks - summarizing a document, analyzing a chart, sending an email and generating some slides directly. All of this is done from a free text input. +* [ChromaDB](https://github.com/google-gemini/cookbook/tree/main/examples/chromadb): A directory with guides with to using Gemini with ChromaDB integrations. +* [LangChain](https://github.com/google-gemini/cookbook/tree/main/examples/langchain): A directory with guides with to using Gemini with LangChain integrations. +* [LlamaIndex](https://github.com/google-gemini/cookbook/tree/main/examples/llamaindex): A directory with guides with to using Gemini with LlamaIndex integrations. +* [QDrant](https://github.com/google-gemini/cookbook/tree/main/examples/qdrant): A directory with guides with to using Gemini with QDrant integrations. There are even more examples in the [quickstarts](https://github.com/google-gemini/cookbook/tree/main/quickstarts) folder and in the [Awesome Gemini page](../Awesome_gemini.md). diff --git a/examples/llamaindex/Evaluate_RAG_with_LlamaIndex.ipynb b/examples/llamaindex/Evaluate_RAG_with_LlamaIndex.ipynb new file mode 100644 index 000000000..908b2bf69 --- /dev/null +++ b/examples/llamaindex/Evaluate_RAG_with_LlamaIndex.ipynb @@ -0,0 +1,550 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "9NdTPlcnHXXe" + }, + "source": [ + "##### Copyright 2024 Google LLC." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "cellView": "form", + "id": "ryJhxbEjHh0o" + }, + "outputs": [], + "source": [ + "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "# you may not use this file except in compliance with the License.\n", + "# You may obtain a copy of the License at\n", + "#\n", + "# https://www.apache.org/licenses/LICENSE-2.0\n", + "#\n", + "# Unless required by applicable law or agreed to in writing, software\n", + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", + "# See the License for the specific language governing permissions and\n", + "# limitations under the License." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6xrMnk6fHLec" + }, + "source": [ + "# Gemini API: RAG Evaluation with LlamaIndex\n", + "This notebook demonstrates how to evaluate Retrieval-Augmented Generation (RAG) with LlamaIndex. You will learn how to:\n", + "\n", + "1. Read the data\n", + "2. Create a vector store with Gemini embeddings\n", + "3. Run a query engine with Gemini models\n", + "4. Evaluate results using LlamaIndex components" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FzoekDciM_pM" + }, + "source": [ + "
\n", + " Run in Google Colab\n", + " | \n", + "
\n", + " | Query | \n", + "Response | \n", + "Source | \n", + "Evaluation Result | \n", + "
---|---|---|---|---|
0 | \n", + "In what situations can impeachment occur? | \n", + "Impeachment can occur for treason, bribery, or other high crimes and misdemeanors. \n", + " | \n", + "The Senate shall choose their other Officers, and also a President\r\n", + "pro tempore, in the Absence of the Vice-President, or when he shall\r\n", + "exercise the Office of President of the United States.\r\n", + "\r\n", + "The Senate shall have the sole Power to try all Impeachments.\r\n", + "When sitting for that Purpose, they shall be on Oath or Affirmation.\r\n", + "When the President of the United States is tried, the Chief Justice\r\n", + "shall preside: And no Person shall be convicted without the Concurrence\r\n", + "of two thirds of the Members present.\r\n", + "\r\n", + "Judgment in cases of Impeachment shall not extend further than to removal\r\n", + "from Office, and disqualification to hold and enjoy any Office of honor,\r\n", + "Trust or Profit under the United States: but the Party convicted shall\r\n", + "nevertheless be liable and subject to Indictment, Trial, Judgment and\r\n", + "Punishment, according to Law.\r\n", + "\r\n", + "Section 4.\n", + "Section 4. The President, Vice President and all civil Officers of the\r\n", + "United States, shall be removed from Office on Impeachment for,\r\n", + "and Conviction of, Treason, Bribery, or other high Crimes and Misdemeanors.\r\n", + "\r\n", + "ARTICLE THREE\r\n", + "\r\n", + "Section 1. The judicial Power of the United States, shall be vested\r\n", + "in one supreme Court, and in such inferior Courts as the Congress may\r\n", + "from time to time ordain and establish. The Judges, both of the supreme\r\n", + "and inferior Courts, shall hold their Offices during good behavior,\r\n", + "and shall, at stated Times, receive for their Services, a Compensation,\r\n", + "which shall not be diminished during their Continuance in Office.\r\n", + "\r\n", + "Section 2. | \n", + "YES\n", + " | \n", + "
\n", + " | Query | \n", + "Response | \n", + "Source | \n", + "Evaluation Result | \n", + "
---|---|---|---|---|
0 | \n", + "From what age can someone become a Representative? | \n", + "Someone must be at least 25 years old to become a Representative. \n", + " | \n", + "No Person shall be a Representative who shall not have attained to the\r\n", + "Age of twenty five Years, and been seven Years a citizen of the United States,\r\n", + "and who shall not, when elected, be an Inhabitant of that State in which\r\n", + "he shall be chosen.\r\n", + "\r\n", + "Representatives and direct Taxes shall be apportioned among\r\n", + "the several States which may be included within this Union,\r\n", + "according to their respective Numbers, which shall be determined\r\n", + "by adding to the whole number of free Persons, including those\r\n", + "bound to Service for a Term of Years, and excluding Indians not taxed,\r\n", + "three fifths of all other Persons. The actual Enumeration shall be made\r\n", + "within three Years after the first Meeting of the Congress of the\r\n", + "United States, and within every subsequent Term of ten Years,\r\n", + "in such Manner as they shall by law Direct.\n", + "Article 1\r\n", + "\r\n", + "Section 1. All legislative Powers herein granted shall be vested in a\r\n", + "Congress of the United States, which shall consist of a Senate and\r\n", + "House of Representatives.\r\n", + "\r\n", + "Section 2. The House of Representatives shall be composed of Members\r\n", + "chosen every second Year by the People of the several States,\r\n", + "and the electors in each State shall have the qualifications requisite\r\n", + "for electors of the most numerous branch of the State legislature.\r\n", + "\r\n", + "No Person shall be a Representative who shall not have attained to the\r\n", + "Age of twenty five Years, and been seven Years a citizen of the United States,\r\n", + "and who shall not, when elected, be an Inhabitant of that State in which\r\n", + "he shall be chosen. | \n", + "YES \n", + " | \n", + "