> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # ExtractParams ExtractParams는 LLM 분석을 사용하여 문서 청크에서 메타데이터 추출을 구성합니다. ## 예 ```typescript import { MDocument } from '@mastra/rag' const doc = MDocument.fromText(text) const chunks = await doc.chunk({ extract: { title: true, // Extract titles using default settings summary: true, // Generate summaries using default settings keywords: true, // Extract keywords using default settings }, }) // Example output: // chunks[0].metadata = { // documentTitle: "AI Systems Overview", // sectionSummary: "Overview of artificial intelligence concepts and applications", // excerptKeywords: "KEYWORDS: AI, machine learning, algorithms" // } ``` ## 매개변수 `extract` 매개변수는 다음 필드를 허용합니다. **title** (`boolean | TitleExtractorsArgs`): 제목 추출을 활성화합니다. 기본 설정을 사용하려면 true로 설정하고, 그렇지 않으면 사용자 지정 구성을 제공하세요. **summary** (`boolean | SummaryExtractArgs`): 요약 추출을 활성화합니다. 기본 설정을 사용하려면 true로 설정하고, 그렇지 않으면 사용자 지정 구성을 제공하세요. **questions** (`boolean | QuestionAnswerExtractArgs`): 질문 생성을 활성화합니다. 기본 설정을 사용하려면 true로 설정하고, 그렇지 않으면 사용자 지정 구성을 제공하세요. **keywords** (`boolean | KeywordExtractArgs`): 키워드 추출을 활성화합니다. 기본 설정을 사용하려면 true로 설정하고, 그렇지 않으면 사용자 지정 구성을 제공하세요. **schema** (`SchemaExtractArgs`): Zod 스키마를 사용한 구조화된 메타데이터 추출을 활성화합니다. ## 추출기 인수 ### `TitleExtractorsArgs` **llm** (`MastraLanguageModel`): 제목 추출에 사용할 AI SDK 언어 Model입니다. **nodes** (`number`): 추출할 제목 노드 수입니다. **nodeTemplate** (`string`): 제목 노드 추출용 사용자 지정 Prompt 템플릿입니다. {context} 플레이스홀더를 포함해야 합니다. **combineTemplate** (`string`): 제목 결합용 사용자 지정 Prompt 템플릿입니다. {context} 플레이스홀더를 포함해야 합니다. ### `SummaryExtractArgs` **llm** (`MastraLanguageModel`): 요약 추출에 사용할 AI SDK 언어 Model입니다. **summaries** (`('self' | 'prev' | 'next')[]`): 생성할 요약 유형 목록입니다. 'self'(현재 청크), 'prev'(이전 청크), 'next'(다음 청크)만 포함할 수 있습니다. **promptTemplate** (`string`): 요약 생성용 사용자 지정 Prompt 템플릿입니다. {context} 플레이스홀더를 포함해야 합니다. ### `QuestionAnswerExtractArgs` **llm** (`MastraLanguageModel`): 질문 생성에 사용할 AI SDK 언어 Model입니다. **questions** (`number`): 생성할 질문 수입니다. **promptTemplate** (`string`): 질문 생성용 사용자 지정 Prompt 템플릿입니다. {context} 및 {numQuestions} 플레이스홀더를 모두 포함해야 합니다. **embeddingOnly** (`boolean`): true이면 실제 질문 없이 임베딩만 생성합니다. ### `KeywordExtractArgs` **llm** (`MastraLanguageModel`): 키워드 추출에 사용할 AI SDK 언어 Model입니다. **keywords** (`number`): 추출할 키워드 수입니다. **promptTemplate** (`string`): 키워드 추출용 사용자 지정 Prompt 템플릿입니다. {context} 및 {maxKeywords} 플레이스홀더를 모두 포함해야 합니다. ### `SchemaExtractArgs` **schema** (`ZodType`): 추출할 데이터의 구조를 정의하는 Zod 스키마입니다. **llm** (`MastraLanguageModel`): 추출에 사용할 AI SDK 언어 Model입니다. **instructions** (`string`): 추출할 항목을 LLM에 지정하는 지침입니다. **metadataKey** (`string`): 추출 결과를 중첩할 키입니다. 생략하면 결과가 메타데이터 객체에 펼쳐집니다. ## 고급 예 ```typescript import { MDocument } from '@mastra/rag' const doc = MDocument.fromText(text) const chunks = await doc.chunk({ extract: { // Title extraction with custom settings title: { nodes: 2, // Extract 2 title nodes nodeTemplate: 'Generate a title for this: {context}', combineTemplate: 'Combine these titles: {context}', }, // Summary extraction with custom settings summary: { summaries: ['self'], // Generate summaries for current chunk promptTemplate: 'Summarize this: {context}', }, // Question generation with custom settings questions: { questions: 3, // Generate 3 questions promptTemplate: 'Generate {numQuestions} questions about: {context}', embeddingOnly: false, }, // Keyword extraction with custom settings keywords: { keywords: 5, // Extract 5 keywords promptTemplate: 'Extract {maxKeywords} key terms from: {context}', }, // Schema extraction with Zod schema: { schema: z.object({ productName: z.string(), category: z.enum(['electronics', 'clothing']), }), instructions: 'Extract product information.', metadataKey: 'product', }, }, }) // Example output: // chunks[0].metadata = { // documentTitle: "AI in Modern Computing", // sectionSummary: "Overview of AI concepts and their applications in computing", // questionsThisExcerptCanAnswer: "1. What is machine learning?\n2. How do neural networks work?", // excerptKeywords: "1. Machine learning\n2. Neural networks\n3. Training data", // product: { // productName: "Neural Net 2000", // category: "electronics" // } // } ``` ## 제목 추출을 위한 문서 그룹화 `TitleExtractor`를 사용할 때 각 청크의 `metadata` 필드에 공유 `docId`를 지정하여 여러 청크를 그룹화한 후 제목을 추출할 수 있습니다. 동일한 `docId`를 가진 모든 청크에는 동일한 추출 제목이 적용됩니다. `docId`를 설정하지 않으면 각 청크가 제목 추출을 위한 별도의 문서로 처리됩니다. **예:** ```ts import { MDocument } from '@mastra/rag' const doc = new MDocument({ docs: [ { text: 'chunk 1', metadata: { docId: 'docA' } }, { text: 'chunk 2', metadata: { docId: 'docA' } }, { text: 'chunk 3', metadata: { docId: 'docB' } }, ], type: 'text', }) await doc.extractMetadata({ title: true }) // The first two chunks will share a title, while the third chunk will be assigned a separate title. ```