Chat - 출처 및 인용
Chat - 출처 및 인용 (Sources and citations)
검색 증강 생성(RAG) 애플리케이션을 위해 소스 파트로 참조 링크와 문서 발췌문을 표시해요.
본문
소스 파트는 AI 어시스턴트가 자신의 출처를 인용할 수 있게 해줘요. 두 가지 파트 유형이 흔한 인용 패턴을 다뤄요: URL 참조와 문서 발췌문.
소스 파트 렌더링 (Rendering source parts)
아래 데모는 source-url과 source-document 파트를 담은 어시스턴트 메시지를 시드(seed)로 사용해요. 둘 다 내장 파트 렌더러가 자동으로 렌더링해요:
'use client';
import * as React from 'react';
import Box from '@mui/material/Box';
import { ChatConversation, ChatMessageList } from '@mui/x-chat';
import { ChatProvider } from '@mui/x-chat/headless';
import type {
ChatConversation as ChatConversationType,
ChatMessage,
} from '@mui/x-chat/headless';
import { createEchoAdapter } from 'docs/data/chat/core/examples/shared/demoUtils';
const adapter = createEchoAdapter();
const conversation: ChatConversationType = {
id: 'sources-demo',
title: 'Sources and citations',
participants: [],
readState: 'read',
unreadCount: 0,
lastMessageAt: '2026-03-15T10:00:00.000Z',
};
const messages: ChatMessage[] = [
{
id: 'msg-1',
conversationId: conversation.id,
role: 'user',
status: 'sent',
createdAt: '2026-03-15T09:59:00.000Z',
parts: [{ type: 'text', text: 'How do I override the source link styles?' }],
},
{
id: 'msg-2',
conversationId: conversation.id,
role: 'assistant',
status: 'sent',
createdAt: '2026-03-15T10:00:00.000Z',
parts: [
{
type: 'text',
text: 'According to the documentation [1], use the partProps slot overrides. The theming guide covers the resolution order:',
},
{
type: 'source-url',
sourceId: 'src-1',
url: 'https://mui.com/x/react-chat/',
title: 'MUI X Chat documentation',
},
{
type: 'source-document',
sourceId: 'src-2',
title: 'Theming guide — slot overrides',
text: 'Slots are resolved in order: theme defaults first, then component-level props.',
},
],
},
];
export default function SourcePartsDemo() {
return (
<ChatProvider
adapter={adapter}
initialActiveConversationId={conversation.id}
initialConversations={[conversation]}
initialMessages={messages}
>
<Box
sx={{
height: 360,
overflow: 'hidden',
}}
>
<ChatConversation>
<ChatMessageList />
</ChatConversation>
</Box>
</ChatProvider>
);
}
Source URL 파트 (Source URL parts)
ChatSourceUrlMessagePart은 외부 리소스에 대한 링크를 나타내요:
interface ChatSourceUrlMessagePart {
type: 'source-url';
sourceId: string;
url: string;
title?: string;
}
| 필드 | 타입 | 설명 |
|---|---|---|
type |
'source-url' |
파트 타입 유니언을 구분하는 판별자(discriminant) |
sourceId |
string |
소스에 대한 안정적인 식별자 |
url |
string |
소스의 URL |
title |
string |
선택적 표시 제목(없으면 URL로 대체) |
중복된 sourceId 값은 자동으로 병합되지 않아요—필요하다면 어댑터에서 중복을 제거하세요.
렌더링 (Rendering)
Source URL은 새 탭에서 열리는 외부 링크 아이콘이 있는 인라인 링크로 렌더링돼요. 링크 텍스트는 사용 가능하면 title을, 그렇지 않으면 원본 url을 보여줘요.
// How it appears in the parts array
const message: ChatMessage = {
id: 'msg-1',
role: 'assistant',
parts: [
{ type: 'text', text: 'According to the documentation [^1]:' },
{
type: 'source-url',
sourceId: 'src-1',
url: 'https://mui.com/x/react-chat/',
title: 'MUI X Chat Documentation',
},
],
};
[^1] 각주 표시는 내장 마크다운 파서에 의해 위첨자로 렌더링돼요 (Text and Markdown 참고). 이는 시각적 관례일 뿐이에요—뒤따르는 소스 파트에 자동으로 연결되지 않으므로, 표시자와 소스의 순서는 직접 맞춰주세요.
슬롯 (Slots)
Source URL 파트는 SourceUrlPart 컴포넌트(@mui/x-chat/headless에서 내보냄)가 렌더링하며, 세 개의 슬롯을 노출해요:
| 슬롯 | 기본 요소 | 설명 |
|---|---|---|
root |
span |
외부 컨테이너 |
icon |
span |
외부 링크 아이콘 래퍼 |
link |
a |
클릭 가능한 소스 링크 |
:::info
소스 링크는 rel="noreferrer noopener"이 자동으로 적용된 상태로 새 탭에서 열려요. 접근 가능한 이름은 제공된 경우 title이고, 없으면 원본 url로 대체돼요—스크린 리더가 의미 있는 내용을 알려주도록 제목을 제공하세요. 외부 링크 아이콘은 aria-hidden이므로 알려지지 않아요.
:::
Source document 파트 (Source document parts)
ChatSourceDocumentMessagePart은 인라인 문서 발췌문을 나타내요—AI 어시스턴트가 검색된 문서에서 인용할 때 유용해요:
interface ChatSourceDocumentMessagePart {
type: 'source-document';
sourceId: string;
title?: string;
text?: string;
}
| 필드 | 타입 | 설명 |
|---|---|---|
type |
'source-document' |
파트 타입 유니언을 구분하는 판별자 |
sourceId |
string |
소스에 대한 안정적인 식별자 |
title |
string |
선택적 문서 또는 섹션 제목 |
text |
string |
선택적 발췌문 텍스트 |
렌더링 (Rendering)
기본 렌더러는 제목을 굵게, 발췌문 텍스트를 그 아래에, 테두리가 있는 카드로 감싸 보여줘요.
// How it appears in the parts array
const message: ChatMessage = {
id: 'msg-2',
role: 'assistant',
parts: [
{ type: 'text', text: 'The theming guide describes the override order:' },
{
type: 'source-document',
sourceId: 'src-2',
title: 'Theming guide — slot overrides',
text: 'Slots are resolved in order: theme defaults, then component props.',
},
],
};
슬롯 (Slots)
Document 파트는 SourceDocumentPart 컴포넌트(@mui/x-chat/headless에서 내보냄)가 렌더링하며, 세 개의 슬롯을 노출해요:
| 슬롯 | 기본 요소 | 설명 |
|---|---|---|
root |
div |
외부 컨테이너 (카드) |
title |
div |
문서 제목 |
excerpt |
div |
발췌문 텍스트 |
스트리밍 (Streaming)
소스 파트는 단일 청크로 도착해요—증분적으로 전달되지 않아요:
// URL source chunk
{ type: 'source-url', sourceId: 'src-1', url: 'https://example.com', title: 'Example' }
// Document source chunk
{ type: 'source-document', sourceId: 'src-2', title: 'API Reference', text: 'The method accepts…' }
소스 렌더링 커스터마이즈 (Customizing source rendering)
아래 스니펫은 이미 adapter가 구성되어 있다고 가정해요—설정은 Backend adapters를 참고하세요.
ChatBox에서 slotProps.messageContent.partProps를 통해 소스 파트 렌더링을 덮어쓸 수 있어요:
<ChatBox
adapter={adapter}
slotProps={{
messageContent: {
partProps: {
'source-url': {
slots: { root: MyCustomSourceUrlRoot },
},
'source-document': {
slots: { root: MyCustomSourceDocRoot },
},
},
},
}}
/>
소스 렌더링을 완전히 커스터마이즈하려면 partRenderers prop을 통해 커스텀 렌더러를 등록하세요:
<ChatBox
adapter={adapter}
partRenderers={{
'source-url': ({ part }) => (
<a href={part.url} className="citation-link">
[{part.sourceId}] {part.title ?? part.url}
</a>
),
}}
/>
headless 프리미티브를 직접 구성할 때는 @mui/x-chat/headless의 ChatProvider에 같은 partRenderers 맵을 전달하세요—Custom parts 참고.
독립형 소스 목록 (Standalone sources list)
소스 파트는 메시지에서 나타나는 위치에 인라인으로 렌더링돼요. 답변 끝에 통합된 인용 목록을 제시하려면—대부분의 RAG UI가 사용하는 패턴—독립형 ChatMessageSources와 ChatMessageSource 컴포넌트를 직접 구성하세요. 이들은 표현용 프리미티브예요: 수집된 소스를 매핑하면 되고, 메시지 파트에 의해 구동되지는 않아요.
ChatMessageSources는 순서 있는 목록(ol/li)을 렌더링하므로, 보조 기술(AT)이 인용 개수와 위치를 알려줘요.
import * as React from 'react';
import { ChatMessageSource, ChatMessageSources } from '@mui/x-chat';
import { PlaygroundCard } from 'docs/src/modules/components/chat-playground/PlaygroundCard';
import {
DividerLabel,
NumberControl,
TextControl,
} from 'docs/src/modules/components/chat-playground/controls';
import {
useCustomizations,
type CustomizationDef,
} from 'docs/src/modules/components/chat-playground/useCustomizations';
const POOL = [
{ href: 'https://mui.com/x/react-chat/', title: 'MUI X Chat overview' },
{
href: 'https://mui.com/material-ui/customization/theming/',
title: 'Material UI theming',
},
{ href: 'https://mui.com/x/api/chat/chat-box/', title: 'ChatBox API' },
{ href: 'https://mui.com/x/react-chat/material/', title: 'Material adapter' },
{ href: 'https://mui.com/system/styled/', title: 'styled() utility' },
];
type ClassKey = 'root' | 'label' | 'list';
const CLASS_DEFS: ReadonlyArray<CustomizationDef<ClassKey>> = [
{ name: 'root', description: 'The sources container.' },
{
name: 'label',
selector: '.MuiChatMessageSources-label',
description: 'The "Sources" label above the list.',
},
{
name: 'list',
selector: '.MuiChatMessageSources-list',
description: 'The ordered list element.',
},
];
export default function ChatMessageSourcesPlayground() {
const [count, setCount] = React.useState(3);
const [label, setLabel] = React.useState('Sources');
const classesCustomizations = useCustomizations<ClassKey>(CLASS_DEFS);
const rootSx = classesCustomizations.toClassesSx();
return (
<PlaygroundCard
title="ChatMessageSources"
description="Citation list for an assistant answer (RAG)."
previewMinHeight={200}
classCustomizations={classesCustomizations.customizations}
onClassesReset={classesCustomizations.reset}
controls={
<React.Fragment>
<DividerLabel>props</DividerLabel>
<TextControl label="label" value={label} onChange={setLabel} />
<DividerLabel>fixture data</DividerLabel>
<NumberControl
label="source count"
value={count}
min={1}
max={POOL.length}
onChange={setCount}
/>
</React.Fragment>
}
preview={
<ChatMessageSources label={label} sx={rootSx}>
{POOL.slice(0, count).map((source, i) => (
<ChatMessageSource
key={source.href}
index={i + 1}
href={source.href}
title={source.title}
/>
))}
</ChatMessageSources>
}
/>
);
}
함께 보기 (See also)
- Text and Markdown - 소스를 참조하는 텍스트 내용에 대한 자세한 내용
- Custom parts - 완전히 커스텀한 인용 UI를 만드는 자세한 내용
ChatMessageContent API
데모 (Demos)
이 React 컴포넌트의 사용 예제와 자세한 내용은 컴포넌트 데모 페이지를 방문하세요:
- Chat - Reasoning
- Chat - Step Tracking
- Chat - Tool calling
- Chat - Messages
- Chat - Custom parts
- Chat - Files and images
- Chat - Sources and citations
- Chat - Text and markdown
가져오기 (Import)
import { ChatMessageContent } from '@mui/x-chat/ChatMessage';
// or
import { ChatMessageContent } from '@mui/x-chat';
Props
| 이름 | 타입 | 기본값 | 필수 | 설명 |
|---|---|---|---|---|
| afterContent | node |
- | No | |
| partProps | { dynamic-tool?: { className?: string, defaultExpanded?: object, slotProps?: object, slots?: object, toolSlotProps?: object, toolSlots?: object }, file?: { className?: string, slotProps?: object, slots?: object }, reasoning?: { className?: string, slotProps?: object, slots?: object }, source-document?: { className?: string, slotProps?: object, slots?: object }, source-url?: { className?: string, slotProps?: object, slots?: object }, text?: { renderText?: func }, tool?: { className?: string, defaultExpanded?: object, slotProps?: object, slots?: object, toolSlotProps?: object, toolSlots?: object } } |
- | No |
참고:
ref는 루트 요소로 전달돼요.
제공되는 다른 props는 모두 루트 요소(네이티브 요소)로 전달돼요.
소스 코드 (Source code)
이 페이지에서 정보를 찾지 못했다면, 자세한 내용을 위해 컴포넌트의 구현을 살펴보는 것을 고려해보세요.
ChatMessageSource API
데모 (Demos)
이 React 컴포넌트의 사용 예제와 자세한 내용은 컴포넌트 데모 페이지를 방문하세요:
가져오기 (Import)
import { ChatMessageSource } from '@mui/x-chat/ChatMessageSources';
// or
import { ChatMessageSource } from '@mui/x-chat';
Props
| 이름 | 타입 | 기본값 | 필수 | 설명 |
|---|---|---|---|---|
| href | string |
- | Yes | |
| index | number |
- | No | |
| title | string |
- | No |
참고:
ref는 루트 요소로 전달돼요.
슬롯 (Slots)
| 이름 | 기본값 | 클래스 | 설명 |
|---|---|---|---|
| root | 'li' |
.MuiChatMessageSource-root |
루트 목록 항목 요소 |
| index | 'span' |
.MuiChatMessageSource-index |
숫자 인덱스 배지 |
| link | 'a' |
.MuiChatMessageSource-link |
앵커 링크 |
소스 코드 (Source code)
이 페이지에서 정보를 찾지 못했다면, 자세한 내용을 위해 컴포넌트의 구현을 살펴보는 것을 고려해보세요.
ChatMessageSources API
데모 (Demos)
이 React 컴포넌트의 사용 예제와 자세한 내용은 컴포넌트 데모 페이지를 방문하세요:
가져오기 (Import)
import { ChatMessageSources } from '@mui/x-chat/ChatMessageSources';
// or
import { ChatMessageSources } from '@mui/x-chat';
Props
| 이름 | 타입 | 기본값 | 필수 | 설명 |
|---|---|---|---|---|
| label | string |
'Sources' |
No |
참고:
ref는 루트 요소로 전달돼요.
제공되는 다른 props는 모두 루트 요소(네이티브 요소)로 전달돼요.
슬롯 (Slots)
| 이름 | 기본값 | 클래스 | 설명 |
|---|---|---|---|
| root | 'div' |
.MuiChatMessageSources-root |
루트 컨테이너 요소 |
| label | 'p' |
.MuiChatMessageSources-label |
목록 위에 표시되는 레이블 요소 |
| list | 'ol' |
.MuiChatMessageSources-list |
소스 항목을 감싸는 순서 있는 목록 |
소스 코드 (Source code)
이 페이지에서 정보를 찾지 못했다면, 자세한 내용을 위해 컴포넌트의 구현을 살펴보는 것을 고려해보세요.