@arizeai/phoenix-evals

中文文档
2.7.1发布于 2026/10/28Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 5.8万

A library for running evaluations for AI use cases

原始使用文档
文档目录10 节
  1. Installation
  2. Usage
  3. Creating a Classifier
  4. Pre-Built Evaluators
  5. Code Evaluators
  6. Data Mapping
  7. Experimentation with Phoenix
  8. Running Experiments
  9. Examples
  10. Community

Arize Phoenix logo
@arizeai/phoenix-evals

NPM Version Documentation

This package provides a TypeScript evaluation library. It is vendor agnostic and can be used in isolation of any framework or platform. This package is still under active development and is subject to change.

Installation

# or yarn, pnpm, bun, etc...
npm install @arizeai/phoenix-evals

This package is built on AI SDK v7, which is ESM-only. Node.js 22.12 or newer is required (the CommonJS build relies on require() of ESM). Use AI SDK v7-compatible model provider packages (e.g. @ai-sdk/openai v4+).

Usage

Creating a Classifier

The library provides a createClassifier function that allows you to create custom evaluators for different tasks like hallucination detection, relevance scoring, or any binary/multi-class classification.

import { createClassifier } from "@arizeai/phoenix-evals/llm";
import { openai } from "@ai-sdk/openai";

const model = openai("gpt-4o-mini");

const promptTemplate = `
In this task, you will be presented with a query, a reference text and an answer. The answer is
generated to the question based on the reference text. The answer may contain false information. You
must use the reference text to determine if the answer to the question contains false information,
if the answer is a hallucination of facts. Your objective is to determine whether the answer text
contains factual information and is not a hallucination. A 'hallucination' refers to
an answer that is not based on the reference text or assumes information that is not available in
the reference text. Your response should be a single word: either "factual" or "hallucinated", and
it should not include any other text or characters.

    [BEGIN DATA]
    ************
    [Query]: {{input}}
    ************
    [Reference text]: {{reference}}
    ************
    [Answer]: {{output}}
    ************
    [END DATA]

Is the answer above factual or hallucinated based on the query and reference text?
`;

// Create the classifier
const evaluator = await createClassifier({
  model,
  choices: { factual: 1, hallucinated: 0 },
  promptTemplate: promptTemplate,
});

// Use the classifier
const result = await evaluator({
  output: "Arize is not open source.",
  input: "Is Arize Phoenix Open Source?",
  reference:
    "Arize Phoenix is a platform for building and deploying AI applications. It is open source.",
});

console.log(result);
// Output: { label: "hallucinated", score: 0 }

See the complete example in examples/classifier_example.ts.

Pre-Built Evaluators

The library includes several pre-built evaluators for common evaluation tasks. These evaluators come with optimized prompts and can be used directly with any AI SDK model.

All pre-built evaluators are available from the @arizeai/phoenix-evals/llm module:

EvaluatorFunctionDescription
FaithfulnesscreateFaithfulnessEvaluatorDetects hallucinations — checks if the output is grounded in the provided context
CompletenesscreateCompletenessEvaluatorChecks whether every active user request in a conversation was actually completed
ConcisenesscreateConcisenessEvaluatorEvaluates whether the response is appropriately concise
CorrectnesscreateCorrectnessEvaluatorChecks if the output is factually correct given the input
Retrieval RelevancecreateRetrievalRelevanceEvaluatorMeasures how relevant retrieved information is to a request
RefusalcreateRefusalEvaluatorDetects whether the model refused to answer
Tool InvocationcreateToolInvocationEvaluatorEvaluates whether the correct tool was invoked with the right arguments
Tool SelectioncreateToolSelectionEvaluatorChecks whether the right tool was selected for the task
Tool Response HandlingcreateToolResponseHandlingEvaluatorEvaluates how well the model uses a tool's response
PII DetectioncreatePiiDetectionEvaluatorScreens a conversation record for personally identifiable information
import {
  createFaithfulnessEvaluator,
  createConcisenessEvaluator,
  createCorrectnessEvaluator,
  createRetrievalRelevanceEvaluator,
  createRefusalEvaluator,
} from "@arizeai/phoenix-evals/llm";
import { openai } from "@ai-sdk/openai";

const model = openai("gpt-4o-mini");

// Faithfulness: checks if the output is grounded in the context
const faithfulnessEvaluator = createFaithfulnessEvaluator({ model });
const faithfulnessResult = await faithfulnessEvaluator.evaluate({
  input: "What is the capital of France?",
  context: "France is a country in Europe. Paris is its capital city.",
  output: "The capital of France is London.",
});
console.log(faithfulnessResult);
// Output: { label: "unfaithful", score: 0, explanation: "..." }

// Correctness: checks if the output is factually correct
const correctnessEvaluator = createCorrectnessEvaluator({ model });
const correctnessResult = await correctnessEvaluator.evaluate({
  input: "What is the capital of France?",
  output: "Paris is the capital of France.",
});
console.log(correctnessResult);
// Output: { label: "correct", score: 1, explanation: "..." }

// Retrieval Relevance: checks if retrieved information is relevant to the request
const relevanceEvaluator = createRetrievalRelevanceEvaluator({ model });
const relevanceResult = await relevanceEvaluator.evaluate({
  input: "What is the capital of France?",
  context: "Paris is the capital of France and a major European city.",
});
console.log(relevanceResult);
// Output: { label: "relevant", score: 1, explanation: "..." }

Code Evaluators

The library also includes built-in, deterministic (non-LLM) code evaluators for common classification metrics: precision, recall, and F-beta (including F1). These are available from the @arizeai/phoenix-evals/code module and work over a batch of expected vs. predicted labels, supporting both binary classification (via positiveLabel) and multi-class classification (via macro/micro/weighted averaging).

  • Precision — of everything predicted as a class, the fraction that was actually that class (TP / (TP + FP)). Lower precision means more false alarms.
  • Recall — of everything that actually belongs to a class, the fraction the model found (TP / (TP + FN)). Lower recall means more misses.
  • F-beta — the weighted harmonic mean of precision and recall. beta = 1 (F1, the default) weights them equally; beta > 1 weights recall more (use when missing a true positive is costlier, e.g. medical screening); beta < 1 weights precision more (use when a false alarm is costlier, e.g. spam filtering).
import {
  createPrecisionEvaluator,
  createRecallEvaluator,
  createF1Evaluator,
  createPrecisionRecallFScoreEvaluators,
} from "@arizeai/phoenix-evals/code";

const f1 = createF1Evaluator();
const result = await f1.evaluate({
  expected: ["cat", "dog", "cat", "bird"],
  output: ["cat", "cat", "cat", "bird"],
});
console.log(result);
// Output: { score: 0.6 }

// Or create matching precision/recall/F-score evaluators at once
const { precision, recall, fScore } = createPrecisionRecallFScoreEvaluators({
  average: "weighted",
});

Use createFBetaEvaluator({ beta }) for F-scores other than F1 (e.g. beta: 2 weights recall higher than precision). createPrecisionRecallFScoreEvaluators returns three separate evaluators ({ precision, recall, fScore }) sharing one options object — each yields a single score, matching the individual factories.

For multi-class data, average controls how per-class scores combine into one number: "macro" (default) weights every class equally — good for surfacing whether a rare class is being ignored; "weighted" weights each class by how often it occurs — good when overall performance matters more than parity across classes; "micro" pools every true/false positive and false negative across classes first — for single-label multi-class problems this equals overall accuracy.

See examples/classification_metrics_example.ts for a runnable walkthrough covering binary classification, F-beta tradeoffs, and all three averaging strategies. For the underlying formulas, the precision/recall tradeoff, and citations, see the Precision / Recall / F-Score docs.

Note: unlike the per-row LLM evaluators above, these classification-metric evaluators are batch/dataset-level: expected/output are the full sequence of labels across every example, not a single row's labels. Don't wire them directly into runExperiment as a per-row evaluator — instead, collect every row's expected/predicted label first, then call .evaluate({ expected, output }) once over the full arrays.

Data Mapping

When your data structure doesn't match what an evaluator expects, use bindEvaluator to map your fields to the evaluator's expected input format:

import { bindEvaluator } from "@arizeai/phoenix-evals";
import { createFaithfulnessEvaluator } from "@arizeai/phoenix-evals/llm";
import { openai } from "@ai-sdk/openai";

const model = openai("gpt-4o-mini");

type ExampleType = {
  question: string;
  context: string;
  answer: string;
};

const evaluator = bindEvaluator<ExampleType>(
  createFaithfulnessEvaluator({ model }),
  {
    inputMapping: {
      input: "question", // Map "input" from "question"
      context: "context", // Map "context" from "context"
      output: "answer", // Map "output" from "answer"
    },
  }
);

const result = await evaluator.evaluate({
  question: "Is Arize Phoenix Open Source?",
  context:
    "Arize Phoenix is a platform for building and deploying AI applications. It is open source.",
  answer: "Arize is not open source.",
});

Mapping supports simple properties ("fieldName"), dot notation ("user.profile.name"), array access ("items[0].id"), JSONPath expressions ("$.items[*].id"), and function extractors ((data) => data.customField).

See the complete example in examples/bind_evaluator_example.ts.

Experimentation with Phoenix

This package works seamlessly with @arizeai/phoenix-client to enable experimentation workflows. You can create datasets, run experiments, and trace evaluation calls for analysis and debugging.

Running Experiments

To run experiments with your evaluations, install the phoenix-client

npm install @arizeai/phoenix-client
import { createFaithfulnessEvaluator } from "@arizeai/phoenix-evals/llm";
import { openai } from "@ai-sdk/openai";
import { createDataset } from "@arizeai/phoenix-client/datasets";
import {
  asExperimentEvaluator,
  runExperiment,
} from "@arizeai/phoenix-client/experiments";

// Create your evaluator
const faithfulnessEvaluator = createFaithfulnessEvaluator({
  model: openai("gpt-4o-mini"),
});

// Create a dataset for your experiment
const dataset = await createDataset({
  name: "faithfulness-eval",
  description: "Evaluate the faithfulness of the model",
  examples: [
    {
      input: {
        question: "Is Phoenix Open-Source?",
        context: "Phoenix is Open-Source.",
      },
    },
    // ... more examples
  ],
});

// Define your experimental task
const task = async (example) => {
  // Your AI system's response to the question
  return "Phoenix is not Open-Source";
};

// Create a custom evaluator to validate results
const faithfulnessCheck = asExperimentEvaluator({
  name: "faithfulness",
  kind: "LLM",
  evaluate: async ({ input, output }) => {
    // Use the faithfulness evaluator from phoenix-evals
    const result = await faithfulnessEvaluator({
      input: input.question,
      context: input.context,
      output: output,
    });

    return result; // Return the evaluation result
  },
});

// Run the experiment with automatic tracing
runExperiment({
  experimentName: "faithfulness-eval",
  experimentDescription: "Evaluate the faithfulness of the model",
  dataset: dataset,
  task,
  evaluators: [faithfulnessCheck],
});

Examples

To run examples, install dependencies using pnpm and run:

pnpm install
pnpx tsx examples/classifier_example.ts
# change the file name to run other examples

Community

Join our community to connect with thousands of AI builders:

版本与发布记录

@arizeai/phoenix-evals 共发布 40 个版本,首次发布于 2025/07/08;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.7.1latest2026/10/2810 天前
2.7.02026/10/2217 天前
2.6.02026/09/221 个月前
2.5.02026/09/101 个月前
2.4.02026/08/292 个月前
2.3.02026/08/222 个月前

关于 @arizeai/phoenix-evals 的常见问题

@arizeai/phoenix-evals 是什么?

A library for running evaluations for AI use cases

如何安装 @arizeai/phoenix-evals?

在项目目录运行 npm install @arizeai/phoenix-evals,或使用 pnpm add / yarn add / bun add。

@arizeai/phoenix-evals 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arizeai/phoenix-evals 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@arizeai/phoenix-evals 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@arizeai/phoenix-evals 可以商用吗?

@arizeai/phoenix-evals 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@arizeai/phoenix-evals 的下载量有多少?

根据 npm 官方下载统计,@arizeai/phoenix-evals 在 2026/10/07 – 2026/11/05 这 30 天内被下载 58,215 次,日均约 1,941 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arizeai/phoenix-evals 还在维护吗?

最新版本 2.7.1 发布于 2026/10/28(10 天前);至今共发布 40 个版本,其中过去 12 个月发布了 27 个;首次发布于 2025/07/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。