fix(quick-qa): distinguish web and knowledge base retrieval in pipeline UI
Emit search_source metadata from RAG progress events so quick-answer steps, summaries, and IM labels no longer mislabel web-only results as knowledge base search.
This commit is contained in:
@@ -66,3 +66,13 @@ test('getRagPipelineStepTitle uses query-aware search labels', () => {
|
||||
})
|
||||
assert.equal(title, 'searching 讯飞开放平台')
|
||||
})
|
||||
|
||||
test('getRagPipelineStepTitle uses web labels when search_source is web', () => {
|
||||
const title = getRagPipelineStepTitle(t, {
|
||||
tool_name: 'knowledge_search',
|
||||
pending: false,
|
||||
success: true,
|
||||
arguments: { search_source: 'web' },
|
||||
})
|
||||
assert.equal(title, 'agentStream.toolStatus.webSearch')
|
||||
})
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { ComposerTranslation } from 'vue-i18n'
|
||||
|
||||
export type RetrievalSearchSource = 'knowledge' | 'web' | 'mixed'
|
||||
|
||||
function collectQueryStrings(value: unknown): string[] {
|
||||
if (value == null) return []
|
||||
|
||||
@@ -71,6 +73,44 @@ export function getWikiPageText(args: unknown): string {
|
||||
return Array.from(new Set(slugs)).join('、')
|
||||
}
|
||||
|
||||
export function getRetrievalSearchSource(
|
||||
args: unknown,
|
||||
toolData?: Record<string, unknown> | null,
|
||||
): RetrievalSearchSource {
|
||||
const fromArgs =
|
||||
args && typeof args === 'object'
|
||||
? String((args as Record<string, unknown>).search_source || '')
|
||||
: ''
|
||||
const fromData = toolData ? String(toolData.search_source || '') : ''
|
||||
const source = (fromData || fromArgs).trim()
|
||||
if (source === 'web' || source === 'mixed') {
|
||||
return source
|
||||
}
|
||||
return 'knowledge'
|
||||
}
|
||||
|
||||
function getRetrievalStatusKeys(source: RetrievalSearchSource, failed: boolean) {
|
||||
if (source === 'web') {
|
||||
return failed
|
||||
? { pending: 'agentStream.ragPipeline.searchingWeb', pendingWithQuery: 'agentStream.ragPipeline.searchingWebWithQuery', done: 'agentStream.toolStatus.webSearch', doneFailed: 'agentStream.toolStatus.webSearchFailed' }
|
||||
: { pending: 'agentStream.ragPipeline.searchingWeb', pendingWithQuery: 'agentStream.ragPipeline.searchingWebWithQuery', done: 'agentStream.toolStatus.webSearch', doneFailed: 'agentStream.toolStatus.webSearchFailed' }
|
||||
}
|
||||
if (source === 'mixed') {
|
||||
return {
|
||||
pending: 'agentStream.ragPipeline.searchingMixed',
|
||||
pendingWithQuery: 'agentStream.ragPipeline.searchingMixedWithQuery',
|
||||
done: 'agentStream.toolStatus.searchMixed',
|
||||
doneFailed: 'agentStream.toolStatus.searchMixedFailed',
|
||||
}
|
||||
}
|
||||
return {
|
||||
pending: 'agentStream.ragPipeline.searching',
|
||||
pendingWithQuery: 'agentStream.ragPipeline.searchingWithQuery',
|
||||
done: 'agentStream.toolStatus.searchKb',
|
||||
doneFailed: 'agentStream.toolStatus.searchKbFailed',
|
||||
}
|
||||
}
|
||||
|
||||
export function getKnowledgeSearchSummaryHtml(
|
||||
t: ComposerTranslation,
|
||||
toolData: Record<string, unknown> | null | undefined,
|
||||
@@ -81,6 +121,14 @@ export function getKnowledgeSearchSummaryHtml(
|
||||
const count = (Array.isArray(results) ? results.length : 0) || Number(toolData.count) || 0
|
||||
if (count === 0) return t('agentStream.search.noResults')
|
||||
|
||||
const searchSource = getRetrievalSearchSource(null, toolData)
|
||||
const webCount = Number(toolData.web_count) || 0
|
||||
const docCount = Number(toolData.doc_count) || 0
|
||||
|
||||
if (searchSource === 'web' || (webCount > 0 && docCount === 0)) {
|
||||
return t('agentStream.search.webResults', { count: `<strong>${count}</strong>` })
|
||||
}
|
||||
|
||||
const kbCounts = toolData.kb_counts
|
||||
const kbCount = kbCounts && typeof kbCounts === 'object' ? Object.keys(kbCounts).length : 0
|
||||
if (kbCount > 0) {
|
||||
@@ -90,6 +138,14 @@ export function getKnowledgeSearchSummaryHtml(
|
||||
})
|
||||
}
|
||||
|
||||
if (searchSource === 'mixed' && docCount > 0 && webCount > 0) {
|
||||
return t('agentStream.search.foundMixedResults', {
|
||||
count: `<strong>${count}</strong>`,
|
||||
docCount: `<strong>${docCount}</strong>`,
|
||||
webCount: `<strong>${webCount}</strong>`,
|
||||
})
|
||||
}
|
||||
|
||||
return t('agentStream.search.foundResults', { count: `<strong>${count}</strong>` })
|
||||
}
|
||||
|
||||
@@ -115,15 +171,15 @@ export function getRagPipelineStepTitle(t: ComposerTranslation, event: RagPipeli
|
||||
}
|
||||
|
||||
if (toolName === 'knowledge_search' || toolName === 'search_knowledge') {
|
||||
const searchSource = getRetrievalSearchSource(event.arguments, event.tool_data)
|
||||
const labels = getRetrievalStatusKeys(searchSource, event.success === false)
|
||||
if (pending) {
|
||||
return query
|
||||
? t('agentStream.ragPipeline.searchingWithQuery', { query })
|
||||
: t('agentStream.ragPipeline.searching')
|
||||
? t(labels.pendingWithQuery, { query })
|
||||
: t(labels.pending)
|
||||
}
|
||||
|
||||
const baseTitle = event.success === false
|
||||
? t('agentStream.toolStatus.searchKbFailed')
|
||||
: t('agentStream.toolStatus.searchKb')
|
||||
const baseTitle = event.success === false ? t(labels.doneFailed) : t(labels.done)
|
||||
return query ? `${baseTitle}:「${query}」` : baseTitle
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
/** TDesign icon names for agent / RAG pipeline tool steps. */
|
||||
export function getAgentToolIconName(toolName: string): string {
|
||||
export function getAgentToolIconName(
|
||||
toolName: string,
|
||||
searchSource?: 'knowledge' | 'web' | 'mixed',
|
||||
): string {
|
||||
if (toolName === 'thinking') {
|
||||
return 'ai-search'
|
||||
}
|
||||
if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
|
||||
if (searchSource === 'web') {
|
||||
return 'internet'
|
||||
}
|
||||
return 'data-search'
|
||||
}
|
||||
if (toolName === 'wiki_search') {
|
||||
|
||||
@@ -19,6 +19,20 @@ test('synthesizeRagPipelineToolEvents builds completed retrieval steps', () => {
|
||||
assert.equal(events[0].tool_name, 'query_understand')
|
||||
assert.equal(events[1].tool_name, 'knowledge_search')
|
||||
assert.equal(events[1].tool_data.count, 3)
|
||||
assert.equal(events[1].tool_data.search_source, 'knowledge')
|
||||
})
|
||||
|
||||
test('synthesizeRagPipelineToolEvents marks web-only references as web search', () => {
|
||||
const events = synthesizeRagPipelineToolEvents({
|
||||
knowledge_references: [
|
||||
{ chunk_type: 'web_search', knowledge_title: 'page-1' },
|
||||
{ chunk_type: 'web_search', knowledge_title: 'page-2' },
|
||||
],
|
||||
})
|
||||
|
||||
assert.equal(events[1].tool_data.search_source, 'web')
|
||||
assert.equal(events[1].tool_data.web_count, 2)
|
||||
assert.equal(events[1].tool_data.doc_count, 0)
|
||||
})
|
||||
|
||||
test('ensureRagPipelineHistoryStream restores quick-answer history after reload', () => {
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
export const RAG_PIPELINE_TOOL_NAMES = new Set(['query_understand', 'knowledge_search'])
|
||||
|
||||
type RagHistoryReference = {
|
||||
chunk_type?: string
|
||||
knowledge_id?: string
|
||||
knowledge_title?: string
|
||||
}
|
||||
|
||||
function inferRetrievalSearchSource(refs: RagHistoryReference[]): 'knowledge' | 'web' | 'mixed' {
|
||||
let docCount = 0
|
||||
let webCount = 0
|
||||
for (const ref of refs) {
|
||||
if (ref.chunk_type === 'web_search') {
|
||||
webCount++
|
||||
} else {
|
||||
docCount++
|
||||
}
|
||||
}
|
||||
if (docCount > 0 && webCount > 0) return 'mixed'
|
||||
if (webCount > 0) return 'web'
|
||||
return 'knowledge'
|
||||
}
|
||||
|
||||
type RagHistoryMessage = {
|
||||
knowledge_references?: Array<{
|
||||
chunk_type?: string
|
||||
knowledge_id?: string
|
||||
knowledge_title?: string
|
||||
}>
|
||||
knowledge_references?: RagHistoryReference[]
|
||||
agentEventStream?: Array<Record<string, unknown>>
|
||||
}
|
||||
|
||||
@@ -25,13 +42,21 @@ export function synthesizeRagPipelineToolEvents(
|
||||
): Array<Record<string, unknown>> {
|
||||
const refs = item.knowledge_references ?? []
|
||||
const kbCounts: Record<string, number> = {}
|
||||
let docCount = 0
|
||||
let webCount = 0
|
||||
|
||||
for (const ref of refs) {
|
||||
if (ref.chunk_type === 'web_search') continue
|
||||
if (ref.chunk_type === 'web_search') {
|
||||
webCount++
|
||||
continue
|
||||
}
|
||||
docCount++
|
||||
const key = ref.knowledge_id || ref.knowledge_title || 'document'
|
||||
kbCounts[key] = (kbCounts[key] || 0) + 1
|
||||
}
|
||||
|
||||
const searchSource = inferRetrievalSearchSource(refs)
|
||||
|
||||
const events: Array<Record<string, unknown>> = [
|
||||
{
|
||||
type: 'tool_call',
|
||||
@@ -46,8 +71,12 @@ export function synthesizeRagPipelineToolEvents(
|
||||
tool_name: 'knowledge_search',
|
||||
pending: false,
|
||||
success: true,
|
||||
arguments: { search_source: searchSource },
|
||||
tool_data: {
|
||||
count: refs.length,
|
||||
doc_count: docCount,
|
||||
web_count: webCount,
|
||||
search_source: searchSource,
|
||||
kb_counts: kbCounts,
|
||||
results: refs,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user