Skip to main content
This is an interactive notebook. You can run it locally or use the following links:

Import traces from third-party systems

This notebook shows you how to import historical conversation traces from a CSV file into W&B Weave so you can analyze them, compare model behavior, and run evaluations on data that was generated outside of a Weave-instrumented application. Sometimes you can’t instrument your Python or JavaScript code with the Weave integration to obtain real-time traces of your GenAI application. Often, these traces are available to you later in CSV or JSON format. This notebook uses the lower-level Weave Python API to extract data from a CSV file and import it into Weave so you can analyze and evaluate it. The sample dataset assumed in this cookbook has the following structure:
To understand the decisions for import in this notebook, remember that Weave traces have parent-child relationships that are 1:Many and continuous. A single parent can have multiple children, and that parent can itself be a child of another parent. This notebook uses conversation_id as the parent identifier and turn_index as the child identifier to provide complete conversation logging. You must modify the variables in the following sections to match your own dataset, file paths, and W&B project.

Set up the environment

Install and import all needed packages. Set WANDB_API_KEY in your environment so that you can log in with wandb.login() (provide this to Colab as a secret). Set the name of the file you upload to Colab in name_of_file, and set the W&B project you want to log into in name_of_wandb_project.
name_of_wandb_project can also be in the format [TEAM_NAME]/[PROJECT_NAME] to specify a team to log the traces into.
Then, fetch a Weave client by calling weave.init().

Load the data

With the environment ready, you can load and shape the CSV data so that it matches the parent-child structure that Weave expects. Load the data into a pandas DataFrame, and sort it by conversation_id and turn_index to ensure the parents and children are correctly ordered. This results in a two-column pandas DataFrame with the conversation turns as an array under conversation_data.

Log the traces to Weave

With the data shaped into conversations and turns, the next step is to write those records into Weave as parent and child calls. Iterate through the pandas DataFrame:
  • Create a parent call for every conversation_id.
  • Iterate through the turn array to create child calls sorted by their turn_index.
Important concepts of the lower-level Python API:
  • A Weave call is equivalent to a Weave trace. This call can have a parent or children associated with it.
  • A Weave call can have other things associated with it, such as feedback and metadata. This example only associates inputs and outputs, but you can add these other items in your import if the data provides them.
  • A Weave call is created and finished because these are meant to be tracked in real time. Because this is an after-the-fact import, you create and finish once the objects are defined and tied to one another.
  • The op value of a call is how Weave categorizes calls of the same makeup. In this example, all parent calls are of Conversation type, and all child calls are of Turn type. You can modify this as you see fit.
  • A call can have inputs and output. inputs are defined at creation, and output is defined when the call is finished.

Result: traces logged to Weave

At this point, your CSV data has been imported into Weave. You can now browse the conversations and their turns in the Weave UI, grouped under the Conversation and Turn operations you defined. Traces:
Imported conversation traces in the Weave UI
Operations:
Conversation and Turn operations in the Weave UI

Optional: export your traces to run evaluations

Once the traces are in Weave and you understand how the conversations look, you can export them to another process to run Weave Evaluations.
Exporting traces from a Weave project
To do this, fetch all conversations from W&B through the query API and create a dataset from them.

Result

The exported dataset is now published back to Weave and is ready to use as input for an evaluation.
Published dataset in the Weave UI, ready for use in an evaluation
To learn more about evaluations, see the Quickstart on using your newly created dataset to evaluate your RAG application.