我有一个使用 GPTVectorStoreIndex
创建的现有索引。但是,当我尝试使用 insert
方法将新文档添加到现有索引时,出现以下错误:
AttributeError:“list”对象没有属性“get_text”
我更新索引的代码如下:
max_input_size = 4096
num_outputs = 5000
max_chunk_overlap = 256
chunk_size_limit = 3900
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
directory_path = "./trial_docs"
file_metadata = lambda x : {"filename": x}
reader = SimpleDirectoryReader(directory_path, file_metadata=file_metadata)
documents = reader.load_data()
print(type(documents))
index.insert(document = documents, service_context = service_context)
最佳答案
我做对了,我犯的错误是将文档作为一个整体传递,这是一个 List
对象。正确的更新方式如下
max_input_size = 4096
num_outputs = 5000
max_chunk_overlap = 256
chunk_size_limit = 3900
prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
directory_path = "./trial_docs"
file_metadata = lambda x : {"filename": x}
reader = SimpleDirectoryReader(directory_path, file_metadata=file_metadata)
documents = reader.load_data()
print(type(documents))
for d in documents:
index.insert(document = d, service_context = service_context)
关于llama-index - 我们如何将文档列表添加到 llama-index 中的现有索引中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76304374/