이 페이지에서는 에이전트의 품질을 측정하기 위한 고품질 평가 집합을 가상으로 생성하는 방법을 설명합니다.
평가 집합을 수동으로 빌드하는 것은 종종 시간이 오래 걸리며 에이전트의 모든 기능을 포함하는지 확인하기가 어렵습니다. Mosaic AI 에이전트 평가는 문서에서 대표 평가 집합을 자동으로 생성하여 이러한 장벽을 제거하고, 테스트 사례 전반에 걸쳐 에이전트를 신속하고 효과적으로 평가할 수 있습니다.
평가 집합 생성
문서 검색을 사용하는 에이전트에 대한 평가를 합성하려면 generate_evals_df
Python 패키지의 일부인 databricks-agents
메서드를 사용합니다. API에 대한 자세한 내용은 Python SDK 참조참조하세요.
이 메서드를 사용하려면 문서를 Pandas DataFrame 또는 Spark DataFrame으로 제공해야 합니다.
입력 데이터 프레임에는 다음 열이 있어야 합니다.
-
content
: 구문 분석된 문서의 내용이 문자열로 나타납니다. -
doc_uri
: 문서 URI입니다.
세 가지 추가 매개 변수를 사용하여 생성을 제어할 수 있습니다.
num_evals
: 모든 문서에서 생성할 총 평가 수입니다. 함수는 문서의 크기를 고려하여 생성된 평가를 모든 문서에 분산하려고 합니다. 만약num_evals
가 문서의 수보다 작으면, 평가 집합에서는 모든 문서를 포함하지 못할 것입니다.num_evals
사용하여 문서에 평가를 배포하는 방법에 대한 자세한 내용은num_evals
사용되는 방법을 참조하세요.agent_description
: 에이전트에 대한 작업 설명question_guidelines
: 가상 질문 생성을 안내하는 데 도움이 되는 지침 집합입니다. 생성을 요청하는 데 사용할 자유 형식 문자열입니다. 아래 예제를 참조하세요.
결과 generate_evals_df
는 DataFrame입니다. DataFrame의 열은 MLflow 3 또는 MLflow 2를 사용하는지 여부에 따라 달라집니다.
MLflow 3
-
request_id
: 고유한 요청 ID입니다. -
inputs
: 채팅 완료 API의 합성된 입력 -
expectations
: 두 필드가 있는 사전:-
expected_facts
: 응답에 예상되는 팩트 목록입니다. 이 열에는 dtype list[string]이 있습니다. -
expected_retrieved_context
: 이 평가가 합성된 컨텍스트는 문서 콘텐츠와 doc_uri를 포함합니다.
-
MLflow 2
-
request_id
: 고유한 요청 ID입니다. -
request
: 합성된 요청입니다. -
expected_facts
: 응답에 예상되는 팩트 목록입니다. 이 열에는 dtype list[string]이 있습니다. -
expected_retrieved_context
: 이 평가가 합성된 컨텍스트는 문서 콘텐츠와 doc_uri를 포함합니다.
본보기
다음 예제에서는 generate_evals_df
사용하여 평가 집합을 생성한 다음 mlflow.evaluate()
직접 호출하여 이 eval 집합에서 Meta Llama 3.1의 성능을 측정합니다. Llama 3.1 모델은 문서를 본 적이 없으므로 환각할 가능성이 높습니다. 그럼에도 불구하고 이 실험은 사용자 지정 에이전트에 적합한 기준선입니다.
%pip install databricks-agents
dbutils.library.restartPython()
import mlflow
from databricks.agents.evals import generate_evals_df
import pandas as pd
import math
# `docs` can be a Pandas DataFrame or a Spark DataFrame with two columns: 'content' and 'doc_uri'.
docs = pd.DataFrame.from_records(
[
{
'content': f"""
Apache Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Java,
Scala, Python and R, and an optimized engine that supports general execution graphs. It also supports a rich set
of higher-level tools including Spark SQL for SQL and structured data processing, pandas API on Spark for pandas
workloads, MLlib for machine learning, GraphX for graph processing, and Structured Streaming for incremental
computation and stream processing.
""",
'doc_uri': 'https://spark.apache.org/docs/3.5.2/'
},
{
'content': f"""
Spark's primary abstraction is a distributed collection of items called a Dataset. Datasets can be created from Hadoop InputFormats (such as HDFS files) or by transforming other Datasets. Due to Python's dynamic nature, we don't need the Dataset to be strongly-typed in Python. As a result, all Datasets in Python are Dataset[Row], and we call it DataFrame to be consistent with the data frame concept in Pandas and R.""",
'doc_uri': 'https://spark.apache.org/docs/3.5.2/quick-start.html'
}
]
)
agent_description = """
The Agent is a RAG chatbot that answers questions about using Spark on Databricks. The Agent has access to a corpus of Databricks documents, and its task is to answer the user's questions by retrieving the relevant docs from the corpus and synthesizing a helpful, accurate response. The corpus covers a lot of info, but the Agent is specifically designed to interact with Databricks users who have questions about Spark. So questions outside of this scope are considered irrelevant.
"""
question_guidelines = """
# User personas
- A developer who is new to the Databricks platform
- An experienced, highly technical Data Scientist or Data Engineer
# Example questions
- what API lets me parallelize operations over rows of a delta table?
- Which cluster settings will give me the best performance when using Spark?
# Additional Guidelines
- Questions should be succinct, and human-like
"""
num_evals = 10
evals = generate_evals_df(
docs,
# The total number of evals to generate. The method attempts to generate evals that have full coverage over the documents
# provided. If this number is less than the number of documents, is less than the number of documents,
# some documents will not have any evaluations generated. See "How num_evals is used" below for more details.
num_evals=num_evals,
# A set of guidelines that help guide the synthetic generation. These are free-form strings that will be used to prompt the generation.
agent_description=agent_description,
question_guidelines=question_guidelines
)
display(evals)
# Evaluate the model using the newly generated evaluation set. After the function call completes, click the UI link to see the results. You can use this as a baseline for your agent.
results = mlflow.evaluate(
model="endpoints:/databricks-meta-llama-3-1-405b-instruct",
data=evals,
model_type="databricks-agent"
)
# Note: To use a different model serving endpoint, use the following snippet to define an agent_fn. Then, specify that function using the `model` argument.
# MODEL_SERVING_ENDPOINT_NAME = '...'
# def agent_fn(input):
# client = mlflow.deployments.get_deploy_client("databricks")
# return client.predict(endpoint=MODEL_SERVING_ENDPOINT_NAME, inputs=input)
예제 출력은 다음과 같습니다. 출력 열은 MLflow 3 또는 MLflow 2를 사용하는지 여부에 따라 달라집니다.
MLflow 3
다음 예제 출력에서는 request_id
열과 expectations.expected_retrieved_context
표시되지 않습니다.
inputs.messages[0].content | 기대.예상된_사실 |
---|---|
Apache Spark에서 사용되는 Spark SQL은 무엇인가요? |
|
Apache Spark에서 지원하는 고급 도구는 무엇이며 어떤 용도로 제공됩니까? |
|
Spark의 기본 추상화란 무엇이며 데이터 세트는 Python에서 어떻게 표현됩니까? |
|
Python의 모든 데이터 세트가 Spark의 DataFrames라고 하는 이유는 무엇인가요? |
|
MLflow 2
다음 예제 출력에서는 request_id
열과 expected_retrieved_context
표시되지 않습니다.
요청 | 예상 사실 |
---|---|
Apache Spark에서 사용되는 Spark SQL은 무엇인가요? |
|
Apache Spark에서 지원하는 고급 도구는 무엇이며 어떤 용도로 제공됩니까? |
|
Spark의 기본 추상화란 무엇이며 데이터 세트는 Python에서 어떻게 표현됩니까? |
|
Python의 모든 데이터 세트가 Spark의 DataFrames라고 하는 이유는 무엇인가요? |
|
num_evals
사용하는 방법
num_evals
문서 집합에 대해 생성된 총 평가 수입니다. 이 함수는 문서 크기의 차이를 고려하는 동안 이러한 평가를 문서 전체에 분산합니다. 즉, 문서 집합 전체에서 페이지당 거의 동일한 수의 질문을 유지하려고 합니다.
num_evals
문서 수보다 작으면 일부 문서에는 평가가 생성되지 않습니다. 함수에서 반환된 DataFrame에는 평가를 생성하는 데 사용된 source_doc_ids
값이 있는 열이 포함됩니다. 이 열을 사용하여 원래 DataFrame에 다시 조인하여 제외된 문서에 대한 평가를 생성할 수 있습니다.
원하는 범위에 대한 num_evals
을 추정하는 데 도움이 되도록 estimate_synthetic_num_evals
메서드를 제공합니다.
from databricks.agents.evals import estimate_synthetic_num_evals
num_evals = estimate_synthetic_num_evals(
docs, # Same docs as before.
eval_per_x_tokens = 1000 # Generate 1 eval for every x tokens to control the coverage level.
)
가상 평가 집합 만들기 - Notebook 예제
가상 평가 집합을 만드는 예제 코드는 다음 Notebook을 참고하십시오.
합성 평가 예제 노트
Notebook 가져오기
에이전트의 성능을 향상시키기 위한 10분 데모
다음 예제 Notebook에서는 에이전트의 품질을 개선하는 방법을 보여 줍니다. 여기에는 다음 단계가 포함됩니다.
- 합성 평가 데이터 세트를 생성합니다.
- 기준 에이전트를 빌드하고 평가합니다.
- 기준 에이전트를 여러 구성(예: 다른 프롬프트) 및 기본 모델과 비교하여 품질, 비용 및 대기 시간의 적절한 균형을 찾습니다.
- 관련자가 추가 피드백을 테스트하고 제공할 수 있도록 웹 UI에 에이전트를 배포합니다.
가상 데이터 Notebook을 사용하여 에이전트 성능 향상
Notebook 가져오기
가상 데이터를 구동하는 모델에 대한 정보
- 가상 데이터는 타사 서비스를 사용하여 Microsoft에서 운영하는 Azure OpenAI를 포함하여 생성 AI 애플리케이션을 평가할 수 있습니다.
- Azure OpenAI의 경우 Databricks는 남용 모니터링을 옵트아웃하여 Azure OpenAI와 함께 프롬프트 또는 응답을 저장하지 않습니다.
- 유럽 연합(EU) 작업 영역의 경우 가상 데이터는 EU에서 호스트되는 모델을 사용합니다. 다른 모든 지역에서는 미국에서 호스트되는 모델을 사용합니다.
- Azure AI 기반 AI 보조 기능을 사용하지 않도록 설정하면 합성 데이터 서비스가 Azure AI 기반 모델을 호출하지 않게 됩니다.
- 가상 데이터 서비스로 전송된 데이터는 모델 학습에 사용되지 않습니다.
- 가상 데이터는 고객이 에이전트 애플리케이션을 평가하는 데 도움을 주기 위한 것이며, 출력은 LLM을 학습, 개선 또는 미세 조정하는 데 사용해서는 안 됩니다.