Skip to content
Latestv1.0.60

AiSources Knowledge Base Attribution

inline mode

Suitable for embedding below conversation bubbles, hover to preview summary.

card mode

Displays full attribution details, supports maxVisible to control default display count, expendable for more.

badge mode

Minimalist badge, click to pop up side drawer for details, suitable for space-constrained scenarios.

Citation Jump & Highlight

By getting the component instance and calling the scrollToSource(id) method, you can precisely jump from the citation in the main text to the corresponding source item and trigger a highlight micro-animation.

API

Props

AttributeTypeDefaultDescription
sourcesAiSourceItem[][]Source data list
mode'inline' | 'card' | 'badge''inline'Display mode
maxVisiblenumber5Default display count
showScorebooleantrueWhether to show relevance score
showFileTypebooleantrueWhether to show file type icon
themeOverridesComponentThemeVars-Theme overrides

AiSourceItem

FieldTypeDescription
idstring | numberUnique ID (also shown as source number)
titlestringSource title
urlstringSource URL
sourcestringSource website/doc name
scorenumberMatch relevance (0-1)
excerptstringSummary/Reference snippet
fileType'web' | 'pdf' | 'doc' | 'xlsx' | 'code' | stringFile type

Events

Event NameParamsDescription
click(source: AiSourceItem)Clicked source item
open(source: AiSourceItem)Clicked to view original source

Methods

Method NameParamsDescription
scrollToSource(id: string | number)Scroll to the specified source item and trigger the highlight

Theme Variables

CSS VariableDescriptionDefault
--yh-ai-sources-badge-bgBadge background colorvar(--yh-color-primary-light-9)
--yh-ai-sources-badge-colorBadge text colorvar(--yh-color-primary)
--yh-ai-sources-card-bgCard background colorvar(--yh-bg-color)
--yh-ai-sources-drawer-widthSide drawer width380px
--yh-ai-sources-score-highHigh relevance colorvar(--yh-color-success)
--yh-ai-sources-score-midMedium relevance colorvar(--yh-color-primary)
vue
<yh-ai-sources
  :sources="sources"
  mode="card"
  :theme-overrides="{
    aiSourcesCardBg: '#f0f9ff',
    aiSourcesDrawerWidth: '460px'
  }"
/>

Nuxt Support

Configuration

ts
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@yh-ui/nuxt']
  // YH-UI CSS is injected by default; only configure yhUI.importStyle when disabling auto styles
})

RAG Retrieval Scene Example

vue
<!-- components/AiReply.vue -->
<script setup lang="ts">
import type { AiSourceItem } from '@yh-ui/components'

const props = defineProps<{
  content: string
  sources?: AiSourceItem[]
>()

const handleOpenSource = (source: AiSourceItem) => {
  // Open original source document
  window.open(source.url, '_blank')
}
</script>

<template>
  <div class="ai-reply">
    <div class="ai-reply__content">{{ content }}</div>
    <!-- Show RAG attribution -->
    <YhAiSources
      v-if="sources && sources.length"
      :sources="sources"
      mode="inline"
      :show-score="true"
      @open="handleOpenSource"
    />
  </div>
</template>

SSR Considerations

The side drawer in badge mode uses <Teleport to="body">, which needs to be used with <ClientOnly> in SSR environments:

vue
<ClientOnly>
  <YhAiSources :sources="sources" mode="badge" />
</ClientOnly>

Released under the MIT License.