Find answers from the community

Updated last year

Document

I'm getting Error: 'str' object has no attribute 'get_doc_id' , using below code, what I'm doing wrong ?


text_content = "The sports teams in Toronto include the Toronto Maple Leafs (NHL), Toronto Raptors (NBA), Toronto Blue Jays (MLB)"

index = SummaryIndex.from_documents(
documents=text_content,
service_context=service_context,
show_progress=True
)
query_engine = index.as_query_engine(
service_context=service_context,
text_qa_template=qa_prompt_template,
use_async=True
)

response = query_engine.query(question)
W
x
3 comments
You'll have to pass a Document object in there. Which can be done in the following way.

Plain Text
from llama_index import Document

text_list = [text1, text2, ...]
documents = [Document(text=t) for t in text_list]

# Pass this list of Documents in the index
index = SummaryIndex.from_documents(
    documents=documents,
    service_context=service_context,
    show_progress=True
)
query_engine = index.as_query_engine(
    service_context=service_context,
    text_qa_template=qa_prompt_template,
    use_async=True
)

response = query_engine.query(question)
Thanks @WhiteFang_Jr and what will have best results DocumentSummaryIndex or SummaryIndex, I want to put a question and use the entire document as context ?
Add a reply
Sign up and join the conversation on Discord