from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
# Load documents
documents = SimpleDirectoryReader("../../examples/data/paul_graham").load_data()
# Build index with a smaller batch size to limit resource usage
index = VectorStoreIndex.from_documents(documents, insert_batch_size=512)
2条答案
按热度按时间hgqdbh6s1#
你好@atlas-comstock!我是一个机器人,可以帮助你解决任何问题或疑问。如果你需要帮助或有任何问题,请随时提问!
为了限制
VectorStoreIndex
的from_documents
资源使用,你可以调整向量生成和插入的批处理大小。默认情况下,VectorStoreIndex
以2048个节点的批次生成和插入向量。如果你的内存受限,可以通过传递insert_batch_size
参数来降低此批处理大小。以下是一个示例:
此外,如果你使用的是Vectra后端,可以使用
parallelize_ingest
参数来控制摄取过程是否应该并行化。这有助于更有效地管理资源使用。以下是Vectra的示例:
要更精细地控制资源使用,可以使用低级API自定义存储上下文。这允许你管理导入的文档、嵌入向量和索引元数据的存储位置,从而有助于优化资源使用。
以下是使用低级API的示例:
这些调整有助于更有效地管理内存和处理资源,特别是在处理大型数据集或有限系统资源时。此外,
VectorStoreIndex
类提供了异步方法用于嵌入和添加节点,这可以利用异步处理1(https://github.com/run-llama/llama_index/blob/main/docs/docs/module_guides/indexing/vector_store_index.md)2(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/indices/managed/vectara/base.py)3(https://github.com/run-llama/llama_index/blob/main/docs/docs/module_guides/storing/customization.md)4(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/indices/vector_store/base.py)进一步优化资源使用。wi3ka0sx2#
很难说,除非看到你的代码。
如果你使用本地嵌入,你可能需要设置批处理大小。例如:
HuggingFaceEmbedding(..., embed_batch_size=2)
如果你索引大量数据,你可能需要使用专用的向量存储集成,而不是使用默认的内存选项。