Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

perf(prompts): drop fk contraint on observations.prompt_id (#2355)

Marc Klingenaff27ef922c6
diff --git a/packages/shared/prisma/migrations/20240617094803_observations_remove_prompt_fk_constraint/migration.sql b/packages/shared/prisma/migrations/20240617094803_observations_remove_prompt_fk_constraint/migration.sql
new file mode 100644
index 0000000000..b9d3adcd36
--- /dev/null
+++ b/packages/shared/prisma/migrations/20240617094803_observations_remove_prompt_fk_constraint/migration.sql
@@ -0,0 +1,2 @@
+-- DropForeignKey
+ALTER TABLE "observations" DROP CONSTRAINT "observations_prompt_id_fkey";
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 1a528cb4f8..4220a20201 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -316,8 +316,7 @@ model Observation {
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
derivedDatasetItems DatasetItem[]
- promptId String? @map("prompt_id")
- prompt Prompt? @relation(fields: [promptId], onDelete: SetNull, references: [id])
+ promptId String? @map("prompt_id") // no fk constraint, prompt can be deleted
@@unique([id, projectId])
@@index([projectId, internalModel, startTime, unit])
@@ -590,15 +589,14 @@ model Prompt {
createdBy String @map("created_by")
- prompt Json
- name String
- version Int
- type String @default("text")
- isActive Boolean? @map("is_active") // Deprecated. To be removed once 'production' labels work as expected.
- config Json @default("{}")
- tags String[] @default([])
- labels String[] @default([])
- Observation Observation[]
+ prompt Json
+ name String
+ version Int
+ type String @default("text")
+ isActive Boolean? @map("is_active") // Deprecated. To be removed once 'production' labels work as expected.
+ config Json @default("{}")
+ tags String[] @default([])
+ labels String[] @default([])
@@unique([projectId, name, version])
@@index([projectId, name, version])
diff --git a/web/src/__tests__/observations.servertest.ts b/web/src/__tests__/observations.servertest.ts
index ea9dc94ff0..513f15de5b 100644
--- a/web/src/__tests__/observations.servertest.ts
+++ b/web/src/__tests__/observations.servertest.ts
@@ -75,9 +75,7 @@ describe("/api/public/observations API Endpoint", () => {
},
internalModel: "gpt-3.5-turbo",
unit: ModelUsageUnit.Tokens,
- prompt: {
- connect: { id: prompt.id },
- },
+ promptId: prompt.id,
},
});