From 0e828e2c7d4f48a9c03759953f915c4bc735a8b1 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Sat, 30 May 2026 14:25:08 +0400 Subject: [PATCH] Revert "Studio: suppress RAG sources for uncited external prefetch" This reverts commit 05944a1e9b0c988c0fe0c05d1b783aa5f5d8ef9a. --- .../src/features/chat/api/chat-adapter.ts | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.ts index e4fad142f8..e847dd537c 100644 --- a/studio/frontend/src/features/chat/api/chat-adapter.ts +++ b/studio/frontend/src/features/chat/api/chat-adapter.ts @@ -449,18 +449,10 @@ function indexChunksByCitationId( function documentSourceIds( allChunks: ParsedChunk[], citedIds: Set, - requireCitations: boolean, ): string[] { if (citedIds.size > 0) { return Array.from(citedIds); } - // Prefetch injects docs unconditionally, so zero citations means the model - // judged them irrelevant — emit no badges rather than falsely attributing an - // off-topic answer to every retrieved chunk. The tool path keeps the lenient - // fallback since the model itself chose to search. - if (requireCitations) { - return []; - } return allChunks.map((chunk) => chunk.id); } @@ -511,10 +503,9 @@ function toDocumentSourcePart( function buildDocumentSourceParts( allChunks: ParsedChunk[], citedIds: Set, - requireCitations: boolean, ): DocumentSourcePart[] { const byId = indexChunksByCitationId(allChunks); - const idsToShow = documentSourceIds(allChunks, citedIds, requireCitations); + const idsToShow = documentSourceIds(allChunks, citedIds); const out: DocumentSourcePart[] = []; const emittedIds = new Set(); for (const id of idsToShow) { @@ -3136,31 +3127,14 @@ export function createOpenAIStreamAdapter(): ChatModelAdapter { } return parseChunks(typeof tc.result === "string" ? tc.result : ""); }); - const citedIds = extractCitedIds(cumulativeText); const documentSourceParts = ragChunks.length > 0 ? buildDocumentSourceParts( ragChunks, - citedIds, - // Prefetched (external) chunks were injected unconditionally, - // so require explicit citations before attributing sources. - ragPrefetchedThisTurn, + extractCitedIds(cumulativeText), ) : []; - // Prefetch surfaces a synthetic search_knowledge_base card every turn. - // If the model cited none of the injected chunks it judged them - // irrelevant, so drop the card from the final (persisted) content — - // same rationale as the suppressed source badges above. - if (ragPrefetchSynthetic && citedIds.size === 0) { - const idx = toolCallParts.findIndex( - (p) => p.toolCallId === ragPrefetchSynthetic?.toolCallId, - ); - if (idx !== -1) { - toolCallParts.splice(idx, 1); - } - } - // SDK's SourceMessagePart only types `sourceType: "url"` with a // required `url` field. SourcesGroup branches on `sourceType` at // runtime, so cast the doc-shaped parts through `unknown` rather