Skip to content

Commit f4ab1f0

Browse files
RogerHYangmikeldkingaxiomofjoy
authored
feat(evaluators): db migration for evaluator tables (#9960)
Co-authored-by: Mikyo King <[email protected]> Co-authored-by: Xander Song <[email protected]>
1 parent 597536b commit f4ab1f0

File tree

15 files changed

+1753
-1
lines changed

15 files changed

+1753
-1
lines changed

app/schema.graphql

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,22 @@ input ClusterInput {
387387
id: ID
388388
}
389389

390+
type CodeEvaluator implements Evaluator & Node {
391+
"""The Globally Unique ID of this object"""
392+
id: ID!
393+
name: Identifier!
394+
description: String
395+
kind: EvaluatorKind!
396+
createdAt: DateTime!
397+
updatedAt: DateTime!
398+
user: User
399+
}
400+
401+
type CodeEvaluatorMutationPayload {
402+
evaluator: CodeEvaluator!
403+
query: Query!
404+
}
405+
390406
union ContentPart = TextContentPart | ToolCallContentPart | ToolResultContentPart
391407

392408
input ContentPartInput @oneOf {
@@ -449,12 +465,25 @@ input CreateChatPromptVersionInput {
449465
tags: [SetPromptVersionTagInput!] = null
450466
}
451467

468+
input CreateCodeEvaluatorInput {
469+
datasetId: ID!
470+
name: Identifier!
471+
description: String
472+
}
473+
452474
input CreateDatasetInput {
453475
name: String!
454476
description: String
455477
metadata: JSON
456478
}
457479

480+
input CreateDatasetLLMEvaluatorInput {
481+
datasetId: ID!
482+
name: Identifier!
483+
description: String
484+
promptVersion: ChatPromptVersionInput!
485+
}
486+
458487
input CreateDatasetLabelInput {
459488
name: String!
460489
description: String
@@ -633,6 +662,7 @@ type Dataset implements Node {
633662
experiments(first: Int = 50, last: Int, after: String, before: String, filterCondition: String, filterIds: [ID!]): ExperimentConnection!
634663
experimentAnnotationSummaries: [DatasetExperimentAnnotationSummary!]!
635664
labels: [DatasetLabel!]!
665+
evaluators(first: Int = 50, last: Int, after: String, before: String): EvaluatorConnection!
636666
lastUpdatedAt: DateTime
637667
}
638668

@@ -1236,6 +1266,39 @@ input EvalResultKey {
12361266
attr: EvalAttr!
12371267
}
12381268

1269+
interface Evaluator implements Node {
1270+
"""The Globally Unique ID of this object"""
1271+
id: ID!
1272+
name: Identifier!
1273+
description: String
1274+
kind: EvaluatorKind!
1275+
createdAt: DateTime!
1276+
updatedAt: DateTime!
1277+
}
1278+
1279+
"""A connection to a list of items."""
1280+
type EvaluatorConnection {
1281+
"""Pagination data for this connection"""
1282+
pageInfo: PageInfo!
1283+
1284+
"""Contains the nodes in this connection"""
1285+
edges: [EvaluatorEdge!]!
1286+
}
1287+
1288+
"""An edge in a connection."""
1289+
type EvaluatorEdge {
1290+
"""A cursor for use in pagination"""
1291+
cursor: String!
1292+
1293+
"""The item at the end of the edge"""
1294+
node: Evaluator!
1295+
}
1296+
1297+
enum EvaluatorKind {
1298+
LLM
1299+
CODE
1300+
}
1301+
12391302
type Event {
12401303
id: ID!
12411304
eventMetadata: EventMetadata!
@@ -1768,6 +1831,25 @@ type JSONInvocationParameter implements InvocationParameterBase {
17681831
defaultValue: JSON
17691832
}
17701833

1834+
type LLMEvaluator implements Evaluator & Node {
1835+
"""The Globally Unique ID of this object"""
1836+
id: ID!
1837+
name: Identifier!
1838+
description: String
1839+
kind: EvaluatorKind!
1840+
createdAt: DateTime!
1841+
updatedAt: DateTime!
1842+
prompt: Prompt!
1843+
promptVersionTag: PromptVersionTag
1844+
user: User
1845+
promptVersion: PromptVersion!
1846+
}
1847+
1848+
type LLMEvaluatorMutationPayload {
1849+
evaluator: LLMEvaluator!
1850+
query: Query!
1851+
}
1852+
17711853
type LabelFraction {
17721854
label: String!
17731855
fraction: Float!
@@ -1831,6 +1913,8 @@ type Mutation {
18311913
addDatasetExamplesToDatasetSplits(input: AddDatasetExamplesToDatasetSplitsInput!): AddDatasetExamplesToDatasetSplitsMutationPayload!
18321914
removeDatasetExamplesFromDatasetSplits(input: RemoveDatasetExamplesFromDatasetSplitsInput!): RemoveDatasetExamplesFromDatasetSplitsMutationPayload!
18331915
createDatasetSplitWithExamples(input: CreateDatasetSplitWithExamplesInput!): DatasetSplitMutationPayloadWithExamples!
1916+
createDatasetCodeEvaluator(input: CreateCodeEvaluatorInput!): CodeEvaluatorMutationPayload!
1917+
createDatasetLlmEvaluator(input: CreateDatasetLLMEvaluatorInput!): LLMEvaluatorMutationPayload!
18341918
deleteExperiments(input: DeleteExperimentsInput!): ExperimentMutationPayload!
18351919

18361920
"""
@@ -2501,6 +2585,7 @@ type Query {
25012585
promptLabels(first: Int = 50, last: Int, after: String, before: String): PromptLabelConnection!
25022586
datasetLabels(first: Int = 50, last: Int, after: String, before: String): DatasetLabelConnection!
25032587
datasetSplits(first: Int = 50, last: Int, after: String, before: String): DatasetSplitConnection!
2588+
evaluators(first: Int = 50, last: Int, after: String, before: String): EvaluatorConnection!
25042589
annotationConfigs(first: Int = 50, last: Int = null, after: String = null, before: String = null): AnnotationConfigConnection!
25052590
clusters(clusters: [ClusterInput!]!): [Cluster!]!
25062591
hdbscanClustering(

scripts/ddl/postgresql_schema.sql

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,70 @@ CREATE INDEX ix_document_annotations_span_rowid ON public.document_annotations
650650
USING btree (span_rowid);
651651

652652

653+
-- Table: evaluators
654+
-- -----------------
655+
CREATE TABLE public.evaluators (
656+
id bigserial NOT NULL,
657+
name VARCHAR NOT NULL,
658+
description VARCHAR,
659+
kind VARCHAR NOT NULL,
660+
user_id BIGINT,
661+
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
662+
CONSTRAINT pk_evaluators PRIMARY KEY (id),
663+
CONSTRAINT uq_evaluators_kind_id
664+
UNIQUE (kind, id),
665+
CONSTRAINT uq_evaluators_name
666+
UNIQUE (name),
667+
CHECK (((kind)::text = ANY ((ARRAY[
668+
'LLM'::character varying,
669+
'CODE'::character varying
670+
])::text[]))),
671+
CONSTRAINT fk_evaluators_user_id_users FOREIGN KEY
672+
(user_id)
673+
REFERENCES public.users (id)
674+
ON DELETE SET NULL
675+
);
676+
677+
CREATE INDEX ix_evaluators_user_id ON public.evaluators
678+
USING btree (user_id);
679+
680+
681+
-- Table: code_evaluators
682+
-- ----------------------
683+
CREATE TABLE public.code_evaluators (
684+
id BIGINT NOT NULL,
685+
kind VARCHAR NOT NULL DEFAULT 'CODE'::character varying,
686+
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
687+
CONSTRAINT pk_code_evaluators PRIMARY KEY (id),
688+
CHECK (((kind)::text = 'CODE'::text)),
689+
CONSTRAINT fk_code_evaluators_kind_evaluators FOREIGN KEY
690+
(kind, id)
691+
REFERENCES public.evaluators (kind, id)
692+
ON DELETE CASCADE
693+
);
694+
695+
696+
-- Table: datasets_evaluators
697+
-- --------------------------
698+
CREATE TABLE public.datasets_evaluators (
699+
dataset_id BIGINT NOT NULL,
700+
evaluator_id BIGINT NOT NULL,
701+
input_config JSONB NOT NULL,
702+
CONSTRAINT pk_datasets_evaluators PRIMARY KEY (dataset_id, evaluator_id),
703+
CONSTRAINT fk_datasets_evaluators_dataset_id_datasets FOREIGN KEY
704+
(dataset_id)
705+
REFERENCES public.datasets (id)
706+
ON DELETE CASCADE,
707+
CONSTRAINT fk_datasets_evaluators_evaluator_id_evaluators FOREIGN KEY
708+
(evaluator_id)
709+
REFERENCES public.evaluators (id)
710+
ON DELETE CASCADE
711+
);
712+
713+
CREATE INDEX ix_datasets_evaluators_evaluator_id ON public.datasets_evaluators
714+
USING btree (evaluator_id);
715+
716+
653717
-- Table: experiments
654718
-- ------------------
655719
CREATE TABLE public.experiments (
@@ -976,6 +1040,38 @@ CREATE INDEX ix_prompt_version_tags_user_id ON public.prompt_version_tags
9761040
USING btree (user_id);
9771041

9781042

1043+
-- Table: llm_evaluators
1044+
-- ---------------------
1045+
CREATE TABLE public.llm_evaluators (
1046+
id BIGINT NOT NULL,
1047+
kind VARCHAR NOT NULL DEFAULT 'LLM'::character varying,
1048+
prompt_id BIGINT NOT NULL,
1049+
prompt_version_tag_id BIGINT,
1050+
output_config JSONB NOT NULL,
1051+
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
1052+
CONSTRAINT pk_llm_evaluators PRIMARY KEY (id),
1053+
CHECK (((kind)::text = 'LLM'::text)),
1054+
CONSTRAINT fk_llm_evaluators_kind_evaluators FOREIGN KEY
1055+
(kind, id)
1056+
REFERENCES public.evaluators (kind, id)
1057+
ON DELETE CASCADE,
1058+
CONSTRAINT fk_llm_evaluators_prompt_id_prompts FOREIGN KEY
1059+
(prompt_id)
1060+
REFERENCES public.prompts (id)
1061+
ON DELETE RESTRICT,
1062+
CONSTRAINT fk_llm_evaluators_prompt_version_tag_id_prompt_version_tags
1063+
FOREIGN KEY
1064+
(prompt_version_tag_id)
1065+
REFERENCES public.prompt_version_tags (id)
1066+
ON DELETE SET NULL
1067+
);
1068+
1069+
CREATE INDEX ix_llm_evaluators_prompt_id ON public.llm_evaluators
1070+
USING btree (prompt_id);
1071+
CREATE INDEX ix_llm_evaluators_prompt_version_tag_id ON public.llm_evaluators
1072+
USING btree (prompt_version_tag_id);
1073+
1074+
9791075
-- Table: refresh_tokens
9801076
-- ---------------------
9811077
CREATE TABLE public.refresh_tokens (

0 commit comments

Comments
 (0)