Skip to main content

Implementing Retrieval Augmented Generation with OpenAI and TakeShape

warning

TakeShape's vector search related features are considered experimental. Use in production with the knowledge that these features may change.

tip

The best way to get started with RAG is to try our RAG example project which has a detailed setup guide.

Introduction

Retrieval augmented generation (RAG) is a technique that combines information retrieval and language generation to create more accurate, relevant, and contextually aware responses. It involves retrieving relevant information from a knowledge base or corpus and using that information to guide the generation process of a language model like OpenAI's GPT-3.

Benefits of using RAG:

  • Improved accuracy: By leveraging relevant information from a knowledge base, RAG can produce more accurate and factually correct responses.
  • Enhanced relevance: The retrieved information helps to generate responses that are more relevant to the user's query or context.
  • Increased efficiency: RAG can help to reduce the reliance on large-scale pretraining and fine-tuning of language models, making the generation process more efficient.
  • Contextual awareness: By incorporating retrieved information, the generated responses can be more contextually aware and aligned with the user's intent.

RAG Example Project

This example demonstrates how to use TakeShape's vector capabilities combined with indexing to enable the RAG use-case. A prerequisite for RAG is to populate a vector database, for this example we will use TakeShape's built-in index. The first step to preparing our data is to extend Shopify_Product with a vector property that contains an embedding created by OpenAI. Once we have a our extended Shopify_Product we can use API Indexing to iterate over every product and store the combined data in our index:

This combined Shopify_Product will be kept up to date by listening to Shopify webhooks and will be fully re-indexed every 24hrs.

Now that our Shopify_Product data is stored in the built-in index we can perform RAG:

Check out the RAG example project repo for more information.