Find answers from the community

Updated 4 months ago

How do I query from GPTListIndex.from_documents() now?

At a glance

The community members are discussing how to query from GPTListIndex.from_documents(). A community member provides an example of how to create an index using from_documents() and then use the query() method to query the index. They also mention different query modes and response modes that can be used. However, another community member notes that the query() method is not available on the GPTListIndex object, and instead suggests using index.as_query_engine().query("my query").

Useful resources
How do I query from GPTListIndex.from_documents() now?
k
L
J
7 comments
Please stand by @Jace93 ▬D══════ﺤ as I search the knowledge base. We are experiencing especially high traffic right now and might take longer than usual. :wave:
----------------------
To query from GPTListIndex.from_documents(), you first need to create an index using the from_documents() method and then use the query() method on the created index. Here's an example:

Plain Text
from gpt_index import GPTListIndex

documents = ...  # Load your documents here
index = GPTListIndex.from_documents(documents)

response = index.query("Your query here")


You can also specify different query modes and response modes. For example:

Plain Text
response = index.query("Your query here", mode="embedding", response_mode="compact")


For more information on query modes and response modes, refer to the following extracts:

----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Kapa seems out of date somehow 😕
yeah, I got the error AttributeError: 'GPTListIndex' object has no attribute 'query'
query_engine = index.as_query_engine()

query_engine.query("my query")
Add a reply
Sign up and join the conversation on Discord