Skip to content

元数据提取使用模式#

您可以使用LLMs来使用我们的Metadata Extractor模块自动提取元数据。

我们的元数据提取器模块包括以下“特征提取器”:

  • SummaryExtractor - 自动提取一组节点的摘要
  • QuestionsAnsweredExtractor - 提取每个节点可以回答的一组问题
  • TitleExtractor - 在每个节点的上下文中提取标题
  • EntityExtractor - 提取内容中提到的实体(即地点、人物、事物的名称)

然后,您可以将Metadata Extractor与我们的节点解析器进行链接:

from llama_index.core.extractors import (
    TitleExtractor,
    QuestionsAnsweredExtractor,
)
from llama_index.core.node_parser import TokenTextSplitter

text_splitter = TokenTextSplitter(
    separator=" ", chunk_size=512, chunk_overlap=128
)
title_extractor = TitleExtractor(nodes=5)
qa_extractor = QuestionsAnsweredExtractor(questions=3)

# 假设文档已定义 -> 提取节点
from llama_index.core.ingestion import IngestionPipeline

pipeline = IngestionPipeline(
    transformations=[text_splitter, title_extractor, qa_extractor]
)

nodes = pipeline.run(
    documents=documents,
    in_place=True,
    show_progress=True,
)

或者插入到索引中:

from llama_index.core import VectorStoreIndex

index = VectorStoreIndex.from_documents(
    documents, transformations=[text_splitter, title_extractor, qa_extractor]
)

资源#