在python-flask应用程序中尝试时,干草堆搜索中可能会出现内存错误的原因是什么



我在弹性搜索中索引了大约1000个文档。当我尝试用haystack搜索进行查询时,它会返回文件作为输出,但在连续使用5次后出现内存错误。并且程序的执行停止。我已经附上了这里使用的代码。

document_store = ElasticsearchDocumentStore(host="localhost", username="", password="", index="document")
json_object = open("doc_json_file.json")
data_json = json.load(json_object)
json_object.close()
document_store.write_documents(data_json)
retriever = TfidfRetriever(document_store=document_store)
reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2", use_gpu=True)
pipe = ExtractiveQAPipeline(reader, retriever)
prediction = pipe.run(query=str(query), params={"Retriever": {"top_k": 20}, "Reader": {"top_k": 20}})
return prediction

文件名和文件内容存储在json文件中。下面是错误日志

OSError: [WinError 1455] The paging file is too small for this operation to complete
from .netcdf import netcdf_file, netcdf_variable
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 818, in get_code
File "<frozen importlib._bootstrap_external>", line 917, in get_data
MemoryError
from pandas._libs.interval import Interval
ImportError: DLL load failed: The paging file is too small for this operation to complete.

如果使用ElasticsearchDocumentStore,最好使用BM25RetrieverTfidfRetriever是一个更简单的版本,它不需要像Elasticsearch那样的反向索引数据库。

不利的是,它必须将任何索引数据保存在内存中,这可能会导致非常高的内存压力。BM25RetrieverElasticsearchDocumentStore的组合使用了几乎相同(但稍微优越(的检索模型,并且不会有这个问题。

最新更新