Skip to content

How to use the RAG Collection in Python code #13

@MaxaAI

Description

@MaxaAI

I tryed using Rag Collection in the Python Code but couldn't figure out how to make it inside of the code

import gradientai
import os
from gradientai import Gradient

os.environ['GRADIENT_ACCESS_TOKEN'] = ""
os.environ['GRADIENT_WORKSPACE_ID'] =""

Initialize your Gradient instance

gradient = Gradient()

Initialize your Gradient instance

gradient = Gradient()

def run_answer_example_with_rag_collection(*, gradient: Gradient) -> None:
question = "What is Mprofy?"

print("==== Q & A ====")
print(f"Question: {question}\n")

print("Answering question using RAG collection...")
try:
    # Assuming the RAG Collection ID is passed as a separate parameter, 
    # which is not shown in the documentation snippet provided.
    result = gradient.answer(
        question=question,
        RAG_Collections="Rag collection Id"  # Speculative parameter
    )

    print(f"Answer: {result['answer']}")
except TypeError as e:
    print(f"An error occurred: {e}")
print("================\n")

Run the function

run_answer_example_with_rag_collection(gradient=gradient)

This is the code i have tryed but i couldn't bring it working

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions