
LlamaIndex • 2024-01-26
介绍 LlamaIndex 检索增强生成命令行工具
想在不写一行代码的情况下尝试检索增强生成 (RAG) 吗?我们为您准备好了!隆重推出新的 llamaindex-cli
工具,当您 pip install llama-index
时即可安装!它底层使用了 Chroma,所以您还需要 pip install chromadb
。
如何使用
- 设置
OPENAI_API_KEY
环境变量:默认情况下,此工具使用 OpenAI 的 API。因此,每当使用该工具时,您需要确保OPENAI_API_KEY
环境变量已设置 OpenAI API 密钥。
$ export OPENAI_API_KEY=<api_key>
2. 摄取一些文件:现在,您需要将工具指向一些本地文件,以便将其摄取到本地向量数据库中。在本例中,我们将摄取 LlamaIndex 的 README.md
文件
$ llamaindex-cli rag --files "./README.md"
您只能指定一个文件通配符模式,例如
$ llamaindex-cli rag --files "./docs/**/*.rst"
3. 提问:现在,您可以开始询问有关您在先前步骤中摄取的任何文档的问题
$ llamaindex-cli rag --question "What is LlamaIndex?"
LlamaIndex is a data framework that helps in ingesting, structuring, and accessing private or domain-specific data for LLM-based applications. It provides tools such as data connectors to ingest data from various sources, data indexes to structure the data, and engines for natural language access to the data. LlamaIndex follows a Retrieval-Augmented Generation (RAG) approach, where it retrieves information from data sources, adds it to the question as context, and then asks the LLM to generate an answer based on the enriched prompt. This approach overcomes the limitations of fine-tuning LLMs and provides a more cost-effective, up-to-date, and trustworthy solution for data augmentation. LlamaIndex is designed for both beginner and advanced users, with a high-level API for easy usage and lower-level APIs for customization and extension.
4. 打开聊天 REPL:您甚至可以在终端中打开一个聊天界面!只需运行 llamaindex-cli rag --chat
,即可开始询问有关您已摄取文件的问题。
随心所欲地定制它!
您可以定制 llamaindex-cli
以使用任何 LLM 模型,甚至是通过 Ollama 使用本地模型,如 Mixtral 8x7b,您还可以构建更高级的查询和检索技术。查阅文档以获取入门详情。