LlamaIndex常见问题解答(FAQ):自定义你的LLM应用
在本节中,我们将从你为入门示例编写的代码开始,展示最常见的自定义方法,以满足你的用例需求。
提示
如果你还没有安装LlamaIndex并完成入门教程,请先完成这些步骤。如果你遇到不认识的术语,请查看高级概念。
基础代码
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
常见问题及解决方案
1. 我想将文档解析成更小的块
全局设置
from llama_index.core import Settings
Settings.chunk_size = 512
局部设置
from llama_index.core.node_parser import SentenceSplitter
index = VectorStoreIndex.from_documents(
documents, transformations=[SentenceSplitter(chunk_size=512)