Repository: truera/trulens
Issue: Generate TruLens eval report of generated Question answer context pairs.
Root cause: Documentation Deficiency

I have used Mixtral and mistral models for 1000 sampled questions. using RAG pipeline from Llama index have retrieved contexts and generated answer for these 1k questions. 
Is it possible to evaluate RAG Triage metric for this existing data frame of questions context and answer columns using GPT 3.5 as an evaluator? 

Hey @prasad4fun ! Definitely. Check out these [docs](https://www.trulens.org/trulens_eval/feedback_functions_existing_data/) for running on existing data

> Hey @prasad4fun ! Definitely. Check out these [docs](https://www.trulens.org/trulens_eval/feedback_functions_existing_data/) for running on existing data

I already have the questions and the context retrieved by RAG. Can I directly use Trulens for evaluation? Where can I find the documentation? I see that the document link you provided above is no longer valid.

Hi @kmr666 - those docs have moved [here](https://www.trulens.org/trulens_eval/evaluation/running_feedback_functions/existing_data/)

> Hi @kmr666 - those docs have moved [here](https://www.trulens.org/trulens_eval/evaluation/running_feedback_functions/existing_data/)

Hello, thank you very much for your reply and help. I have another question to consult you with. I already have a database with multiple entries of question, context, and answer. However, my context is given in the form of a nested array, such as [[], [], []). Do I need to expand the content in the context into a list containing a string? Or is there another method? Could you tell me how to input my own data? Thank you very much.


Not sure if I am getting your data right, please let me know and share a sample data frame if not.

You can load data like this:

```python
import pandas as pd

data = {
    'prompt': ['Where is Germany?', 'What is the capital of France?'],
    'response': ['Germany is in Europe', 'The capital of France is Paris'],
    'context': [['Germany is a country located in Europe',
                 'Germany lies between the Baltic and North Sea to the North and Alps to the South'], ['France is a country in Europe and its capital is Paris.',
                'Paris is the capital of France']]
}
df = pd.DataFrame(data)
```

Into TruLens virtual records like this:

```python
from trulens_eval.tru_virtual import VirtualRecord
data_dict = df.to_dict('records')

data = []

for record in data_dict:
    rec = VirtualRecord(
        main_input=record['prompt'],
        main_output=record['response'],
        calls=
            {
                context_call: dict(
                    args=[record['prompt']],
                    rets=record['context']
                )
            }
        )
    data.append(rec)

from trulens_eval.tru_virtual import TruVirtual

virtual_recorder = TruVirtual(
    app_id="a virtual app",
    app=virtual_app)

for record in data:
    virtual_recorder.add_record(record)
```

Once you've done this, you can then see your app represented in the TruLens dashboard.

![Screenshot 2024-07-11 at 10 22 26 AM](https://github.com/truera/trulens/assets/171636836/a481aab4-b5bb-4b40-8986-01ea4247b7c8)

And see both retrieved context if you click on the `get_context` span.

![Screenshot 2024-07-11 at 10 22 18 AM](https://github.com/truera/trulens/assets/171636836/04c66efd-1c35-43d6-bf9f-9ecccaad7551)

The beauty of this approach is that it can be set up to mirror any arbitrary app structure. Let me know if you have more questions on this.

> Not sure if I am getting your data right, please let me know and share a sample data frame if not.
> 
> You can load data like this:
> 
> ```python
> import pandas as pd
> 
> data = {
>     'prompt': ['Where is Germany?', 'What is the capital of France?'],
>     'response': ['Germany is in Europe', 'The capital of France is Paris'],
>     'context': [['Germany is a country located in Europe',
>                  'Germany lies between the Baltic and North Sea to the North and Alps to the South'], ['France is a country in Europe and its capital is Paris.',
>                 'Paris is the capital of France']]
> }
> df = pd.DataFrame(data)
> ```
> 
> Into TruLens virtual records like this:
> 
> ```python
> from trulens_eval.tru_virtual import VirtualRecord
> data_dict = df.to_dict('records')
> 
> data = []
> 
> for record in data_dict:
>     rec = VirtualRecord(
>         main_input=record['prompt'],
>         main_output=record['response'],
>         calls=
>             {
>                 context_call: dict(
>                     args=[record['prompt']],
>                     rets=record['context']
>                 )
>             }
>         )
>     data.append(rec)
> 
> from trulens_eval.tru_virtual import TruVirtual
> 
> virtual_recorder = TruVirtual(
>     app_id="a virtual app",
>     app=virtual_app)
> 
> for record in data:
>     virtual_recorder.add_record(record)
> ```
> 
> Once you've done this, you can then see your app represented in the TruLens dashboard.
> 
> ![Screenshot 2024-07-11 at 10 22 26 AM](https://private-user-images.githubusercontent.com/171636836/347857784-a481aab4-b5bb-4b40-8986-01ea4247b7c8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEwMDY4OTksIm5iZiI6MTcyMTAwNjU5OSwicGF0aCI6Ii8xNzE2MzY4MzYvMzQ3ODU3Nzg0LWE0ODFhYWI0LWI1YmItNGI0MC04OTg2LTAxZWE0MjQ3YjdjOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxNVQwMTIzMTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kNmY2YjY0OWZkYzJiMWZlNjIwNzc4ZWM5M2I0N2E4MDZmMWJmMDVkNWI1MDE5NjVjM2JjNzE1ZmI5ZjkxYWIxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.KeoK0ONj8yxSAmrESwp6sbWC77cl8F68Qr09sRogPy8)
> 
> And see both retrieved context if you click on the `get_context` span.
> 
> ![Screenshot 2024-07-11 at 10 22 18 AM](https://private-user-images.githubusercontent.com/171636836/347857817-04c66efd-1c35-43d6-bf9f-9ecccaad7551.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEwMDY4OTksIm5iZiI6MTcyMTAwNjU5OSwicGF0aCI6Ii8xNzE2MzY4MzYvMzQ3ODU3ODE3LTA0YzY2ZWZkLTFjMzUtNDNkNi1iZjlmLTllY2NjYWFkNzU1MS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxNVQwMTIzMTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNjM4Nzc2NGYzNWQyOTBlNzI0Nzc4NmVkOTliZTBiNjllOWJjM2QzNjNmZWU1NGJhN2ZiYTNkZDA0OWUxZGJlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.gWCiOdafu50kBh4RvXhkKpoWGkf5OekoS0bq96MlT34)
> 
> The beauty of this approach is that it can be set up to mirror any arbitrary app structure. Let me know if you have more questions on this.

Hello, thank you very much for your answers and help. My data is stored in a CSV file with three columns: question, context, and answer. The content is in Chinese text, and the data format is as follows:

data_samples = {
'question': ['xxx', 'xxx'],
'response': ['xxx', 'xxx'],
'contexts': [['xxx'],
['xxx']],
}
Here is a data instance as follows:
![image](https://github.com/user-attachments/assets/07c1aee4-a1f5-444b-9cb2-56d361d457ba)

Can you tell me if it's possible to use TruLens to evaluate an existing dataset of this type? Thank you very much, I look forward to your reply!

TruLens would be a good fit for this because of its wide model support. I would recommend exploring LLMs to use as providers that have good Chinese language support.

If you encounter issues because of the prompting is in English, you can also use [custom feedback functions](https://www.trulens.org/trulens_eval/evaluation/feedback_implementations/custom_feedback_functions/) and translate the feedback prompts to Chinese.

> TruLens would be a good fit for this because of its wide model support. I would recommend exploring LLMs to use as providers that have good Chinese language support.
> 
> If you encounter issues because of the prompting is in English, you can also use [custom feedback functions](https://www.trulens.org/trulens_eval/evaluation/feedback_implementations/custom_feedback_functions/) and translate the feedback prompts to Chinese.

Thank you for your help. I have another problem that I hope can get your help. When I was evaluating my own data, the background could not display Trace details, and I could not see the corresponding context information added.
![image](https://github.com/user-attachments/assets/2e7c151c-2a10-4675-85f9-5884e2b8fb76)
My code is as follows:
```
for record in data_dict:
    rec = VirtualRecord(
        main_input=record['prompt'],
        main_output=record['response'],
        calls=
            {
                context_call: dict(
                    args=[record['prompt']],
                    rets=record['context']
                )
            }
        )
    data.append(rec)
context = context_call.rets[:]

# Question/statement relevance between question and each context chunk.
f_context_relevance = (
    Feedback(fopenai.context_relevance)
    .on_input()
    .on(context)
)

from trulens_eval.tru_virtual import TruVirtual

virtual_recorder = TruVirtual(
    app_id="a virtual app",
    app=virtual_app,
    feedbacks=[f_context_relevance]
)


for rec in data:
    virtual_recorder.add_record(rec)
# Retrieve feedback results. You can either browse the dashboard or retrieve the
# results from the record after it has been `add_record`ed.

for rec in data:
    print(rec.main_input, "-->", rec.main_output, )

    for feedback, feedback_result in rec.wait_for_feedback_results().items():
        print("\t", feedback.name, feedback_result.result)
        
    print('finish')
```

response in my own dataset is currently null.
How can I see the full data, including Trace details, as you have shown above?