{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "aiHV6ip2f5id" }, "source": [ "# Building a Semantic Cache with Redis and VertexAI Gemini Model\n", "\n", "\"Open\n" ] }, { "cell_type": "markdown", "metadata": { "id": "np5gjopbPBS9" }, "source": [ "## Intro\n", "Google's Vertex AI has expanded its capabilities by introducing [Generative AI](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview). This advanced technology comes with a specialized [in-console studio experience](https://cloud.google.com/vertex-ai/docs/generative-ai/start/quickstarts/quickstart), a [dedicated API](https://cloud.google.com/vertex-ai/docs/generative-ai/start/quickstarts/api-quickstart) and [Python SDK](https://cloud.google.com/vertex-ai/docs/python-sdk/use-vertex-ai-python-sdk) designed for deploying and managing instances of Google's powerful Gemini language models.\n", "\n", "Redis offers robust vector database features. When coupled with its versatile data structures - including lists, hashes, JSON, and sets - Redis shines as the optimal solution for crafting high-quality Large Language Model (LLM)-based applications. It embodies a streamlined architecture and exceptional performance, making it an instrumental tool for production environments.\n", "\n", "**Below we will design a semantic caching layer using Gemini (LLM) and Redis.**" ] }, { "cell_type": "markdown", "metadata": { "id": "37rbBPKdL09o" }, "source": [ "## 1. Setup\n", "Before we begin, we must install some required libraries, authenticate with Google, create a Redis database, and initialize other required components.\n" ] }, { "cell_type": "markdown", "metadata": { "id": "7MMyrImcPPBo" }, "source": [ "### Install required libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "id": "pc-IxYu3wnQm" }, "outputs": [], "source": [ "%pip install -q \"redisvl>=0.4.1\" unstructured[pdf]\n", "%pip install -q llama-parse llama-index-readers-file\n", "%pip install -q langchain langchain-google-vertexai" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import IPython\n", "\n", "app = IPython.Application.instance()\n", "app.kernel.do_shutdown(True)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "id": "EilkeT0PelCh" }, "outputs": [], "source": [ "import textwrap\n", "\n", "from IPython.display import display\n", "from IPython.display import Markdown\n", "\n", "def to_markdown(text):\n", " text = text.replace('•', ' *')\n", " return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))" ] }, { "cell_type": "markdown", "metadata": { "id": "THynXaAhPRNb" }, "source": [ "### Connect to resources" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "-fR3mWQvdKxb" }, "outputs": [], "source": [ "import os\n", "import nest_asyncio\n", "from getpass import getpass\n", "\n", "\n", "# input your Llama Cloud API Key\n", "if \"LLAMA_CLOUD_API_KEY\" not in os.environ:\n", " os.environ[\"LLAMA_CLOUD_API_KEY\"] = getpass(\"LLAMA_CLOUD_API_KEY:\")\n", "\n", "# input your GCP project ID and region for Vertex AI\n", "if \"GCP_PROJECT_ID\" not in os.environ:\n", " PROJECT_ID = getpass(\"GCP_PROJECT_ID:\") #'central-beach-194106'\n", " REGION = input(\"GCP_REGION:\") #'us-central1'\n", "else:\n", " PROJECT_ID = os.environ[\"GCP_PROJECT_ID\"]\n", " REGION = os.environ[\"GCP_REGION\"]\n", "\n", "# need this for running llama-index code in Jupyter Notebooks\n", "nest_asyncio.apply()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "jdzxvKgwlNPY", "outputId": "8b7ade7e-97bb-42ca-8fff-a18fc66e3790" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Authenticated\n" ] } ], "source": [ "from google.colab import auth\n", "\n", "auth.authenticate_user()\n", "print('Authenticated')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "CITRv5zUyVSN" }, "outputs": [], "source": [ "import vertexai\n", "\n", "vertexai.init(project=PROJECT_ID, location=REGION)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "id": "4DvCWkLrUIbG" }, "outputs": [], "source": [ "from langchain_google_vertexai import ChatVertexAI\n", "\n", "# Create LLM instance\n", "llm = ChatVertexAI(\n", " model_name=\"gemini-2.0-flash-001\",\n", " temperature=0.5,\n", " top_p=0.85\n", ")" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "id": "Kge8K1TQPoaD" }, "outputs": [], "source": [ "from redisvl.utils.vectorize import VertexAITextVectorizer\n", "\n", "# Create vectorizer instance\n", "vectorizer = VertexAITextVectorizer(\n", " model = \"textembedding-gecko@003\",\n", " api_config = {\"project_id\": PROJECT_ID, \"location\": REGION}\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "PucGDUf4fHn2" }, "source": [ "### Fetch sample dataset\n", "\n", "For the semantic caching demonstration today we will be focusing on a chevy colorado truck brochure.\n" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "IeNQp1k3fJk1", "outputId": "f8f56fed-9995-4c58-fd6e-13838fbf25e1" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--2024-05-21 15:29:42-- https://raw.githubusercontent.com/redis-developer/LLM-Document-Chat/main/docs/2022-chevrolet-colorado-ebrochure.pdf\n", "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.110.133, 185.199.111.133, ...\n", "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 3566101 (3.4M) [application/octet-stream]\n", "Saving to: ‘data/2022-chevrolet-colorado-ebrochure.pdf’\n", "\n", "data/2022-chevrolet 100%[===================>] 3.40M --.-KB/s in 0.05s \n", "\n", "2024-05-21 15:29:42 (62.3 MB/s) - ‘data/2022-chevrolet-colorado-ebrochure.pdf’ saved [3566101/3566101]\n", "\n" ] } ], "source": [ "!mkdir -p 'data/'\n", "!wget 'https://raw.githubusercontent.com/redis-developer/LLM-Document-Chat/main/docs/2022-chevrolet-colorado-ebrochure.pdf' -O 'data/2022-chevrolet-colorado-ebrochure.pdf'" ] }, { "cell_type": "markdown", "metadata": { "id": "p5kx9ePDwwp6" }, "source": [ "### Install Redis locally\n", "If you have a Redis db running elsewhere with [Redis Stack](https://redis.io/docs/about/about-stack/) installed, you don't need to run it on this machine. You can skip to the \"Connect to Redis server\" step." ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "vs4KZURX4XpT", "outputId": "04ed262d-8751-4b69-bda4-e519ebe324e2" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb jammy main\n", "Starting redis-stack-server, database path /var/lib/redis-stack\n" ] } ], "source": [ "# NBVAL_SKIP\n", "%%sh\n", "curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg\n", "echo \"deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main\" | sudo tee /etc/apt/sources.list.d/redis.list\n", "sudo apt-get update > /dev/null 2>&1\n", "sudo apt-get install redis-stack-server > /dev/null 2>&1\n", "redis-stack-server --daemonize yes" ] }, { "cell_type": "markdown", "metadata": { "id": "zvDp8WNz4XpU" }, "source": [ "Replace the connection params below with your own if you are connecting to an external Redis instance." ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "duCyNgfZ4XpU", "outputId": "4679665b-8400-4c3c-f456-39898da90299" }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import os\n", "import redis\n", "\n", "# Redis connection params\n", "REDIS_HOST = os.getenv(\"REDIS_HOST\", \"localhost\") #\"redis-12110.c82.us-east-1-2.ec2.cloud.redislabs.com\"\n", "REDIS_PORT = os.getenv(\"REDIS_PORT\", \"6379\") #12110\n", "REDIS_PASSWORD = os.getenv(\"REDIS_PASSWORD\", \"\") #\"pobhBJP7Psicp2gV0iqa2ZOc1WdXXXXX\"\n", "\n", "# Create Redis client\n", "redis_client = redis.Redis(\n", " host=REDIS_HOST,\n", " port=REDIS_PORT,\n", " password=REDIS_PASSWORD\n", ")\n", "\n", "# Test connection\n", "redis_client.ping()" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "0Rrz76w96dF3", "outputId": "f1f02254-e3b5-4bf0-acec-629e8d8046b7" }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Clear Redis database (optional)\n", "redis_client.flushdb()" ] }, { "cell_type": "markdown", "metadata": { "id": "peqHRwfvmA0e" }, "source": [ "## 2. Semantic Caching Strategies\n", "\n", "\n", "There are several strategies for semantic caching that should be considered for your RAG application depending on the data source, who the users are, the kinds of questions you anticipate, and the validity of the data sources in question.\n", "\n", "**Common caching strategies with LLMs:**\n", "\n", "1. Pre-generated Cache w/ Google Gemini LLM\n", "2. Online caching (live)\n", "\n", "This notebook will explore building a pre-generated cache with Google Gemini.\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "id": "sfgEMKkBPiIy" }, "source": [ "### Pre-generated Cache\n", "\n", "The objective of the pre-generated cache is to load Redis with **frequently asked questions**, derived from domain experts, LLMs, or session data (collected from your application). This is the SAFEST caching strategy because the information can be manually vetted before placing in the cache. This information.\n", "\n", "This notebook will use:\n", "- **LlamaIndex** to parse the pdf file with high fidelity.\n", "- **Google Gemini LLM** to extract FAQs from the extracted source material.\n", "- **Redis** to index the FAQs for semantic caching.\n", "\n", "*Note that many of these components could be changed out for other foundation models and parsing tools that are approved by your organization for use.*" ] }, { "cell_type": "markdown", "metadata": { "id": "VsNJn75A0VJm" }, "source": [ "#### Parse source pdf document\n", "\n", "Our chevy colorado product manual is the source of \"truth\" here.\n", "\n" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "id": "HG_w_jPSmXVb" }, "outputs": [], "source": [ "from llama_parse import LlamaParse\n", "from llama_index.core import SimpleDirectoryReader" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "BtTSE4ZmmDt5", "outputId": "d5324418-4654-4e13-a8e2-57c0370bf36e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Started parsing the file under job_id 5afa9727-102d-4c25-965a-de91941db75c\n", "." ] } ], "source": [ "# set up LlamaParse agent to convert the PDF into markdown\n", "parser = LlamaParse(\n", " result_type=\"markdown\" # \"markdown\" and \"text\" are available\n", ")\n", "\n", "file_extractor = {\".pdf\": parser}\n", "reader = SimpleDirectoryReader(\"./data\", file_extractor=file_extractor)\n", "documents = reader.load_data()" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "id": "tEVzLfjzmD-k" }, "outputs": [], "source": [ "from llama_index.core.node_parser import MarkdownNodeParser\n", "\n", "parser = MarkdownNodeParser()\n", "\n", "nodes = parser.get_nodes_from_documents(documents)" ] }, { "cell_type": "code", "execution_count": 48, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "rRh5Dw5jmEBr", "outputId": "fa442464-8193-4e02-c5dd-749a7fdb22ad" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "############ \n", " COLORADO 2022\n", "---\n", "Choose your adventure. The 2022 Colorado delivers everything you could ask for in a midsize pickup. Engine choices that are powerful and efficient, including an available GM-exclusive Duramax® 2.8L Turbo-Diesel engine that provides up to 7,700 lbs. of towing muscle. A ZR2 off-road beast with the capability to conquer tough trails. And a comfortable interior filled with convenience and technology features. So go ahead. Choose your best life in Colorado.\n", "\n", "Colorado Crew Cab ZR2 in Sand Dune Metallic with available ZR2 Dusk Special Edition. Vehicle shown can tow up to 5,000 lbs.\n", "\n", "1 Requires Colorado Crew Cab Short Box LT 2WD with available Trailering Package, LT Convenience Package and Safety Package. 2 Maximum trailering ratings are intended for comparison purposes only. Before you buy a vehicle or use it for trailering, carefully review the Trailering section of the Owner’s Manual. The trailering capacity of your specific vehicle may vary. The weight of passengers, cargo and options or accessories may reduce the amount you can trailer. 3 Requires available Trailering Package and automatic locking rear differential on LT; requires available Trailering Package on Z71.\n", "\n", "Due to current supply chain shortages, certain features shown have limited or late availability, or are no longer available. See the window label or a dealer regarding the features on an individual vehicle.\n", "---\n", "############ \n", " INTRODUCING COLORADO\n", "############ \n", " Colorado at a glance.\n", "\n", "- Four models: WT, LT, Z71 and ZR2\n", "- Extended Cab or Crew Cab\n", "- Three engines\n", "- 2.5L 4-cylinder\n", "- 3.6L V6\n", "- Duramax 2.8L Turbo-Diesel\n", "- 30 MPG highway - 1 with available diesel engine\n", "- 7,700 lbs. maximum trailering weight - 2 with available diesel engine\n", "- Apple CarPlay® - 3 and Android Auto™ - 4 compatibility\n", "\n", "Available ZR2 Bison Edition includes:\n", "\n", "- 17-inch AEV-designed aluminum wheels\n", "- AEV front bumper with winch provisions\n", "- AEV rear bumper with recovery points\n", "- Five AEV hot-stamped boron steel skid plates\n", "- AEV fender flares\n", "- Fog lamps\n", "- Front and rear floor liners with AEV logo\n", "- AEV embroidered head restraints\n", "\n", "Colorado Crew Cab ZR2 in Sand Dune Metallic with available ZR2 Bison Edition and available accessories.\n", "\n", "Colorado Extended Cab Z71 in Black with available Chevrolet Accessories.\n", "\n", "1 EPA-estimated MPG city/highway: Colorado 2WD with available Duramax 2.8L Turbo-Diesel engine 20/30.\n", "\n", "2 Requires Colorado Crew Cab Short Box LT 2WD with available Trailering Package, LT Convenience Package and Safety Package. Maximum trailering ratings are intended for comparison purposes only. Before you buy a vehicle or use it for trailering, carefully review the Trailering section of the Owner’s Manual. The trailering capacity of your specific vehicle may vary. The weight of passengers, cargo and options or accessories may reduce the amount you can trailer.\n", "\n", "3 Vehicle user interface is a product of Apple and its terms and privacy statements apply. Requires compatible iPhone and data plan rates apply.\n", "\n", "4 Vehicle user interface is a product of Google and its terms and privacy statements apply. Requires the Android Auto app on Google Play and a compatible Android smartphone. Data plan rates apply. You can check which smartphones are compatible at g.co/androidauto/requirements.\n", "\n", "5 Non-GM warranty. See your dealer for limited warranty details.\n", "\n", "Apple CarPlay, iPhone, Siri and Apple Music are trademarks of Apple Inc., registered in the U.S. and other countries. Android, Google Play and Android Auto are trademarks of Google LLC.\n", "\n", "Due to current supply chain shortages, certain features shown have limited or late availability, or are no longer available. See the window label or a dealer regarding the features on an individual vehicle.\n", "---\n", "############ \n", " MODELS\n", "\n", "Four models to choose from. Colorado is everything you need in a midsize pickup, but make sure to add everything you want.\n", "\n", "|WT|LT|Z71|ZR2|\n", "|---|---|---|---|\n", "|Always ready, willing and able to work.|Take a step forward in comfort and style.|Leave the paved roads behind.|Off-road warrior that’s on-road capable.|\n", "\n", "Actual production vehicle may vary.\n", "\n", "Actual production vehicle may vary.\n", "\n", "|WT|2.5L 4-cylinder engine (Extended Cab and Crew Cab Short Box 2WD)|4-wheel antilock disc brakes|CornerStep rear bumper|Locking tailgate|Recovery hooks 1 (4x4)|Cargo area lighting|4-way power-adjustable driver seat|Dual rear seats (Extended Cab)|Front center floor console|Chevrolet Infotainment 3 system 2 with 7-inch diagonal color touch-screen|Two USB ports 3|\n", "|---|---|---|---|---|---|---|---|---|---|---|---|\n", "|LT|Body-color rear bumper, mirror caps and door handles|EZ Lift power locking tailgate|Remote Keyless Entry|6-way power-adjustable driver seat|Leather-wrapped steering wheel|Inside rearview auto-dimming mirror|Overhead console|Chevrolet Infotainment 3 system 2 with 8-inch diagonal color touch-screen|Folding rear bench seat (Crew Cab)|Two charge-only USB ports 3 on rear of center console|Cruise control|\n", "|Z71|3.6L V6 engine|17-inch aluminum wheels|Power-adjustable outside mirrors|Hill Descent Control|Automatic locking rear differential|Transfer case shield (4x4)|17-inch bright machined-aluminum wheels and all-terrain tires|Black Chevrolet bowtie emblems|Projector-beam headlamps|Fog lamps|Remote vehicle starter system|Automatic climate control|HD Rear Vision Camera 4|Z71 Midnight Edition available|\n", "|ZR2|ZR2 Off-Road Package|Multimatic DSSV™ Damping System|Front and rear full locking differentials|Increased clearance and track width compared to other trim levels|Skid plates|Transfer case shield|17-inch Graphite and Oxide Gold aluminum wheels and all-terrain tires|Off-Road Appearance Package|Distinctive hood, front fascia and grille|Spray-on bedliner with ZR2 logo|Front and rear wheel flares|Leather-appointed front seats|ZR2 Bison Edition available|ZR2 Dusk Special Edition available|ZR2 Midnight Special Edition available|\n", "\n", "1 To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual. 2 Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices. 3 Not compatible with all devices. 4 Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "Due to current supply chain shortages, certain features shown have limited or late availability, or are no longer available. See the window label or a dealer regarding the features on an individual vehicle.\n", "---\n", "|MODEL|AVAILABILITY|\n", "|---|---|\n", "|STANDARD|NOT AVAILABLE|\n", "|STANDARD|AVAILABLE|\n", "|MAX PAYLOAD|1|\n", "|MAX TRAILERING|2|\n", "|EXTENDED CAB|TRIM|2WD|4x4|ENGINE|ENGINES|RATING (LBS.)|WEIGHT RATING (LBS.)|\n", "| |WT|2.5L I-4|3.6L V6|1,530|7,000|\n", "| |WT|2.5L I-4|3.6L V6|1,500|7,000|\n", "| |LT|2.5L I-4|3.6L V6|1,530|7,000|\n", "| |LT|2.5L I-4|3.6L V6|1,490|7,000|\n", "| |Z71|3.6L V6|1,460|7,000|\n", "|ZR2|3.6L V6Duramax 2.8L I-4|1,350|5,000|\n", "|CREW CAB SHORT BOX|TRIM|2WD|4x4|ENGINE|ENGINES|RATING (LBS.)|WEIGHT RATING (LBS.)|\n", "| |WT|2.5L I-4|3.6L V6|1,540|7,000|\n", "| |WT|3.6L V6|1,530|7,000|\n", "| |LT|2.5L I-4|3.6L V6, Duramax 2.8L I-4|1,540|7,700|\n", "| |LT|3.6L V6|Duramax 2.8L I-4|1,500|7,600|\n", "| |Z71|3.6L V6|1,490|7,000|\n", "| |Z71|3.6L V6|Duramax 2.8L I-4|1,450|7,600|\n", "|ZR2|3.6L V6Duramax 2.8L I-4|1,240|5,000|\n", "|CREW CAB LONG BOX|TRIM|2WD|4x4|ENGINE|ENGINES|RATING (LBS.)|WEIGHT RATING (LBS.)|\n", "| |WT|3.6L V6|1,480|7,000|\n", "| |WT|3.6L V6|1,460|7,000|\n", "| |LT|3.6L V6|1,480|7,000|\n", "| |LT|3.6L V6|Duramax 2.8L I-4|1,450|7,600|\n", "|Z71|3.6L V6|1,400|7,600|\n", "\n", "1 These maximum payload ratings are intended for comparison purposes only. Before you buy a vehicle or use it to haul people or cargo, carefully review the Vehicle Loading section of the Owner’s Manual and check the carrying capacity of your specific vehicle on the label on the inside of the driver door jamb.\n", "\n", "2 Maximum trailering ratings are intended for comparison purposes only. Before you buy a vehicle or use it for trailering, carefully review the Trailering section of the Owner’s Manual. The trailering capacity of your specific vehicle may vary. The weight of passengers, cargo and options or accessories may reduce the amount you can trailer.\n", "\n", "3 Requires available 3.6L V6 engine.\n", "\n", "4 Requires available Trailering Package.\n", "\n", "5 Requires 3.6L V6 engine.\n", "\n", "6 Requires available Duramax 2.8L I-4 engine.\n", "---\n", "############ \n", " STANDARD EQUIPMENT\n", "############ \n", " Standard on every Colorado:\n", "\n", "|MECHANICAL|INTERIOR|\n", "|---|---|\n", "|Battery – with rundown protection and retained accessory power|Airbags - 1– dual-stage frontal airbags for driver and front passenger; seat-mounted side-impact airbags for driver and front passenger; head-curtain airbags for front and rear outboard seating positions; includes front Passenger Sensing System for frontal passenger airbag|\n", "|Brakes – 4-wheel antilock disc with Duralife® rotors|Audio – 6-speaker system|\n", "|Frame – fully boxed|Connectivity – Bluetooth® phone connectivity and wireless audio streaming|\n", "|StabiliTrak® – Electronic Stability Control System and Traction Control; includes Hill Start Assist|Console – front center floor|\n", "|Steering – rack-and-pinion with Electric Power Steering (EPS) assist|Door locks – power programmable with lockout protection and rear door child security|\n", "| |Driver Information Center|\n", "| |Floor mats – front and rear, carpeted|\n", "| |Instrument cluster – with speedometer, fuel level, engine temperature and tachometer|\n", "| |Media – two USB ports and auxiliary input jack in front center floor console|\n", "| |Power outlet – 12-volt auxiliary, front|\n", "| |Seats – front bucket|\n", "| |- dual rear with underseat storage (Extended Cab)|\n", "| |- rear folding bench (Crew Cab)|\n", "| | |\n", "| |SiriusXM® - 3-month trial subscription|\n", "| | |\n", "| |Teen Driver technology|\n", "| |Temperature display – outside|\n", "| |Theft-deterrent system – engine immobilizer|\n", "| |Tire Pressure Monitoring System – with Tire Fill Alert (does not apply to spare tire)|\n", "| | |\n", "| |Windows – power with driver express-up/-down, all others express-down|\n", "\n", "1 A NOTE ON CHILD SAFETY: Always use seat belts and the correct child restraint for your child’s age and size, even with airbags. Even in vehicles equipped with the Passenger Sensing System, children are safer when properly secured in a rear seat in the appropriate infant, child or booster seat. Never place a rear-facing infant restraint in the front seat of any vehicle equipped with an active frontal airbag. See your vehicle Owner’s Manual and the child safety seat instructions for more safety information.\n", "\n", "2 Go to my.chevrolet.com/learnAbout/bluetooth to find out which phones are compatible with the vehicle. Full Bluetooth feature functionality varies by device, model and software version.\n", "\n", "3 Not compatible with all devices.\n", "\n", "4 If you decide to continue service after your trial, your selected subscription plan will automatically renew thereafter. You will be charged at then-current rates. Fees and taxes apply. To cancel you must call SiriusXM at 1-866-635-2349. See SiriusXM Customer Agreement for complete terms at siriusxm.com. All fees and programming subject to change.\n", "\n", "5 Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "---\n", "############ \n", " ENGINE SPECIFICATIONS\n", "\n", "|2.5L DOHC I-4|3.6L DOHC V6|DURAMAX 2.8L TURBO-DIESEL I-4|\n", "|---|---|---|\n", "|Standard on WT and LT Extended Cab, and WT and LT Crew Cab Short Box 2WD.|Standard on WT and LT Crew Cab Short Box 4x4, WT and LT Crew Cab Long Box, Z71, and ZR2.|Available on LT Crew Cab Short Box, LT Crew Cab Long Box 4x4, Z71 Crew Cab 4x4 and ZR2.|\n", "|6-speed automatic transmission|8-speed automatic transmission|6-speed automatic transmission|\n", "|200 hp @ 6300 rpm|308 hp @ 6800 rpm|181 hp @ 3400 rpm|\n", "|191 lb.-ft. of torque @ 4400 rpm|275 lb.-ft. of torque @ 4000 rpm|369 lb.-ft. of torque @ 2000 rpm|\n", "|Displacement: 2460 cc (150 cu. in.)|Displacement: 3640 cc (222 cu. in.)|Displacement: 2776 cc (169 cu. in.)|\n", "|Bore and stroke: 88 mm x 101 mm (3.46 in. x 3.97 in.)|Bore and stroke: 95 mm x 85.6 mm (3.74 in. x 3.37 in.)|Bore and stroke: 94 mm x 100 mm (3.70 in. x 3.94 in.)|\n", "|Compression ratio: 11.3:1|Compression ratio: 11.5:1|Compression ratio: 16.5:1|\n", "|Block: Cast-aluminum|Block: Cast-aluminum|Block: Cast-iron|\n", "|Cylinder head: Cast-aluminum|Cylinder head: Cast-aluminum|Cylinder head: Cast-aluminum|\n", "|Valvetrain: Dual-overhead camshafts with 4 valves per cylinder and Variable Valve Timing (VVT)|Valvetrain: Dual-overhead camshafts with 4 valves per cylinder and Variable Valve Timing (VVT)|Valvetrain: Dual-overhead camshafts with 4 valves per cylinder Fuel delivery: High-pressure, common rail Direct Injection|\n", "|Fuel delivery: Direct Injection|Fuel delivery: Direct Injection|Max payload rating: 1,480 lbs.|\n", "|Max payload rating: 1,420 lbs.|Max payload rating: 1,540 lbs.|Max trailering weight rating: 7,700 lbs.|\n", "|Max trailering weight rating: 3,500 lbs.|Max trailering weight rating: 7,000 lbs.|EPA-estimated fuel economy – 2WD: 20 MPG city/30 highway|\n", "|EPA-estimated fuel economy – 2WD: 19 MPG city/25 highway|EPA-estimated fuel economy – 2WD: 18 MPG city/25 highway|EPA-estimated fuel economy – 4x4: 19 MPG city/28 highway|\n", "|EPA-estimated fuel economy – 4x4: 19 MPG city/24 highway|EPA-estimated fuel economy – 4x4: 17 MPG city/24 highway|EPA-estimated fuel economy – ZR2: 18 MPG city/22 highway|\n", "| | |EPA-estimated fuel economy – ZR2: 16 MPG city/18 highway|\n", "\n", "1 These maximum payload ratings are intended for comparison purposes only. Before you buy a vehicle or use it to haul people or cargo, carefully review the Vehicle Loading section of the Owner’s Manual and check the carrying capacity of your specific vehicle on the label on the inside of the driver door jamb.\n", "\n", "2 Requires Colorado Crew Cab LT 2WD.\n", "\n", "3 Maximum trailering ratings are intended for comparison purposes only. Before you buy a vehicle or use it for trailering, carefully review the Trailering section of the Owner’s Manual. The trailering capacity of your specific vehicle may vary. The weight of passengers, cargo and options or accessories may reduce the amount you can trailer.\n", "\n", "4 Requires Colorado Crew Cab Short Box WT 2WD or Colorado Crew Cab Short Box LT 2WD.\n", "\n", "5 Requires available Trailering Package.\n", "\n", "6 Requires Colorado Crew Cab Short Box LT 2WD.\n", "---\n", "| |Summit White|Satin Steel Metallic|Bright Blue Metallic|\n", "|---|---|---|---|\n", "|Black|1 Extra-cost color.| | |\n", "\n", "Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.\n", "---\n", "############ \n", " WORK TRUCK (WT) FEATURES\n", "\n", "|Dark Ash Vinyl (shown)|Dark Ash Cloth|\n", "|---|---|\n", "|MECHANICAL| |\n", "|Engine – 2.5L DOHC 4-cylinder with Variable Valve Timing (VVT) and Direct Injection| |\n", "|Engine – 3.6L DOHC V6 with Variable Valve Timing (VVT) and Direct Injection (Crew Cab 4x4 and Crew Cab Long Box 2WD models)| |\n", "|Transfer case – 2-speed, electronic with rotary controls; includes Neutral position for dinghy towing (4x4 models)| |\n", "|Transmission – 6-speed automatic, electronically controlled with overdrive| |\n", "|Transmission – 8-speed automatic, electronically controlled with overdrive, Tow/Haul mode and Hitch Guidance (Crew Cab 4x4 and Crew Cab Long Box 2WD models)| |\n", "|EXTERIOR| |\n", "|Mirrors – manual-adjustable, manual-folding with Black caps| |\n", "|Recovery hooks – front (4x4 models)| |\n", "|Tires – 255/65R17 all-season| |\n", "|17\" Ultra Silver Metallic-Painted Steel Wheels|18\" Dark Argent Metallic-Painted Aluminum Wheels|\n", "|INTERIOR| |\n", "|Air conditioning – manual, single-zone| |\n", "|Entertainment – Chevrolet Infotainment 3 system with 7-inch diagonal color touch-screen| |\n", "|Rear Vision Camera| |\n", "|Seat – driver 4-way power adjuster with manual recline| |\n", "|Steering column – manual tilt| |\n", "\n", "1 Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "2 To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual.\n", "\n", "3 Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices.\n", "\n", "Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.\n", "---\n", "|LT EXTERIOR COLORS|Summit White|Satin Steel Metallic|Bright Blue Metallic|\n", "|---|---|---|---|\n", "|Black| | | |\n", "|1 Extra-cost color.|1 Extra-cost color.|1 Extra-cost color.|1 Extra-cost color.|\n", "|Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.|Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.|Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.|Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.|\n", "---\n", "############ \n", " LT FEATURES\n", "\n", "|Available on Extended Cab, Crew Cab Short Box and Crew Cab Long Box. In addition to standard equipment,| | |\n", "|---|---|---|\n", "|Jet Black Cloth| | |\n", "|Jet Black Leather-Appointed Front Seating Surfaces|4 (shown)| |\n", "|select LT features include:| | |\n", "############ \n", " MECHANICAL\n", "\n", "- Engine – 2.5L DOHC 4-cylinder with Variable Valve Timing (VVT) and Direct Injection\n", "- – 3.6L DOHC V6 with Variable Valve Timing (VVT) and Direct Injection (Crew Cab 4x4 and Crew Cab Long Box 2WD models)\n", "- Transfer case – 2-speed, electronic Autotrac® with rotary controls; includes Neutral position for dinghy towing (4x4 models)\n", "- Transmission – 6-speed automatic, electronically controlled with overdrive\n", "- – 8-speed automatic, electronically controlled with overdrive, Tow/Haul mode and Hitch Guidance 1(Crew Cab 4x4 and Crew Cab Long Box 2WD models)\n", "############ \n", " EXTERIOR\n", "\n", "- Mirrors – power-adjustable, manual-folding with body-color caps; includes driver spotter mirror\n", "- Recovery hooks 2 – front (4x4 models)\n", "- 17\" Blade Silver Metallic-Painted Aluminum Wheels\n", "- 18\" Dark Argent Metallic-Painted Aluminum Wheels\n", "- Tires – 255/65R17 all-season\n", "############ \n", " INTERIOR\n", "\n", "- Air conditioning – manual, single-zone\n", "- Cruise control – electronic with Set and Resume Speed\n", "- Entertainment – Chevrolet Infotainment 3 system 3 with 8-inch diagonal color touch-screen\n", "- Mirror – rearview, auto-dimming\n", "- Rear Vision Camera 1\n", "- Remote Keyless Entry – extended-range\n", "- Seat – driver 6-way power adjuster\n", "- Steering column – manual tilt and telescopic\n", "- Steering wheel – leather-wrapped with mounted audio, cruise and phone controls\n", "- 18\" Black-Painted Aluminum Wheels with Red Accents\n", "\n", "Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual.\n", "\n", "Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices.\n", "\n", "Available on Crew Cab models only. Requires available Luxury Package.\n", "\n", "Preproduction models shown. Actual production models may vary. Some features shown may have limited, late, or no availability. See dealer for feature availability.\n", "---\n", "|Summit White|Satin Steel Metallic|Sand Dune Metallic|\n", "|---|---|---|\n", "|Bright Blue Metallic|Black|Black|\n", "|1 Extra-cost color. 2 Limited availability.|1 Extra-cost color. 2 Limited availability.|1 Extra-cost color. 2 Limited availability.|\n", "---\n", "############ \n", " Z71 FEATURES\n", "\n", "|Available on Extended Cab, Crew Cab Short Box and Crew Cab Long Box. In addition to standard equipment,|Jet Black Cloth/Leatherette|Jet Black Leather-Appointed Front Seating Surfaces|4 (shown)|\n", "|---|---|---|---|\n", "|select Z71 features include:| | | |\n", "############ \n", " MECHANICAL\n", "\n", "- Differential – automatic locking rear\n", "- Engine – 3.6L DOHC V6 with Variable Valve Timing (VVT) and Direct Injection\n", "- Transfer case – 2-speed, electronic Autotrac with rotary controls; includes Neutral position for dinghy towing (4x4 models)\n", "- – transfer case shield (4x4 models)\n", "- Transmission – 8-speed automatic, electronically controlled with overdrive, Tow/Haul mode and Hitch Guidance\n", "- Z71 Off-Road Suspension Package\n", "############ \n", " EXTERIOR\n", "\n", "- Fog lamps\n", "- 17\" Bright Machined-Aluminum Wheels\n", "- 17\" Gloss Black-Painted Aluminum Wheels\n", "- Mirrors – heated, power-adjustable, manual-folding with Black caps; includes driver spotter mirror\n", "- Recovery hooks – front\n", "- Tires – 255/65R17 all-terrain\n", "############ \n", " INTERIOR\n", "\n", "- Air conditioning – automatic, single-zone\n", "- Entertainment – Chevrolet Infotainment 3 Plus system with 8-inch diagonal HD color touch-screen\n", "- Remote vehicle starter system\n", "- Seat – driver 6-way power adjuster and power lumbar control\n", "- Steering wheel – heated, leather-wrapped with mounted audio, cruise and phone controls\n", "- Window – sliding rear\n", "\n", "1 Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "2 To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual.\n", "\n", "3 Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices.\n", "\n", "4 Extra-cost interior. Available on Crew Cab models only.\n", "\n", "Some features shown may have limited, late or no availability. See dealer for feature availability.\n", "---\n", "|Summit White|Satin Steel Metallic|Sand Dune Metallic|\n", "|---|---|---|\n", "|Bright Blue Metallic|Black|Black|\n", "|1 Extra-cost color.|1 Extra-cost color.|1 Extra-cost color.|\n", "\n", "Some features shown may have limited, late or no availability. See dealer for feature availability.\n", "---\n", "############ \n", " ZR2 FEATURES\n", "\n", "Available on Extended Cab and Crew Cab Short Box. In addition to standard equipment, select ZR2 features include:\n", "Jet Black Leather-Appointed Front Seating Surfaces (shown)\n", "############ \n", " MECHANICAL\n", "\n", "Differential – full locking front and rear, driver selectable\n", "Engine – 3.6L DOHC V6 wip Variable Valve Timing (VVT) and Direct Injection\n", "Trailering Package – trailer hitch and 7-pin connector\n", "Transfer case – 2-speed, electronic Autotrac wip rotary controls; includes Neutral position for dinghy towing\n", "Transmission – 8-speed automatic, electronically controlled wip overdrive, Tow/Haul mode and Hitch Guidance\n", "############ \n", " EXTERIOR\n", "\n", "Bedliner – Black spray-on wip ZR2 logo\n", "Mirrors – heated, power-adjustable, manual-folding wip body-color caps; includes driver spotter mirror\n", "Off-road rocker protection (limited availability; see dealer for details)\n", "17\" Graphite and Oxide Gold Aluminum Wheels\n", "17\" AEV-Designed Dark Graphite Aluminum Wheels\n", "Recovery hooks - Red\n", "Tires – 265/65R17 Goodyear Wrangler DuraTrac® all-terrain\n", "ZR2 Off-Road Package – taller and wider stance, Multimatic DSSV™ Damping System, off-road front fascia and rear bumper, fender flares and Chevrolet lettered grille wip small flowtie emblem\n", "############ \n", " INTERIOR\n", "\n", "Air conditioning – automatic, single-zone\n", "Entertainment – Chevrolet Infotainment 3 Plus system wip 8-inch diagonal HD color touch-screen\n", "Remote vehicle starter system\n", "Seat – driver 6-way power adjuster and power lumbar control\n", "Front passenger 4-way power adjuster and power lumbar control\n", "17\" Gloss Black-Painted Aluminum Wheels\n", "Steering wheel – heated, leaper-wrapped wip mounted audio, cruise and phone controls\n", "\n", "Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual.\n", "\n", "Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices.\n", "\n", "Some features shown may have limited, late or no availability. See dealer for feature availability.\n", "---\n", "############ \n", " SPECIFICATIONS\n", "\n", "|SAFETY AND DRIVER ASSISTANCE|MECHANICAL (CONTINUED)|\n", "|---|---|\n", "|- Airbags - dual-stage frontal airbags for driver and front passenger; seat-mounted side-impact airbags for driver and front passenger; head-curtain airbags for front and rear outboard seating positions; includes front Passenger Sensing System for frontal passenger airbag\n", "- Forward Collision Alert (requires available Safety Package)\n", "- Lane Departure Warning (requires available Safety Package)\n", "- Rear Park Assist (feature will not function on certain models without dealer retrofit; see dealer or window label for details) (requires available WT Convenience Package on WT; requires available Safety Package on LT)\n", "- Rear Vision Camera\n", "- HD Rear Vision Camera (requires available Chevrolet Infotainment 3 Plus system with Navigation on LT)\n", "- Teen Driver technology\n", "- Theft-deterrent system - engine immobilizer - unauthorized entry (requires available WT Convenience Package on WT)\n", "- Tire Pressure Monitoring System - with Tire Fill Alert (does not monitor spare tire)\n", "- Up to 3 months of OnStar® Safety & Security coverage\n", "|- Engine - 2.5L DOHC 4-cylinder with Variable Valve Timing (VVT) and Direct Injection; 200 hp @ 6300 rpm, 191 lb.-ft. of torque @ 4400 rpm (standard on Crew Cab Short Box 2WD and Extended Cab models)\n", "- - 3.6L DOHC V6 with Variable Valve Timing (VVT) and Direct Injection; 308 hp @ 6800 rpm, 275 lb.-ft. of torque @ 4000 rpm (standard on various models)\n", "- - Duramax 2.8L Turbo-Diesel DOHC I-4 with common rail Direct Injection; 181 hp @ 3400 rpm, 369 lb.-ft. of torque @ 2000 rpm; includes Diesel Exhaust Brake and integrated trailer brake controller (Crew Cab models only; LT requires available Safety Package, LT Convenience Package and Trailering Package; LT 2WD also requires Short Box; Z71 requires available 4x4, Safety Package and Trailering Package)\n", "- Frame - fully boxed\n", "- Hill Descent Control\n", "- StabiliTrak - Electronic Stability Control System and Traction Control; includes Hill Start Assist\n", "- Steering - rack-and-pinion with Electric Power Steering (EPS) assist\n", "- Suspension - Z71 Off-Road Package\n", "- - Multimatic DSSV™ Damping System\n", "- Tow/Haul mode - includes Hitch Guidance with dynamic trailering assist guideline (standard on various models)\n", "- Trailer brake controller - integrated (included with available Duramax 2.8L Turbo-Diesel I-4 engine; requires available Trailering Package with 3.6L V6 engine)\n", "- Transfer case - electric, 2-speed (4x4 models)\n", "- - electric, 2-speed, Autotrac (4x4 models)\n", "- - transfer case shield (4x4 models)\n", "- Transmission - 6-speed automatic, electronically controlled with overdrive (included with 2.5L DOHC 4-cylinder engine and available Duramax 2.8L Turbo-Diesel I-4 engine)\n", "- - 8-speed automatic, electronically controlled with overdrive (included with 3.6L V6 engine)\n", "|\n", "\n", "A NOTE ON CHILD SAFETY: Always use seat belts and the correct child restraint for your child’s age and size, even with airbags. Even in vehicles equipped with the Passenger Sensing System, children are safer when properly secured in a rear seat in the appropriate infant, child or booster seat. Never place a rear-facing infant restraint in the front seat of any vehicle equipped with an active frontal airbag. See your vehicle Owner’s Manual and the child safety seat instructions for more safety information.\n", "\n", "Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices. Map coverage available in the United States, Puerto Rico and Canada.\n", "\n", "When you select a monthly plan within 30 days of activating your 1-month trial, you’ll receive the next 2 months of the plan you select at no additional charge when you associate an approved payment method on file to your account and authorize recurring payments for your service plan. The amount and frequency of each recurring payment is based upon the service(s) and payment interval(s) you select from the options provided. After the trial expires, OnStar will automatically bill your payment method monthly at then-current standard monthly rates. Plans containing 4G LTE data will be billed every 30 days by AT&T. You may cancel at any time by pushing your blue OnStar button or calling 1-888-466-7827. May not be combined with other offers or retroactively applied. Offer subject to change.\n", "---\n", "############ \n", " SPECIFICATIONS\n", "\n", "|EXTERIOR|EXTERIOR (CONTINUED)|\n", "|---|---|\n", "|Bedliner – Black spray-on with Chevrolet logo; ZR2 includes ZR2 logo|● ● ● ● Moldings – Black beltline|\n", "|Bumper – rear CornerSteps|● ● ● — – chrome beltline (requires available Chrome Appearance Package)|\n", "|Bumper – rear CornerSteps|— ● — —|\n", "|Bumper – rear CornerSteps|● ● — — Recovery hooks 1– front (standard on WT and LT 4x4 models)|\n", "|Bumper – rear CornerSteps|● ● ● — – Red, front (requires available Redline Edition on LT)|\n", "|Bumper – rear CornerSteps|— ● ● ●|\n", "|Cargo box light – back of cab|● ● ● ● – EZ Lift with power lock and release (requires available WT Convenience Package on WT)|\n", "|Daytime running lamps|● ● ● ● Tire – full-size spare, 255/65R17 all-season|\n", "|Door handles – Black (requires available Redline Edition on LT)|● ● ● — – full-size spare, 265/65R17 all-terrain|\n", "|Door handles – Black (requires available Redline Edition on LT)|— — — ●|\n", "|Door handles – Black (requires available Redline Edition on LT)|● ● — —|\n", "|Fog lamps (requires available LT Convenience Package on LT; requires available ZR2 Bison Edition on ZR2)|— ● ● ● – 265/60R18 all-season (requires available 18\" Dark Argent Metallic-painted aluminum wheels on WT; requires available 18\" Dark Argent Metallic-painted aluminum wheels or Redline Edition on LT)|\n", "|Fuel filler – capless fueling (gas engine)|● ● ● ●|\n", "|Grille – chrome front grille bar with Gold bowtie emblem (certain vehicles may be built with a painted Black grille bar; see dealer for details)|● — — —|\n", "|Grille – chrome front grille bar with Gold bowtie emblem (certain vehicles may be built with a painted Black grille bar; see dealer for details)|— ● — —|\n", "|Grille – chrome front grille bar with Gold bowtie emblem (certain vehicles may be built with a painted Black grille bar; see dealer for details)|— — ● —|\n", "|Grille – chrome front grille bar with Gold bowtie emblem (certain vehicles may be built with a painted Black grille bar; see dealer for details)|— — — ●|\n", "|Headlamps – halogen with automatic on/off with automatic delay|● ● — —|\n", "|Headlamps – halogen with automatic on/off with automatic delay, projector-beam (requires available Luxury Package on LT)|— ● ● ●|\n", "|Mirrors – manual-adjustable, manual-folding|● — — —|\n", "|Mirrors – manual-adjustable, manual-folding|● ● — —|\n", "|Mirrors – manual-adjustable, manual-folding|— ● — —|\n", "|Mirrors – manual-adjustable, manual-folding|— — ● —|\n", "|Mirrors – manual-adjustable, manual-folding|— — — ●|\n", "|Fuel filler – capless fueling (gas engine)|● ● ● ●|\n", "|Grille – chrome front grille bar with Gold bowtie emblem (certain vehicles may be built with a painted Black grille bar; see dealer for details)|— — — ●|\n", "|Headlamps – halogen with automatic on/off with automatic delay|● ● — —|\n", "|Headlamps – halogen with automatic on/off with automatic delay, projector-beam (requires available Luxury Package on LT)|— ● ● ●|\n", "|Mirrors – manual-adjustable, manual-folding|● — — —|\n", "|Mirrors – manual-adjustable, manual-folding|● ● — —|\n", "|Mirrors – manual-adjustable, manual-folding|— ● — —|\n", "|Mirrors – manual-adjustable, manual-folding|— — ● —|\n", "|Mirrors – manual-adjustable, manual-folding|— — — ●|\n", "|– driver spotter mirror (requires available Custom Special Edition on WT)|●●●●|\n", "\n", "To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual.\n", "---\n", "############ \n", " SPECIFICATIONS\n", "############ \n", " (CONTINUED)\n", "\n", "|INTERIOR| |SEATING|\n", "|---|---|---|\n", "| | |Air conditioning – manual, single-zone|●|Seats – front bucket|● ● ● ●|\n", "|Air conditioning – automatic, single-zone (requires available Luxury Package on LT)|—| | |\n", "| | |Console – front center floor|●| | |\n", "|Console – overhead with sunglasses holder|—| | |\n", "| | |Cruise control – electronic with Set and Resume Speed (requires available WT Convenience Package on WT)|●| | |\n", "| | |Defogger – rear-window (requires available LT Convenience Package on LT)|—| | |\n", "| | |Door locks – power programmable with lockout protection and rear door child security|●| | |\n", "| | |Driver Information Center – monochromatic display|●| | |\n", "|Driver Information Center – enhanced with multi-color display (requires available Chevrolet Infotainment 3 Plus system on LT)|—| | |\n", "|Floor covering – Black vinyl (deletes front and rear carpeted floor mats; not available with ZR2 Bison Edition on ZR2)| |●| | |\n", "| | |Floor mats – front and rear, carpeted (not available with ZR2 Bison Edition on ZR2)|●| | |\n", "| | |Mirror – rearview, manual day/night|●| | |\n", "|Mirror – rearview, auto-dimming|—| | |\n", "| | |Remote Keyless Entry – extended-range (requires available WT Convenience Package on WT)|●| | |\n", "| | |Remote vehicle starter system (requires available LT Convenience Package on LT)|—| | |\n", "| | |Steering column – manual tilt|●| | |\n", "|Steering column – manual tilt and telescopic|—| | |\n", "| | |Steering wheel – leather-wrapped with mounted audio, cruise and phone controls|—| | |\n", "|Steering wheel – heated (requires available heated front seats or Luxury Package on LT)|—| | |\n", "| | |Visors – driver and front passenger, with passenger vanity mirror|●| | |\n", "|Visors – driver and front passenger, illuminated vanity mirrors|—| | |\n", "| | |Window – sliding rear (requires available LT Convenience Package on LT)|—| | |\n", "| | |Windows – power with driver express-up/-down, all others express-down|● ● ● ●| | |\n", "\n", "Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices.\n", "\n", "Map coverage available in the United States, Puerto Rico and Canada.\n", "---\n", "############ \n", " SPECIFICATIONS\n", "############ \n", " ENTERTAINMENT\n", "\n", "|Standard|Available|Not Available|\n", "|---|---|---|\n", "|Chevrolet Infotainment 3 system 1 with 7-inch diagonal color touch-screen, AM/FM stereo, Bluetooth audio streaming 2 for two active devices, voice command pass-through to compatible phone, and Apple CarPlay 3 and Android Auto 4 compatibility| | |\n", "|Chevrolet Infotainment 3 system 1 with 8-inch diagonal color touch-screen, AM/FM stereo, Bluetooth audio streaming 2 for two active devices, voice command pass-through to compatible phone, and Apple CarPlay 3 and Android Auto 4 compatibility| | |\n", "|Chevrolet Infotainment 3 Plus system 1 with 8-inch diagonal HD color touch-screen, AM/FM stereo, Bluetooth audio streaming 2 for two active devices, voice command pass-through to compatible phone, Apple CarPlay 3 and Android Auto 4 compatibility, available Alexa Built-In 5, voice recognition, available In-Vehicle Apps 6 and Chevrolet Maps+ 7|●|●|\n", "|Chevrolet Infotainment 3 Plus system 1 with Navigation 8 and 8-inch diagonal HD color touch-screen, AM/FM stereo, Bluetooth audio streaming 2 for two active devices, voice command pass-through to compatible phone, Apple CarPlay and Android Auto compatibility, available Alexa Built-In, SD card reader, enhanced voice recognition, additional memory for available In-Vehicle Apps 6 and Connected Navigation 9; includes Bose premium 7-speaker sound system; LT includes HD Rear Vision Camera 10 and enhanced multi-color Driver Information Center| |●|●|●|\n", "|Audio system – 6-speaker|●|●|●|●|\n", "|Media – two USB ports and auxiliary input jack in front center floor console|●|●|●|●|\n", "|Media – two USB ports, charge-only, on rear of front center floor console| |●|●|●|\n", "|SiriusXM 12 – 3-month trial subscription|●|●|●|●|\n", "|Available Wi-Fi Hotspot 13 for up to seven devices, includes 1 month of unlimited data (requires available OnStar 14 on WT) 15|●|●|●|●|\n", "|Chevrolet Connected Access with 10 years of standard connectivity, which currently enables features such as Vehicle Diagnostics and Dealer Maintenance Notification (requires available OnStar 14 on WT)|●|●|●|●|\n", "|Wireless charging|●|●| | |\n", "\n", "1 Chevrolet Infotainment System functionality varies by model. Full functionality requires compatible Bluetooth and smartphone, and USB connectivity for some devices.\n", "\n", "2 Go to my.chevrolet.com/learnAbout/bluetooth to find out which phones are compatible with the vehicle. Full Bluetooth feature functionality varies by device, model and software version.\n", "\n", "3 Vehicle user interface is a product of Apple and its terms and privacy statements apply. Requires compatible iPhone and data plan rates apply.\n", "\n", "4 Vehicle user interface is a product of Google and its terms and privacy statements apply. Requires the Android Auto app on Google Play and a compatible Android smartphone. Data plan rates apply. You can check which smartphones are compatible at g.co/androidauto/requirements.\n", "\n", "5 Functionality is subject to limitations and varies by vehicle, infotainment system and location. Select service plan required. Certain Alexa Skills require account linking to use. Visit onstar.com for additional details.\n", "\n", "6 Third-party trademarks are the property of their respective third-party owners and used under agreement. Requires active service plan and paid AT&T vehicle data plan. Visit onstar.com for details and limitations.\n", "\n", "7 U.S. only. Requires select service plan. Functionality is subject to user terms and limitations and varies by vehicle model. Visit onstar.com for details and limitations.\n", "\n", "8 Map coverage available in the United States, Puerto Rico and Canada.\n", "\n", "9 Connected Navigation and Real-time Points of Interest (POI) only available on properly equipped vehicles. Requires paid plan or trial. Map coverage available in the United States, Puerto Rico and Canada. Visit onstar.com for details and limitations.\n", "\n", "10 Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "11 Not compatible with all devices.\n", "\n", "12 If you decide to continue service after your trial, your selected subscription plan will automatically renew thereafter. You will be charged at then-current rates. Fees and taxes apply. To cancel you must call SiriusXM at 1-866-635-2349. See SiriusXM Customer Agreement for complete terms at siriusxm.com. All fees and programming subject to change.\n", "\n", "13 Service varies with conditions and location. Requires active service and paid AT&T data plan. Visit onstar.com for details and limitations. Availability subject to change.\n", "\n", "14 When you select a monthly plan within 30 days of activating your 1-month trial, you’ll receive the next 2 months of the plan you select at no additional charge when you associate an approved payment method on file to your account and authorize recurring payments for your service plan. The amount and frequency of each recurring payment is based upon the service(s) and payment interval(s) you select from the options provided. After the trial expires, OnStar will automatically bill your payment method monthly at then-current standard monthly rates. Plans containing 4G LTE data will be billed every 30 days by AT&T. You may cancel at any time by pushing your blue OnStar button or calling 1-888-466-7827. May not be combined with other offers or retroactively applied. Offer subject to change.\n", "\n", "15 Standard connectivity available only to original purchaser for up to 10 years. Connected Access services are subject to change. Does not include emergency or security services. Diagnostic capabilities vary by model and service plan. Message and data rates may apply. Requires contact method on file and enrollment to receive alerts. Not all issues will deliver alerts. Visit onstar.com for details and limitations.\n", "\n", "16 The system wirelessly charges one compatible mobile device. Some phones have built-in wireless charging technology and others require a special adaptor/back cover. To check for phone or other device compatibility, see my.chevrolet.com/learn or consult your carrier.\n", "---\n", "############ \n", " SPECIFICATIONS\n", "############ \n", " Packages and Special Editions\n", "\n", "| |STANDARD|AVAILABLE|NOT AVAILABLE|\n", "|---|---|---|---|\n", "|Trailering Package|●|●|●|\n", "|Trailer hitch, 7-pin and 4-pin connectors, and Hitch Guidance|1(standard on Crew Cab Long Box models; requires available 3.6L V6 engine and automatic locking rear differential on WT and LT; requires available Duramax 2.8L Turbo-Diesel I-4 engine on LT)| | |\n", "|Custom Special Edition|●|—|—|\n", "|18\" Dark Argent Metallic-painted aluminum wheels, 265/60R18 all-season tires, body-color center grille bar, rear bumper, door handles and mirror caps, and outside rearview mirror with driver spotter mirror (certain vehicles may be built with a painted Black grille bar; see dealer for details)| | | |\n", "|WT Convenience Package|●|—|—|\n", "|Remote Keyless Entry, theft-deterrent system with unauthorized entry, cruise control, and EZ Lift tailgate with power lock and release| | | |\n", "|Chrome Appearance Package|—|●|—|\n", "|Chrome center grille bar, heated power-adjustable manual-folding mirrors with chrome caps, chrome door handles, chrome beltline moldings and chrome rear bumper| | | |\n", "|LT Convenience Package|—|●|—|\n", "|Fog lamps, heated power-adjustable body-color mirrors, remote vehicle starter system and sliding rear window with defogger| | | |\n", "|Luxury Package (Crew Cab)|—|●|—|\n", "|Projector-beam halogen headlamps, driver power lumbar control, heated steering wheel, single-zone automatic climate control and heated front seats (feature will not function on certain models without dealer retrofit; see dealer or window label for details) (requires available LT Convenience Package and leather-appointed front seating surfaces)| | | |\n", "|Redline Edition|—|●|—|\n", "|18\" Black-painted aluminum wheels with Red accents, Black bowtie emblem, Black center grille bar, 3-inch round Black off-road assist steps, Black Out Exterior Trim Package, Black spray-on bedliner and Red recovery hooks 2 (available with Summit White, Satin Steel Metallic or Black exterior colors)| | | |\n", "|Safety Package|—|●|●|\n", "|Forward Collision Alert and Lane Departure Warning; includes Rear Park Assist on LT (feature will not function on certain models without dealer retrofit; see dealer or window label for details)| | | |\n", "|Z71 Midnight Edition|—|—|●|\n", "|Black exterior color, 17\" gloss Black-painted aluminum wheels, Goodyear Wrangler DuraTrac® tires, Z71 door emblem, Black spray-on bedliner, and all-weather floor liner with Chevrolet logo| | | |\n", "\n", "1 Safety or driver assistance features are no substitute for the driver’s responsibility to operate the vehicle in a safe manner. Read the vehicle Owner’s Manual for important feature limitations and information.\n", "\n", "2 To avoid the risk of injury, never use recovery hooks to tow a vehicle. For more information, see the Recovery Hooks section of your Owner’s Manual.\n", "---\n", "############ \n", " SPECIFICATIONS (CONTINUED)\n", "\n", "| |STANDARD|AVAILABLE|NOT AVAILABLE|\n", "|---|---|---|---|\n", "|PACKAGES AND SPECIAL EDITIONS (CONTINUED)| | | |\n", "|ZR2 Bison Edition| | |●|\n", "|17\" AEV-designed aluminum wheels and spare wheel, AEV front bumper with winch provisions and AEV rear bumper with recovery points, AEV hot-stamped boron steel skid plates for front differential, engine oil pan, transfer case, fuel tank and rear differential, AEV fender flares, fog lamps, front and rear floor liners with AEV logo, and AEV embroidered head restraints (available with Summit White, Satin Steel Metallic, Sand Dune Metallic or Black exterior colors)| | | |\n", "|ZR2 Dusk Special Edition| | |●|\n", "|17\" gloss Black-painted aluminum wheels and spare wheel, off-road lights, and sport bar with ZR2 logo| | | |\n", "|ZR2 Midnight Special Edition| | |●|\n", "|Black exterior color, 17\" gloss Black-painted aluminum wheels and spare wheel, off-road lights, and sport bar with ZR2 logo| | | |\n", "\n", "ZR2 Bison Edition (shown with available accessories)\n", "\n", "ZR2 Midnight Special Edition\n", "\n", "ZR2 Dusk Special Edition\n", "\n", "1 Non-GM warranty. See your dealer for limited warranty details.\n", "\n", "Some features shown may have limited, late or no availability. See dealer for feature availability.\n", "---\n", "############ \n", " SPECIFICATIONS\n", "############ \n", " MAXIMUM CAPACITIES\n", "\n", "| |EXTENDED CAB|CREW CAB|\n", "|---|---|---|\n", "|Fuel tank (approximate)|21 gallons|21 gallons|\n", "############ \n", " DIMENSIONS\n", "\n", "| |EXTENDED CAB|CREW CAB|EXTENDED CAB|CREW CAB|EXTENDED CAB|CREW CAB|\n", "|---|---|---|---|---|---|---|\n", "|A - Wheelbase|128.3\"|128.3\" - Short Box|D - Length|212.7\"|212.7\" - Short Box|Head room (front/rear)|41.4\"/36.7\"|41.4\"/38.3\"|\n", "| |128.5\" - ZR2|128.5\" - ZR2| |212.4\" - ZR2|212.7\" - ZR2|Leg room (front/rear)|45.0\"/28.6\"|45.0\"/35.8\"|\n", "| | |140.5\" - Long Box| |224.9\" - Long Box| |Shoulder room|57.5\"/57.3\"|57.5\"/56.2\"|\n", "|B - Height|70.4\" - 2WD|70.7\" - 2WD Short Box|Front track|83.9\"|83.9\"| | | |\n", "| |70.3\" - 4x4|70.6\" - 2WD Long Box|Rear track|62.4\"|62.4\"| | | |\n", "| |72.4\" - ZR2|4x4 Short Box| | | |Hip room (front/rear)|55.0\"/52.2\"|55.0\"/53.3\"|\n", "| | |70.5\" - 4x4 Long Box| | | | | | |\n", "| | |72.5\" - ZR2| | | | | | |\n", "|C - Width| |62.4\"|62.4\"| | | | | | |\n", "| |65.9\" - ZR2|65.9\" - ZR2| | | | | | |\n", "\n", "1 Cargo and load capacity limited by weight and distribution.\n", "---\n", "|ACCESSORIES|\n", "|---|\n", "|All-Weather Floor Liners in Jet Black|4|FV|\n", "|with Chrome Bowtie Logo available Tonneau Cover available from Chevrolet Accessories.|\n", "|COLORado 17\" Gloss Black Aluminum Wheels|\n", "|Off-Road Assist Steps available from Chevrolet Accessories.|\n", "\n", "1 Use only GM-approved wheel/tire combinations. See dealer for details.\n", "---\n", "############ \n", " IMPORTANT INFORMATION\n", "\n", "Every step of the way.\n", "\n", "You may be discovering Chevrolet through a personalized online shopping experience or enjoying every year of vehicle ownership. Either way, we’re committed to providing the tools and programs you need to help you get the most out of your journey.\n", "\n", "GM, the GM logo, Chevrolet, the Chevrolet logo, and the slogans, emblems, vehicle model names, vehicle body designs and other marks appearing in this brochure are the trademarks and/or service marks of General Motors, its subsidiaries, affiliates or licensors.\n", "\n", "©2022 OnStar LLC. All rights reserved.\n", "\n", "Sirius, XM, SiriusXM and all related marks and logos are trademarks of Sirius XM Radio Inc. Amazon, Alexa and all related marks are trademarks of Amazon.com, Inc. or its affiliates. The Bluetooth word mark is a registered trademark owned by Bluetooth SIG, Inc., and any use of such mark by Chevrolet is under license. Bose is a registered trademark of the Bose Corp. Goodyear and Wrangler DuraTrac are registered trademarks of The Goodyear Tire & Rubber Company.\n", "\n", "©2022 General Motors. All rights reserved. October 2022\n", "############ \n", " Build & Price\n", "\n", "Create your perfect Chevrolet from start to finish.\n", "############ \n", " Chevy MyWay\n", "\n", "Engage in a real-time virtual video experience with a Chevy product specialist.\n", "############ \n", " Chevrolet Complete Care\n", "\n", "Enjoy an owner benefit program that provides excellent service and support from day one.\n", "############ \n", " Discover My Chevrolet Rewards\n", "\n", "Unlock a world of appreciation that’s all about you and your Chevrolet. Start earning and redeeming today.\n", "############ \n", " Chevy Truck Legends\n", "\n", "Honoring our dependable, long-lasting trucks and the people who keep them going strong.\n", "############ \n", " Limited Warranty Coverage\n", "\n", "Discover all the ways Chevrolet is committed to providing an excellent ownership experience.\n", "\n", "1 Chevy MyWay is available to anyone over 18 in the United States to access and experience via chevrolet.com/myway. 2 Must be 18 years or older. Points may be earned and redeemed only at GM entities, My Chevrolet Rewards participating dealers or third party retailers in the United States (excluding Puerto Rico, the U.S. Virgin Islands or Guam). Points are not earned on taxes, fees or body shop repair orders and expire without further notice upon Member Account deactivation. Visit myChevroletrewards.com to view My GM Rewards Terms & Conditions.\n", "\n", "Some features shown may have limited, late or no availability. See dealer for feature availability.\n" ] } ], "source": [ "for node in nodes:\n", " print(\"############\", \"\\n\", node.text)" ] }, { "cell_type": "markdown", "metadata": { "id": "cLxoFY9Y1iIv" }, "source": [ "#### Extract FAQs with Gemini\n", "\n", "First we will define a chain to properly prompt an LLM to extract FAQs as a JSON object per node." ] }, { "cell_type": "code", "execution_count": 110, "metadata": { "id": "JfJ_DdvL1hdQ" }, "outputs": [], "source": [ "from langchain import PromptTemplate\n", "from langchain_core.output_parsers import JsonOutputParser\n", "from langchain_core.prompts import PromptTemplate\n", "from langchain_core.pydantic_v1 import BaseModel, Field\n", "from typing import List\n", "\n", "\n", "# Define your desired data structure.\n", "class PromptResponse(BaseModel):\n", " prompt: str = Field(description=\"User input question about information in the document.\")\n", " response: str = Field(description=\"Grounded answer from the LLM pertaining to the user's question.\")\n", "\n", "class FAQs(BaseModel):\n", " pairs: List[PromptResponse] = Field(description=\"List of prompt response pairs extracted from the document\")\n", "\n", "\n", "# Set up a parser + inject instructions into the prompt template.\n", "json_parser = JsonOutputParser(pydantic_object=FAQs)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "id": "5IiIEF1G1wLM" }, "outputs": [], "source": [ "prompt = PromptTemplate(\n", " template=\"\"\"You are a document intelligence tool used to extract FAQs\n", " from portions of a source PDF document. Put yourself in the shoes of a potential\n", " reader of the provided material and anticipate what questions they might have.\n", " Looking at the context below, your goal is to pull out as many likely question\n", " (prompt) and answer (response) pairs as possible, using only what's provided.\n", "\n", " Other Rules:\n", " - Create as many FAQs as possible, even rewording the same question and answer\n", " a few times while remaining faithful to the truth and provided content.\n", " - Ignore heavy marketing or salesly concepts and focus specifically on\n", " factual data.\n", " - It's ok if your response is an empty JSON object for a particular section.\n", "\n", " {format_instructions}\n", "\n", " Document Context:\\n{doc}\\n\"\"\",\n", " input_variables=[\"doc\"],\n", " partial_variables={\"format_instructions\": json_parser.get_format_instructions()},\n", ")\n", "\n", "faq_generator_chain = prompt | llm | json_parser" ] }, { "cell_type": "markdown", "metadata": { "id": "u5lsMVKc2TsF" }, "source": [ "Let's test this out with a sample document from wikipedia first." ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "id": "rKibkgR_2W28" }, "outputs": [], "source": [ "sample_doc = \"\"\"Obi-Wan Kenobi (Ewan McGregor) is a young apprentice Jedi knight\n", "under the tutelage of Qui-Gon Jinn (Liam Neeson) ; Anakin Skywalker (Jake Lloyd),\n", "who will later father Luke Skywalker and become known as Darth Vader, is just\n", "a 9-year-old boy. When the Trade Federation cuts off all routes to the planet\n", "Naboo, Qui-Gon and Obi-Wan are assigned to settle the matter.\"\"\"" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "id": "VAhZYyf22bW9" }, "outputs": [], "source": [ "faqs = faq_generator_chain.invoke({\"doc\": sample_doc})" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "XjsEhdjl2dDj", "outputId": "2f964435-5c52-452b-b148-4e705d4dd1fc" }, "outputs": [ { "data": { "text/plain": [ "{'pairs': [{'prompt': 'Who is Obi-Wan Kenobi?',\n", " 'response': 'Obi-Wan Kenobi is a young apprentice Jedi knight under the tutelage of Qui-Gon Jinn.'},\n", " {'prompt': 'Who is Qui-Gon Jinn?',\n", " 'response': 'Qui-Gon Jinn is a Jedi knight who is the mentor of Obi-Wan Kenobi.'},\n", " {'prompt': 'Who is Anakin Skywalker?',\n", " 'response': 'Anakin Skywalker is a 9-year-old boy who will later father Luke Skywalker and become known as Darth Vader.'},\n", " {'prompt': 'What is the Trade Federation?',\n", " 'response': 'The Trade Federation is a group that cuts off all routes to the planet Naboo.'},\n", " {'prompt': 'What is the mission of Qui-Gon and Obi-Wan?',\n", " 'response': 'Qui-Gon and Obi-Wan are assigned to settle the matter of the Trade Federation cutting off all routes to the planet Naboo.'}]}" ] }, "execution_count": 90, "metadata": {}, "output_type": "execute_result" } ], "source": [ "faqs" ] }, { "cell_type": "markdown", "metadata": { "id": "oSRYapAa4Oue" }, "source": [ "Now we can apply this same logic to nodes from our pdf document." ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "id": "vOSHH6HO4TpV" }, "outputs": [], "source": [ "def extract_faqs(nodes):\n", " all_faqs = []\n", " for i, node in enumerate(nodes):\n", " print(f\"Processing node {i+1} of {len(nodes)}\", flush=True)\n", " results = faq_generator_chain.invoke({\"doc\": node.text})\n", " if results and results.get(\"pairs\"):\n", " all_faqs.extend(results[\"pairs\"])\n", " return all_faqs" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "vIepVu60Jmcq", "outputId": "42bd5864-2d2d-4ba2-ea44-a1c2f04ef967" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing node 1 of 39\n", "Processing node 2 of 39\n", "Processing node 3 of 39\n", "Processing node 4 of 39\n", "Processing node 5 of 39\n", "Processing node 6 of 39\n", "Processing node 7 of 39\n", "Processing node 8 of 39\n", "Processing node 9 of 39\n", "Processing node 10 of 39\n", "Processing node 11 of 39\n", "Processing node 12 of 39\n", "Processing node 13 of 39\n", "Processing node 14 of 39\n", "Processing node 15 of 39\n", "Processing node 16 of 39\n", "Processing node 17 of 39\n", "Processing node 18 of 39\n", "Processing node 19 of 39\n", "Processing node 20 of 39\n", "Processing node 21 of 39\n", "Processing node 22 of 39\n", "Processing node 23 of 39\n", "Processing node 24 of 39\n", "Processing node 25 of 39\n", "Processing node 26 of 39\n", "Processing node 27 of 39\n", "Processing node 28 of 39\n", "Processing node 29 of 39\n", "Processing node 30 of 39\n", "Processing node 31 of 39\n", "Processing node 32 of 39\n", "Processing node 33 of 39\n", "Processing node 34 of 39\n", "Processing node 35 of 39\n", "Processing node 36 of 39\n", "Processing node 37 of 39\n", "Processing node 38 of 39\n", "Processing node 39 of 39\n" ] } ], "source": [ "all_faqs = extract_faqs(nodes)" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "IhTEt-2HO-cz", "outputId": "9a7489f7-e3f8-47bb-ba4b-1dbcb80c20d1" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Generated 329 frequently asked questions.\n" ] } ], "source": [ "print(\"Generated\", len(all_faqs), \"frequently asked questions.\")" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "-LBrSPkJKhV-", "outputId": "7a59c6d0-fbc1-4ce6-de83-224f2e965c84" }, "outputs": [ { "data": { "text/plain": [ "[{'prompt': 'What are the engine choices for the 2022 Colorado?',\n", " 'response': 'The 2022 Colorado offers a variety of engine choices, including a GM-exclusive Duramax® 2.8L Turbo-Diesel engine that provides up to 7,700 lbs. of towing muscle.'},\n", " {'prompt': 'What is the maximum towing capacity of the 2022 Colorado?',\n", " 'response': 'The maximum towing capacity of the 2022 Colorado is 7,700 lbs. This is for the Colorado Crew Cab Short Box LT 2WD with available Trailering Package, LT Convenience Package and Safety Package.'},\n", " {'prompt': 'What are some of the off-road features of the 2022 Colorado?',\n", " 'response': 'The 2022 Colorado ZR2 is an off-road beast with the capability to conquer tough trails.'},\n", " {'prompt': 'What are some of the interior features of the 2022 Colorado?',\n", " 'response': 'The 2022 Colorado has a comfortable interior filled with convenience and technology features.'},\n", " {'prompt': 'What is the availability of certain features on the 2022 Colorado?',\n", " 'response': 'Due to current supply chain shortages, certain features shown have limited or late availability, or are no longer available. See the window label or a dealer regarding the features on an individual vehicle.'},\n", " {'prompt': 'What is the topic of the document?',\n", " 'response': 'The document is about Colorado.'},\n", " {'prompt': 'What is the document about?',\n", " 'response': 'The document is about Colorado.'},\n", " {'prompt': 'What is the document?',\n", " 'response': 'The document is an introduction to Colorado.'},\n", " {'prompt': 'What does the document introduce?',\n", " 'response': 'The document introduces Colorado.'},\n", " {'prompt': 'What is the main focus of the document?',\n", " 'response': 'The main focus of the document is Colorado.'}]" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "all_faqs[:10]" ] }, { "cell_type": "markdown", "metadata": { "id": "JaZe-6xILHPS" }, "source": [ "#### Index FAQs into Redis\n", "\n", "Now we will create embeddings of each prompt and load them into Redis for our semantic cache." ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "OETsrYvfuzmX", "outputId": "da469dda-f4ca-45f1-e10d-7ef6fc31b65b" }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Embed each chunk content using the vertex AI vectorizer\n", "embeddings = vectorizer.embed_many([pair[\"prompt\"] for pair in all_faqs])\n", "\n", "# Check to make sure we've created enough embeddings, 1 per FAQ record\n", "len(embeddings) == len(all_faqs)" ] }, { "cell_type": "code", "execution_count": 96, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "9mNa5LNn4XpX", "outputId": "24b1da53-87d5-43a7-9d73-135d42a6ea11" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "17:41:42 redisvl.index.index INFO Index already exists, not overwriting.\n" ] } ], "source": [ "from redisvl.extensions.cache.llm import SemanticCache\n", "\n", "cache = SemanticCache(vectorizer=vectorizer, distance_threshold=0.2)" ] }, { "cell_type": "code", "execution_count": 97, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "ZEFgLbaCLWmF", "outputId": "a995205f-72be-4a91-8b62-f6263b43f567" }, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cache.check(\"testing\") # cache should be empty" ] }, { "cell_type": "code", "execution_count": 98, "metadata": { "id": "cNjHD3D94_Sc" }, "outputs": [], "source": [ "for i, entry in enumerate(all_faqs):\n", " cache.store(prompt=entry[\"prompt\"], response=entry[\"response\"], vector=embeddings[i])" ] }, { "cell_type": "markdown", "metadata": { "id": "IDtXfaB8MCAx" }, "source": [ "#### Example queries" ] }, { "cell_type": "code", "execution_count": 99, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "lgneMQDDMEhd", "outputId": "8607536d-c6bd-4157-8e20-4f07e62ec76e" }, "outputs": [ { "data": { "text/plain": [ "[{'id': 'llmcache:2c9593e34f4f4b71508cb81d3e22e4b85dfda747add6f5fef3231e61d62f4015',\n", " 'vector_distance': '0.100723683834',\n", " 'prompt': 'How many models of the Colorado are there?',\n", " 'response': 'There are four models of the Colorado: WT, LT, Z71, and ZR2.',\n", " 'prompt_vector': '&\\x15uu.J#>\\x0fe\\x07\\x14=Jٛ=mX\";\\x7fGX=09=:N[=7$7<1}\\x17<|?W=L/\\x08=\\x00 \\x0e;w\\x1fۼZ;!\\t;-d<\\x0c=\\x0b;zg\\x100_M\\x0e$$;V\\x0bp;6=a;=y Aڤ<\\x147KἜ¼U$\\x03\\x1f<\\x1c̻h(=\\r]-Eμ\\x1c&Ift*2;i5\\x1cۼTfj06W\\x18\\x14<,=Pb\\x14=$<>musʼ\\ni=ц<\\x10;:AݢnX=\\x03\\x1b=лY9<\\x0evB\\x11<\\x1b=\\x00=h\\x14:\";=;d\\x19\\x17=L<\\x00+\\x1bc=XOnI:)