Options for Exporting Data from Phoenix
Connect to Phoenix
Point your code at the Phoenix instance you started. The endpoint below is the default for a localphoenix serve; for a deployment running elsewhere, use its hostname instead.
Downloading all Spans as a Dataframe
If you prefer to handle your filtering locally, you can also download all spans as a dataframe using theget_spans_dataframe() method:
Running Span Queries
You can query for data using our query DSL (domain specific language).The
.where() filter expression is the same language used by the filter bar in the dashboard — see the Filter Expressions reference for the full language. It can be helpful to form your filter in the Phoenix dashboard for more immediate feedback, before moving it to code.DataFrame Index By default, the result DataFrame is indexed by
span_id, and if .explode() is used, the index from the exploded list is added to create a multi-index on the result DataFrame. For the special retrieval.documents span attribute, the added index is renamed as document_position.How to Specify a Time Range
By default, all queries will collect all spans that are in your Phoenix instance. If you’d like to focus on most recent spans, you can pull spans based on time frames usingstart_time and end_time.
How to Specify a Project
By default all queries are executed against the default project or the project set via thePHOENIX_PROJECT_NAME environment variable. If you choose to pull from a different project, all methods on the Client have an optional parameter named project_name
Querying for Retrieved Documents
Let’s say we want to extract the retrieved documents into a DataFrame that looks something like the table below, whereinput denotes the query for the retriever, reference denotes the content of each document, and document_position denotes the (zero-based) index in each span’s list of retrieved documents.
Note that this DataFrame can be used directly as input for the Retrieval (RAG) Relevance evaluations.
We can accomplish this with a simple query as follows:
How to Explode Attributes
In addition to the document content, if we also want to explode the document score, we can simply add thedocument.score attribute to the .explode() method alongside document.content as follows. Keyword arguments are necessary to name the output columns, and in this example we name the output columns as reference and score. (Python’s double-asterisk unpacking idiom can be used to specify arbitrary output names containing spaces or symbols. See here for an example.)
How to Apply Filters
The.where() method accepts a filter expression — a string of valid Python boolean expression — and returns only the spans it matches. The same expressions work in the spans/traces filter bar in the Phoenix UI.
is None, and the full operator set — is documented in one place, for both spans and sessions:
Filter Expressions
The span and session filter language: fields, attributes, annotations/evals, substring search,
is None, and more.How to Extract Attributes
Span attributes can be selected by simply listing them inside.select() method.
Renaming Output Columns
Keyword-argument style can be used to rename the columns in the dataframe. The example below returns two columns namedinput and output instead of the original names of the attributes.
Arbitrary Output Column Names
If arbitrary output names are desired, e.g. names with spaces and symbols, we can leverage Python’s double-asterisk idiom for unpacking a dictionary, as shown below.Advanced Usage
Concatenating
The document contents can also be concatenated together. The query below concatenates the list ofdocument.content with (double newlines), which is the default separator. Keyword arguments are necessary to name the output columns, and in this example we name the output column as reference. (Python’s double-asterisk unpacking idiom can be used to specify arbitrary output names containing spaces or symbols. See here for an example.)
Special Separators
If a different separator is desired, say\n************, it can be specified as follows.
Using Parent ID as Index
This is useful for joining a span to its parent span. To do that we would first index the child span by selecting its parent ID and renaming it asspan_id. This works because span_id is a special column name: whichever column having that name will become the index of the output DataFrame.
Joining a Span to Its Parent
To do this, provide two queries to Phoenix and join the resulting dataframes with pandas.How to use Data for Evaluation
Extract the Input and Output from LLM Spans
To learn more about extracting span attributes, see How to Extract Attributes.Retrieval (RAG) Relevance Evaluations
To extract the dataframe input for Retrieval (RAG) Relevance evaluations, apply the query described in Querying for Retrieved Documents.Q&A on Retrieved Data Evaluations
To extract the dataframe input to the Q&A on Retrieved Data evaluations, use the following query which applies techniques described in the Advanced Usage section.input contains the question, the output column contains the answer, and the reference column contains a concatenation of all the retrieved documents.

