Jumpstart your integration with RAG-Buddy in proxy mode, designed to enhance your existing RAG setup with minimal effort. This Quickstart is tailored for a swift and straightforward experience, enabling you to witness the improvements RAG-Buddy brings to your system promptly. For alternative configurations and detailed instructions, our comprehensive Guidebook is available.

The Quickstart below is designed to get you up and running with RAG-Buddy in the shortest time possible. We do however recommend that you use the REST API version of RAG-Buddy. It is more reliable and offers additional advantages over the method described below. That having said, please do follow the quickstart below to get a feel of how RAG-Buddy works with a minimum of effort.

Assumptions

This Quickstart assumes the following prerequisites are met:

  • You have an active OpenAI API key. If you do not possess one, please obtain it from OpenAI.
  • You are using the OpenAI Python client. Installation and setup instructions can be found in the repository.
  • Your use case is:
    1. RAG with the generation of a single citation within the response, or
    2. Text Classification

If your setup or requirements differ from the above, please consult our Guidebook for a path tailored to your needs.

Create a Project

To begin using RAG-Buddy, a new project must be created. If you haven’t set up a project yet, follow these steps:

  1. Visit the console at RAG-Buddy Console and sign up for an account if you don’t already have one.

  2. Once you’re signed in:

    • On your Console, click [Create a new project].
    • Name your project.
    • Select OpenAI:ADA2 as your embedding model.
    • Select OpenAI Chat Completions API as your LLM provider.
    • Select the RAG+Citation or the Text-Classification option.
    • Click Create Project to create your project.
  3. Next, you’ll need an API key for your cache:

    • Navigate to the Services tab.
    • Scroll down to the API Keys for Cache section.
    • Click on Create new key.
    • Assign a name to your key and select Create API Key.
    • Copy the newly generated API key for use in the next step.

Integrate RAG-Buddy

Here we demonstrate how to integrate RAG-Buddy into your existing LLM Pipeline. As this is the Quickstart guide we will create the most basic and most effortless integration possible, with the Proxy Endpoint for the RAG+Citation use case. For more advanced configurations, please refer to our Guidebook.

For the Text-Classification use case please refer to the Proxy Endpoint in the Guidebook. All instructions up until here in the Quickstart are applicable for all use cases. Below we continue with the RAG+Citation use case exclusively.

Using the OpenAI API in a RAG+C Context

In this section, we demonstrate a typical use case of the OpenAI API within a Retriever-Augmented Generation with Citation (RAG+C) context. The focus is on leveraging articles as contextual information to enhance the response quality in a customer support scenario. We start by showcasing a standard OpenAI API call, where the system is fed with a set of pre-selected articles related to banking services. These articles provide the necessary context for the AI to understand and respond accurately to user queries.

Code Example:

Typical RAG+C OpenAI API call
import openai

# Your OpenAI API key
openai_api_key = "sk-abc123" # Replace with your actual API key

# System messages
system_intro = "You are a customer support agent of the e-banking application called Piggy Bank Extraordinaire."
system_instructions = """Select the best article to reply to the question of the user below.
If you can find the answer in the articles listed below, then:
You MUST select exactly one article from the listed articles.
You MUST add the ID of the selected article at the start of your answer in the format "(ID:number) your answer", For example: (ID:1) your answer.
You MUST provide a short summarized answer.
If you cannot find the answer in the list of articles below, then:
You MUST say "(ID:None) I cannot answer this" and MUST say nothing more.
"""

# Articles
chosen_articles = """
## ID:123e4567-e89b-12d3-a456-426655440000    Interest Rates on Piggy Bank Extraordinaire's Savings Accounts
At Piggy Bank Extraordinaire, we understand the importance of saving for your future. That's why our Gold Plus Savings Account offers a competitive interest rate of 2.6% per annum, ensuring your savings grow steadily over time. For those seeking more flexibility, our Silver Flexi Savings Account provides an interest rate of 1.8% per annum, with the added benefit of no minimum balance requirement. Our Bronze Everyday Savings Account is perfect for daily transactions, offering a 1.2% interest rate per annum. With Piggy Bank Extraordinaire, you can choose the savings account that best suits your financial goals and lifestyle.

## ID:123e4567-e89b-12d3-a456-426655440001    Comparing Interest Rates: Piggy Bank Extraordinaire vs. Other Banks
When it comes to choosing a bank for your savings, interest rates play a crucial role. Piggy Bank Extraordinaire stands out with its competitive rates. Our Gold Plus Savings Account offers an interest rate of 2.6% per annum, significantly higher than the industry average of 2.0%. In comparison, Big Bank offers 2.2% on its equivalent account, and Global Trust offers 2.1%. Furthermore, Piggy Bank Extraordinaire's Silver Flexi and Bronze Everyday accounts also outperform their counterparts at other banks, offering higher returns on your deposits. With Piggy Bank Extraordinaire, you can be assured of getting one of the best rates in the market for your savings.

## ID:123e4567-e89b-12d3-a456-426655440002    Understanding Fixed Deposit Interest Rates at Piggy Bank Extraordinaire
Fixed Deposits at Piggy Bank Extraordinaire are an excellent way to earn higher interest on your savings. Our Fixed Deposit accounts offer various tenures ranging from 6 months to 5 years, with interest rates varying accordingly. For a 6-month deposit, enjoy an interest rate of 2.0% per annum. The rate increases to 2.5% for a 1-year term and peaks at 3.5% for a 5-year term. These rates are designed to reward longer commitments with higher returns. Our Fixed Deposits are perfect for customers who wish to lock in their savings for a fixed period to earn a guaranteed return without the risks associated with market fluctuations.
"""

# User query (can be replaced with any relevant question)
user_query = "What are the interest rates for the Gold Plus Savings Account?"

# Format the template
template = f"{system_intro}\n\nINSTRUCTIONS:\n{system_instructions}\n\nARTICLES:\n{chosen_articles}\n\n"

# Initialize OpenAI client
client = openai.OpenAI(
    api_key=openai_api_key,
    timeout=10,
)

# Prepare the messages
messages = [
    {
        "role": "system",
        "content": template,
    },
    {"role": "user", "content": user_query},
]

# Call OpenAI API
completion = client.chat.completions.create(
    model="gpt-4",  # Replace with the specific model name
    messages=messages,
)

# Read the response
response = completion.choices[0].message
print(response.content)

Open this code example in a notebook: Colab notebook

Transitioning to RAG-Buddy Usage

To further enhance the efficiency and relevance of responses, we integrate the RAG-Buddy services. RAG-Buddy acts as a proxy, caching user queries and selected articles, reducing the context size sent to the LLM. To utilize RAG-Buddy, just a few modifications in the existing code are necessary:

  1. Set the base URL to the RAG-Buddy Proxy Endpoint: Modify the base_url parameter to point to the RAG-Buddy Proxy Endpoint:

base_url = "https://api.ragbuddy.ai/proxy/ragc/v1"

This directs the API calls to the RAG-Buddy Proxy instead of directly to OpenAI.

  1. Add the RAG-Buddy Key as a Header: Incorporate the RAG-Buddy key into the headers for authentication and tracking purposes. Your headers configuration will look like this:

headers = {"Helvia-RAG-Buddy-Token": "your-rag-buddy-key"}

Replace “your-rag-buddy-key” with the actual key provided during your project setup.

By making these changes, your API calls will now be routed through the RAG-Buddy proxy, leveraging its caching capabilities for decreasing the context size.

Complete Code with RAG-Buddy Integration:

RAG-Buddy RAG+C Integration
import openai

# Your OpenAI API key
openai_api_key = "sk-abc123" # Replace with your actual API key

# Your RAG Buddy key
rag_buddy_key = "RAG_CA_abc123" # Replace with your actual RAG Buddy key

# Needed for RAG Cache integration
base_url = "https://api.ragbuddy.ai/proxy/ragc/v1"
headers = {"Helvia-RAG-Buddy-Token": rag_buddy_key}

# System messages
system_intro = "You are a customer support agent of the e-banking application called Piggy Bank Extraordinaire."
system_instructions = """Select the best article to reply to the question of the user below.
If you can find the answer in the articles listed below, then:
You MUST select exactly one article from the listed articles.
You MUST add the ID of the selected article at the start of your answer in the format "(ID:number) your answer", For example: (ID:1) your answer.
You MUST provide a short summarized answer.
If you cannot find the answer in the list of articles below, then:
You MUST say "(ID:None) I cannot answer this" and MUST say nothing more.
"""

# Articles
chosen_articles = """
## ID:123e4567-e89b-12d3-a456-426655440000    Interest Rates on Piggy Bank Extraordinaire's Savings Accounts
At Piggy Bank Extraordinaire, we understand the importance of saving for your future. That's why our Gold Plus Savings Account offers a competitive interest rate of 2.6% per annum, ensuring your savings grow steadily over time. For those seeking more flexibility, our Silver Flexi Savings Account provides an interest rate of 1.8% per annum, with the added benefit of no minimum balance requirement. Our Bronze Everyday Savings Account is perfect for daily transactions, offering a 1.2% interest rate per annum. With Piggy Bank Extraordinaire, you can choose the savings account that best suits your financial goals and lifestyle.

## ID:123e4567-e89b-12d3-a456-426655440001    Comparing Interest Rates: Piggy Bank Extraordinaire vs. Other Banks
When it comes to choosing a bank for your savings, interest rates play a crucial role. Piggy Bank Extraordinaire stands out with its competitive rates. Our Gold Plus Savings Account offers an interest rate of 2.6% per annum, significantly higher than the industry average of 2.0%. In comparison, Big Bank offers 2.2% on its equivalent account, and Global Trust offers 2.1%. Furthermore, Piggy Bank Extraordinaire's Silver Flexi and Bronze Everyday accounts also outperform their counterparts at other banks, offering higher returns on your deposits. With Piggy Bank Extraordinaire, you can be assured of getting one of the best rates in the market for your savings.

## ID:123e4567-e89b-12d3-a456-426655440002    Understanding Fixed Deposit Interest Rates at Piggy Bank Extraordinaire
Fixed Deposits at Piggy Bank Extraordinaire are an excellent way to earn higher interest on your savings. Our Fixed Deposit accounts offer various tenures ranging from 6 months to 5 years, with interest rates varying accordingly. For a 6-month deposit, enjoy an interest rate of 2.0% per annum. The rate increases to 2.5% for a 1-year term and peaks at 3.5% for a 5-year term. These rates are designed to reward longer commitments with higher returns. Our Fixed Deposits are perfect for customers who wish to lock in their savings for a fixed period to earn a guaranteed return without the risks associated with market fluctuations.
"""

# User query (can be replaced with any relevant question)
user_query = "What are the interest rates for the Gold Plus Savings Account?"

# Format the template
template = f"{system_intro}\n\nINSTRUCTIONS:\n{system_instructions}\n\nARTICLES:\n{chosen_articles}\n\n"

# Initialize OpenAI client
client = openai.OpenAI(
    api_key=openai_api_key,
    timeout=10,
    default_headers=headers,
    base_url=base_url,
)

# Prepare the messages
messages = [
    {
        "role": "system",
        "content": template,
    },
    {"role": "user", "content": user_query},
]

# Call OpenAI API
completion = client.chat.completions.create(
    model="gpt-4",  # Replace with the specific model name
    messages=messages,
)

# Read the response
response = completion.choices[0].message
print(response.content)

Open this code example in a notebook: Colab notebook

What’s Next?

This quickstart guide is designed to get you up and running with RAG-Buddy in the shortest time possible. For more advanced configurations and detailed instructions, please refer to our Guidebook where you can:

  • Add cache control
  • Inspect the response header for cache hit information
  • Use the REST API instead of this proxy setup
  • Integrate for different use cases
  • And more…