Integrations

Integrate Redis for Enhanced AI Chat Context

Use Redis as a vector database to provide external context to AI chat models, overcoming knowledge cutoffs and improving response quality.

Without it

Piece it together by hand, every time.

With it

Leverage Redis as a high-speed context memory to augment AI chat capabilities, enabling more informed responses on topics beyond the model's knowledge cutoff.

What you get

  • Set up Redis with Search and JSON modules for vector storage.
  • Index external data into Redis for retrieval.
  • Embed user queries and perform vector similarity search in Redis.
  • Incorporate retrieved context into OpenAI chat prompts for improved accuracy.

Use this prompt chain

OpenAI Cookbook Query a databaseRAG indexChatbotKnowledge graph

Redis as a Context Store with OpenAI Chat

This notebook demonstrates how to use Redis as high-speed context memory with ChatGPT.

Prerequisites

  • Redis instance with the Redis Search and Redis JSON modules
  • Redis-py client lib
  • OpenAI Python client lib
  • OpenAI API key

Installation

Install Python modules necessary for the examples.

OpenAI API Key

Create a .env file and add your OpenAI key to it

OpenAI Setup

Key load + helper function for chat completion

Experiment - Chat Completion on a Topic outside of the Model's Knowledge Cutoff Date

Gpt-3.5-turbo was trained on data up to Sep 2021. Let's ask it a question about something that is beyond that date. In this case, the FTX/Sam Bankman-Fried scandal. We are using an old model here for demonstration. Newer models such as got-4o has later knowledge cutoffs (late 2023) and will work here as well.

Incomplete Information

An unfortunate behavior of these AI systems is the system will provide a confident-sounding response - even when the system is not confident with its result. One way to mitigate this is prompt re-engineering, as seen below.

Additional Context

Another way to combat incomplete information is to give the system more information such that it can make intelligent decisions vs guessing. We'll use Redis as the source for that additional context. We'll pull in business news articles from after the GPT knowledge cut-off date such that the system will have a better understanding of how FTX was actually managed.

Start the Redis Stack Docker container

Connect Redis client

Create Index

FT.CREATE

Load Data Files into Redis as JSON Objects with Text and Vector Fields

Redis JSON

Embed the Question and Perform VSS to find the most relevant document

KNN Search

Repeat the Question to OpenAI with context

Now that we have relevant context, add that to the prompt to OpenAI and get a very different response.

Comments (0)

Sign In Sign in to leave a comment.