Find answers from the community

Updated last year

i want to gen questions to my nodes with metadata "questions_this_excerpt_can_answer"

At a glance
@kapa.ai i want to gen questions to my nodes with metadata "questions_this_excerpt_can_answer"
k
2 comments
Please stand by @AnoDy as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To generate questions for your nodes with the metadata "questions_this_excerpt_can_answer", you can use the QuestionsAnsweredExtractor from the MetadataExtractor modules in LlamaIndex. Here is a step-by-step guide on how to do it:

  1. Import the necessary modules:
Plain Text
from llama_index.node_parser import SimpleNodeParser
from llama_index.node_parser.extractors import (
    MetadataExtractor,
    QuestionsAnsweredExtractor
)
from llama_index.text_splitter import TokenTextSplitter


  1. Initialize the TokenTextSplitter and MetadataExtractor:
Plain Text
text_splitter = TokenTextSplitter(separator=" ", chunk_size=512, chunk_overlap=128)
metadata_extractor = MetadataExtractor(
    extractors=[
        QuestionsAnsweredExtractor(questions=3),
    ],
)


  1. Create a SimpleNodeParser and extract nodes from your documents:
Plain Text
node_parser = SimpleNodeParser.from_defaults(
    text_splitter=text_splitter,
    metadata_extractor=metadata_extractor,
)
# assume documents are defined -> extract nodes
nodes = node_parser.get_nodes_from_documents(documents)


This will generate questions for each node and store them in the metadata field "questions_this_excerpt_can_answer".

For more details, you can refer to the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord