🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat: allow observation_id in v2 scores filtering (#11974)
Valery Meleshkin270f03640a5e
diff --git a/fern/apis/server/definition/score-v2.yml b/fern/apis/server/definition/score-v2.ymlindex e376595917..ece6ea69b2 100644--- a/fern/apis/server/definition/score-v2.yml+++ b/fern/apis/server/definition/score-v2.yml@@ -59,6 +59,9 @@ service:traceId:type: optional<string>docs: Retrieve only scores with a specific traceId.+ observationId:+ type: optional<string>+ docs: Comma-separated list of observation IDs to filter scores by.queueId:type: optional<string>docs: Retrieve only scores with a specific annotation queueId.diff --git a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.tsindex 7182c2fcd0..a3eef7693d 100644--- a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts+++ b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts@@ -12,6 +12,13 @@ export const GetScoresQueryV2 = GetScoresQuery.extend({sessionId: z.string().nullish(),traceId: z.string().nullish(),datasetRunId: z.string().nullish(),+ observationId: z+ .string()+ .transform((str) => str.split(",").map((id) => id.trim()))+ .refine((arr) => arr.every((id) => typeof id === "string"), {+ message: "Each observation ID must be a string",+ })+ .nullish(),});export const GetScoreResponseDataV2 = z.intersection(diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex a8a3662d11..26d3c0a162 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -4526,7 +4526,7 @@ paths:API key)operationId: scim_getServiceProviderConfigtags:- - Scim+ - SCIMparameters: []responses:'200':@@ -4567,7 +4567,7 @@ paths:description: Get SCIM Resource Types (requires organization-scoped API key)operationId: scim_getResourceTypestags:- - Scim+ - SCIMparameters: []responses:'200':@@ -4608,7 +4608,7 @@ paths:description: Get SCIM Schemas (requires organization-scoped API key)operationId: scim_getSchemastags:- - Scim+ - SCIMparameters: []responses:'200':@@ -4649,7 +4649,7 @@ paths:description: List users in the organization (requires organization-scoped API key)operationId: scim_listUserstags:- - Scim+ - SCIMparameters:- name: filterin: query@@ -4712,7 +4712,7 @@ paths:key)operationId: scim_createUsertags:- - Scim+ - SCIMparameters: []responses:'200':@@ -4783,7 +4783,7 @@ paths:description: Get a specific user by ID (requires organization-scoped API key)operationId: scim_getUsertags:- - Scim+ - SCIMparameters:- name: userIdin: path@@ -4831,7 +4831,7 @@ paths:does not delete the user entity itself.operationId: scim_deleteUsertags:- - Scim+ - SCIMparameters:- name: userIdin: path@@ -5201,6 +5201,13 @@ paths:schema:type: stringnullable: true+ - name: observationId+ in: query+ description: Comma-separated list of observation IDs to filter scores by.+ required: false+ schema:+ type: string+ nullable: true- name: queueIdin: querydescription: Retrieve only scores with a specific annotation queueId.diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.jsonindex 4d520371ef..24e156f7f8 100644--- a/web/public/generated/postman/collection.json+++ b/web/public/generated/postman/collection.json@@ -3241,7 +3241,7 @@"request": {"description": "Get a list of scores (supports both trace and session scores)","url": {- "raw": "{{baseUrl}}/api/public/v2/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&environment=&source=&operator=&value=&scoreIds=&configId=&sessionId=&datasetRunId=&traceId=&queueId=&dataType=&traceTags=&fields=",+ "raw": "{{baseUrl}}/api/public/v2/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&environment=&source=&operator=&value=&scoreIds=&configId=&sessionId=&datasetRunId=&traceId=&observationId=&queueId=&dataType=&traceTags=&fields=","host": ["{{baseUrl}}"],@@ -3327,6 +3327,11 @@"value": "","description": "Retrieve only scores with a specific traceId."},+ {+ "key": "observationId",+ "value": "",+ "description": "Comma-separated list of observation IDs to filter scores by."+ },{"key": "queueId","value": "",diff --git a/web/src/__tests__/async/scores-api-v2.servertest.ts b/web/src/__tests__/async/scores-api-v2.servertest.tsindex a6d664c306..2ef7d346b2 100644--- a/web/src/__tests__/async/scores-api-v2.servertest.ts+++ b/web/src/__tests__/async/scores-api-v2.servertest.ts@@ -1174,6 +1174,136 @@ describe("/api/public/v2/scores API Endpoint", () => {]),);});++ it("should filter scores by single observation ID", async () => {+ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV2,+ "GET",+ `/api/public/v2/scores?observationId=${generationId}`,+ undefined,+ authentication,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 3,+ totalPages: 1,+ });+ expect(getScore.body.data).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ id: scoreId_1,+ observationId: generationId,+ name: scoreName,+ value: 10.5,+ }),+ expect.objectContaining({+ id: scoreId_2,+ observationId: generationId,+ name: scoreName,+ value: 50.5,+ }),+ expect.objectContaining({+ id: scoreId_3,+ observationId: generationId,+ name: scoreName,+ value: 100.8,+ }),+ ]),+ );+ });++ it("should filter scores by multiple observation IDs", async () => {+ const { projectId, auth } = await createOrgProjectAndApiKey();+ const tId = v4();+ const obsId1 = v4();+ const obsId2 = v4();+ const obsId3 = v4();+ const sId1 = v4();+ const sId2 = v4();+ const sId3 = v4();++ await createTracesCh([createTrace({ id: tId, project_id: projectId })]);+ await createObservationsCh([+ createObservation({+ id: obsId1,+ project_id: projectId,+ type: "GENERATION",+ }),+ createObservation({+ id: obsId2,+ project_id: projectId,+ type: "GENERATION",+ }),+ createObservation({+ id: obsId3,+ project_id: projectId,+ type: "GENERATION",+ }),+ ]);+ await createScoresCh([+ createTraceScore({+ id: sId1,+ project_id: projectId,+ trace_id: tId,+ observation_id: obsId1,+ name: "score",+ value: 1,+ data_type: "NUMERIC",+ }),+ createTraceScore({+ id: sId2,+ project_id: projectId,+ trace_id: tId,+ observation_id: obsId2,+ name: "score",+ value: 2,+ data_type: "NUMERIC",+ }),+ createTraceScore({+ id: sId3,+ project_id: projectId,+ trace_id: tId,+ observation_id: obsId3,+ name: "score",+ value: 3,+ data_type: "NUMERIC",+ }),+ ]);++ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV2,+ "GET",+ `/api/public/v2/scores?observationId=${obsId1},${obsId2}`,+ undefined,+ auth,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 2,+ totalPages: 1,+ });+ expect(getScore.body.data).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ id: sId1,+ observationId: obsId1,+ value: 1,+ }),+ expect.objectContaining({+ id: sId2,+ observationId: obsId2,+ value: 2,+ }),+ ]),+ );+ expect(+ getScore.body.data.find((s: any) => s.id === sId3),+ ).toBeUndefined();+ });});describe("GET /api/public/v2/scores - fields parameter", () => {diff --git a/web/src/features/public-api/server/scores.ts b/web/src/features/public-api/server/scores.tsindex 70ff714290..a79d483af7 100644--- a/web/src/features/public-api/server/scores.ts+++ b/web/src/features/public-api/server/scores.ts@@ -52,6 +52,7 @@ export type ScoreQueryType = {traceTags?: string | string[];operator?: string;scoreIds?: string[];+ observationId?: string[];dataType?: string;environment?: string | string[];fields?: string[] | null;@@ -289,6 +290,13 @@ const secureScoreFilterOptions = [filterType: "StringFilter",clickhousePrefix: "s",},+ {+ id: "observationId",+ clickhouseSelect: "observation_id",+ clickhouseTable: "scores",+ filterType: "StringOptionsFilter",+ clickhousePrefix: "s",+ },{id: "name",clickhouseSelect: "name",diff --git a/web/src/pages/api/public/v2/scores/index.ts b/web/src/pages/api/public/v2/scores/index.tsindex 210ee63f56..92b30885ed 100644--- a/web/src/pages/api/public/v2/scores/index.ts+++ b/web/src/pages/api/public/v2/scores/index.ts@@ -44,6 +44,7 @@ export default withMiddlewares({configId: query.configId ?? undefined,sessionId: query.sessionId ?? undefined,traceId: query.traceId ?? undefined,+ observationId: query.observationId ?? undefined,datasetRunId: query.datasetRunId ?? undefined,queueId: query.queueId ?? undefined,traceTags: query.traceTags ?? undefined,