Show retrieved knowledge chunks in audit logs

This commit is contained in:
2026-07-09 10:29:58 +08:00
parent d6b7ec1e52
commit f39e51a4d4
9 changed files with 172 additions and 3 deletions

View File

@@ -1463,6 +1463,21 @@ function buildChatQuery() {
</el-tab-pane>
<el-tab-pane label="AI 请求" name="aiLogs">
<el-table :data="aiLogs" stripe>
<el-table-column type="expand" width="48">
<template #default="{ row }">
<section v-if="row.retrievedChunks?.length" class="retrieval-chunks">
<article v-for="chunk in row.retrievedChunks" :key="`${row.id}-${chunk.index}`" class="retrieval-chunk">
<div class="chunk-head">
<strong>#{{ chunk.index }} {{ chunk.knowledgeName || '未知知识库' }}</strong>
<span>{{ chunk.title || '未命名片段' }}</span>
</div>
<pre>{{ chunk.content }}</pre>
<a v-if="chunk.sourceUrl" :href="chunk.sourceUrl" target="_blank" rel="noreferrer">查看来源</a>
</article>
</section>
<el-empty v-else description="本条请求未保存召回片段" :image-size="64" />
</template>
</el-table-column>
<el-table-column prop="sessionId" label="会话ID" width="90" />
<el-table-column prop="modelName" label="模型" width="160" />
<el-table-column prop="knowledgeIds" label="知识库" width="120" />
@@ -1528,6 +1543,17 @@ function buildChatQuery() {
<span>耗时{{ log.costMs || '-' }}ms</span>
<span>时间{{ log.createdAt }}</span>
</div>
<section v-if="log.retrievedChunks?.length" class="retrieval-chunks">
<article v-for="chunk in log.retrievedChunks" :key="`${log.id}-${chunk.index}`" class="retrieval-chunk">
<div class="chunk-head">
<strong>#{{ chunk.index }} {{ chunk.knowledgeName || '未知知识库' }}</strong>
<span>{{ chunk.title || '未命名片段' }}</span>
</div>
<pre>{{ chunk.content }}</pre>
<a v-if="chunk.sourceUrl" :href="chunk.sourceUrl" target="_blank" rel="noreferrer">查看来源</a>
</article>
</section>
<el-empty v-else description="本条请求未保存召回片段" :image-size="64" />
<pre class="prompt-preview">{{ log.prompt || '无 Prompt 记录' }}</pre>
<p v-if="log.errorMessage" class="error-text">{{ log.errorMessage }}</p>
</el-collapse-item>

View File

@@ -712,6 +712,58 @@ textarea {
font-size: 13px;
}
.retrieval-chunks {
display: grid;
gap: 12px;
margin: 12px 0;
}
.retrieval-chunk {
padding: 12px;
border: 1px solid #dce8e4;
border-radius: 6px;
background: #fbfdfc;
}
.chunk-head {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
align-items: baseline;
margin-bottom: 8px;
color: #203832;
}
.chunk-head strong {
color: #0f735d;
}
.chunk-head span {
color: #60746d;
font-size: 13px;
}
.retrieval-chunk pre {
max-height: 260px;
margin: 0;
padding: 10px;
overflow: auto;
border-radius: 6px;
background: #f4f7f6;
color: #263832;
white-space: pre-wrap;
word-break: break-word;
font-family: "SFMono-Regular", Consolas, "PingFang SC", monospace;
line-height: 1.65;
}
.retrieval-chunk a {
display: inline-flex;
margin-top: 8px;
color: #0f735d;
text-decoration: none;
}
.error-text {
color: #b42318;
}

View File

@@ -133,6 +133,7 @@ export interface AiLogRecord {
modelName?: string | null;
knowledgeIds?: string | null;
retrieveCount: number;
retrievedChunks: RetrievedKnowledgeChunk[];
inputToken?: number | null;
outputToken?: number | null;
totalToken?: number | null;
@@ -143,6 +144,15 @@ export interface AiLogRecord {
createdAt: string;
}
export interface RetrievedKnowledgeChunk {
index: number;
knowledgeId?: number | null;
knowledgeName: string;
title: string;
content: string;
sourceUrl?: string | null;
}
export interface ChatDetail {
session: ChatRecord;
messages: ChatMessageRecord[];