From a81c35a236784755e647306f08a3d9d8883adf36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Gajdulewicz?= Date: Wed, 31 Jul 2024 11:04:56 +0200 Subject: [PATCH] Fetch ranker relevance scores from GraphQL (#5066) Use https://github.com/sourcegraph/sourcegraph/pull/64172 in Cody ## Test plan - tested locally - code behind a feature flag --- lib/shared/src/sourcegraph-api/graphql/client.ts | 4 ++-- lib/shared/src/sourcegraph-api/graphql/queries.ts | 10 ++++++++-- vscode/src/chat/context/contextAPIClient.ts | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/shared/src/sourcegraph-api/graphql/client.ts b/lib/shared/src/sourcegraph-api/graphql/client.ts index 938f3edcedd4..3b360b6110a8 100644 --- a/lib/shared/src/sourcegraph-api/graphql/client.ts +++ b/lib/shared/src/sourcegraph-api/graphql/client.ts @@ -332,8 +332,8 @@ type RecordContextResponse = unknown interface RankContextResponse { rankContext: { ranker: string - used: number[] - ignored: number[] + used: { index: number; score: number }[] + ignored: { index: number; score: number }[] } } diff --git a/lib/shared/src/sourcegraph-api/graphql/queries.ts b/lib/shared/src/sourcegraph-api/graphql/queries.ts index 5c25fab1edc5..8166b9cedc47 100644 --- a/lib/shared/src/sourcegraph-api/graphql/queries.ts +++ b/lib/shared/src/sourcegraph-api/graphql/queries.ts @@ -213,8 +213,14 @@ export const RANK_CONTEXT_QUERY = ` query RankContext($interactionId: String!, $query: String!, $contextItems: [InputContextItem!]!) { rankContext(interactionId: $interactionId, query:$query, contextItems: $contextItems) { ranker - used - ignored + used { + index + score + } + ignored { + index + score + } } }` diff --git a/vscode/src/chat/context/contextAPIClient.ts b/vscode/src/chat/context/contextAPIClient.ts index 8f126bf077db..2974eac433c0 100644 --- a/vscode/src/chat/context/contextAPIClient.ts +++ b/vscode/src/chat/context/contextAPIClient.ts @@ -18,7 +18,11 @@ function toInput(input: ContextItem[]): InputContextItem[] { retriever: i.source || '', } ) - .filter(i => i !== null) as InputContextItem[] + .filter(notNull) +} + +function notNull(value: T | null | undefined): value is T { + return value !== null && value !== undefined } export class ContextAPIClient {