Revert "Studio: suppress RAG sources for uncited external prefetch"
This reverts commit 05944a1e9b.
This commit is contained in:
parent
538b69cf00
commit
0e828e2c7d
1 changed files with 2 additions and 28 deletions
|
|
@ -449,18 +449,10 @@ function indexChunksByCitationId(
|
|||
function documentSourceIds(
|
||||
allChunks: ParsedChunk[],
|
||||
citedIds: Set<string>,
|
||||
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<string>,
|
||||
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<string>();
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue