Find answers from the community

Updated 4 months ago

chunk size limt settings

At a glance
I'm trying to build an index with very small nodes, first tried to insert manually but running into some issues building the index so thought I'd try a much simpler approach, like this:

Plain Text
documents = SimpleDirectoryReader('data').load_data()
index = GPTSimpleVectorIndex.from_documents(documents, chunk_size_limit=64)
index.save_to_disk('index_list.json')


But getting TypeError: BaseGPTIndex.__init__() got an unexpected keyword argument 'chunk_size_limit' when trying to run it, has that changed recently?
V
k
3 comments
@kapa.ai give an example of setting up chunk size limit and use it to query.
Let me check the knowledge base for you. One moment! :books:
----------------------
To set up a chunk size limit and use it to query, you can follow these steps:

  1. Create a ServiceContext with a specified chunk_size_limit.
  2. Initialize an index using the ServiceContext.
  3. Query the index.
Here's an example using GPTSimpleVectorIndex:

Plain Text
from gpt_index import GPTSimpleVectorIndex, ServiceContext, SimpleDirectoryReader

# Set up the chunk size limit
chunk_size_limit = 512

# Create a ServiceContext with the specified chunk size limit
service_context = ServiceContext.from_defaults(chunk_size_limit=chunk_size_limit)

# Load documents
documents = SimpleDirectoryReader('../paul_graham_essay/data').load_data()

# Initialize the index with the ServiceContext
index = GPTSimpleVectorIndex.from_documents(documents, service_context=service_context)

# Query the index
query = 'What is most interesting about this essay?'
answer = index.query(query)

print(answer.get_formatted_sources())
print('query was:', query)
print('answer was:', answer)


In this example, the chunk_size_limit is set to 512. The ServiceContext is created with this limit and used to initialize the GPTSimpleVectorIndex. Finally, the index is queried with a given question.

Source: Building a Chatbot (https://gpt-index.readthedocs.io/en/latest/guides/tutorials/building_a_chatbot.html)
----------------------
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