diff --git a/packages/web/server/utils/embeddings.ts b/packages/web/server/utils/embeddings.ts index cc53a63..22b838f 100644 --- a/packages/web/server/utils/embeddings.ts +++ b/packages/web/server/utils/embeddings.ts @@ -4,6 +4,8 @@ import { hash } from 'ohash' type RestIssue = RestEndpointMethodTypes['issues']['get']['response']['data'] +export type IssueSegments = 'labels' | 'title' | 'body' + export function storageKeyForIssue(owner: string, repo: string, number: number | string) { return `issue:${owner}:${repo}:${number}` } @@ -136,7 +138,7 @@ function preprocessText(text: string): string { .trim() } -export function chunkIssue(issue: Pick<Issue | RestIssue, 'labels' | 'title' | 'body'>, exclude?: Set<string>) { +export function chunkIssue(issue: Pick<Issue | RestIssue, IssueSegments>, exclude?: Set<string>) { const labels = getLabels(issue).filter(l => !exclude?.has(l)) return preprocessText(`${issue.title}\n${labels.join(', ')}\n${issue.body}`) } @@ -152,6 +154,6 @@ async function generateEmbedding(text: string): Promise<number[]> { } } -function getLabels(issue: Pick<Issue | RestIssue, 'labels' | 'title' | 'body'>) { +function getLabels(issue: Pick<Issue | RestIssue, IssueSegments>) { return issue.labels?.map(label => (typeof label === 'string' ? label : label.name!).toLowerCase()).filter(Boolean) || [] }