-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: rag new schema, standalone package #448
Draft
mantagen
wants to merge
26
commits into
main
Choose a base branch
from
feat/ingest-publish-rag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
523cbd8
feat: create ingest 'publish' script
mantagen 1c06d78
remove merge markers
mantagen be9d8d5
add tests and key stage helper
mantagen 20ba83e
Merge branch 'main' into feat/ingest-publish-rag
mantagen ad665b7
publish script
mantagen 63a3ba0
fix publish step and retrieval
mantagen 05ba3c5
rag lesson plan indexes
mantagen f33933b
Merge branch 'main' into feat/ingest-publish-rag
mantagen f0d8469
move rag into own package
mantagen ce1cd63
split out functions into own files and add tests
mantagen fe64dbd
fix search tests and add faker zod lib
mantagen 1fd47b2
new rag behind feature flag
mantagen dba54e4
camel case sql query response
mantagen 7485394
fix publishing step
mantagen a9f6fb3
Merge branch 'main' into feat/ingest-publish-rag
mantagen 282664c
use posthog feature flag
mantagen 55390d3
Merge branch 'main' into feat/ingest-publish-rag
mantagen af00731
remove shortenKeyStage helper
mantagen b9d7297
move block above new rag call
mantagen 0be6d10
remove else block
mantagen 4b4eaa2
Merge branch 'main' into feat/ingest-publish-rag
mantagen f83a6ae
split out search function
mantagen 2e0c962
rename rag index test file
mantagen 3a1f4fb
code style change
mantagen 12f6233
move utils into appropriate places
mantagen 75a7bbc
use map over for
mantagen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const keyStageMap: Record<string, string> = { | ||
1: "ks1", | ||
2: "ks2", | ||
3: "ks3", | ||
4: "ks4", | ||
5: "ks5", | ||
keystage1: "ks1", | ||
keystage2: "ks2", | ||
keystage3: "ks3", | ||
keystage4: "ks4", | ||
keystage5: "ks5", | ||
eyfs: "early-years-foundation-stage", | ||
}; | ||
|
||
export function parseKeyStage(maybeKeyStage: string): string { | ||
maybeKeyStage = maybeKeyStage.toLowerCase().replace(/[^a-z0-9]/g, ""); | ||
const keyStageSlug = keyStageMap[maybeKeyStage]; | ||
|
||
return keyStageSlug ?? maybeKeyStage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const subjectMap: Record<string, string[]> = { | ||
science: ["biology", "chemistry", "physics", "science", "combined-science"], | ||
biology: ["biology", "science", "combined-science"], | ||
chemistry: ["chemistry", "science", "combined-science"], | ||
physics: ["physics", "science", "combined-science"], | ||
"combined-science": [ | ||
"combined-science", | ||
"science", | ||
"biology", | ||
"chemistry", | ||
"physics", | ||
], | ||
}; | ||
|
||
export function parseSubjects(subject: string): string[] { | ||
return subjectMap[subject] ?? [subject]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const shortenKeyStage = (keyStage: string) => { | ||
const keyStageMap: Record<string, string> = { | ||
"key-stage-1": "KS1", | ||
"key-stage-2": "KS2", | ||
"key-stage-3": "KS3", | ||
"key-stage-4": "KS4", | ||
}; | ||
|
||
return keyStageMap[keyStage] || keyStage; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Schema additions | ||
|
||
This directory houses SQL additions to the Prisma schema where the Prisma schema is not expressive enough to capture the desired schema. |
4 changes: 4 additions & 0 deletions
4
packages/db/prisma/additions/rag_lesson_plans_ivfflat_index.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE INDEX IF NOT EXISTS idx_rag_lesson_plan_parts_embedding_ann | ||
ON rag.rag_lesson_plan_parts | ||
USING ivfflat (embedding vector_cosine_ops) | ||
WITH (lists = 100); |
3 changes: 3 additions & 0 deletions
3
packages/db/prisma/additions/rag_lesson_plans_unique_slug_index.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE UNIQUE INDEX IF NOT EXISTS idx_rag_lesson_plans_unique_published_oak_lesson_slug | ||
ON rag.rag_lesson_plans (oak_lesson_slug) | ||
WHERE is_published = TRUE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1117,16 +1117,21 @@ model IngestError { | |
} | ||
|
||
model RagLessonPlan { | ||
id String @id @default(cuid()) | ||
oakLessonId Int @map("oak_lesson_id") | ||
ingestLessonId String? @map("ingest_lesson_id") | ||
lessonPlan Json @map("lesson_plan") @db.JsonB | ||
subjectSlug String @map("subject_slug") | ||
keyStageSlug String @map("key_stage_slug") | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
ragLessonPlanPart RagLessonPlanPart[] | ||
|
||
id String @id @default(cuid()) | ||
oakLessonId Int? @map("oak_lesson_id") | ||
oakLessonSlug String @map("oak_lesson_slug") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adds slug as a mandatory field |
||
ingestLessonId String? @map("ingest_lesson_id") | ||
lessonPlan Json @map("lesson_plan") @db.JsonB | ||
subjectSlug String @map("subject_slug") | ||
keyStageSlug String @map("key_stage_slug") | ||
isPublished Boolean @default(false) @map("is_published") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adds |
||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") | ||
ragLessonPlanParts RagLessonPlanPart[] | ||
// The following index is not supported by prisma so is applied manually in ./additions/rag_lesson_plans_unique_slug_index.sql | ||
// @@index([oakLessonSlug], name: "unique_published_oak_lesson_slug", dbIndex: false) @db.PartialIndex("is_published = TRUE") | ||
|
||
@@index([isPublished, keyStageSlug, subjectSlug], name: "idx_rag_lesson_plans_published_key_stage_subject") | ||
@@map("rag_lesson_plans") | ||
@@schema("rag") | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.jsonl | ||
*.json | ||
*.csv | ||
*.csv | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonar might complain here about reassigning an argument