首页 > 其他分享 >LlamaIndex 常见问题解答(FAQ)

LlamaIndex 常见问题解答(FAQ)

时间:2024-04-14 23:12:25浏览次数:22  
标签:engine index documents FAQ LlamaIndex llama query 问题解答 response

 

提示:如果您尚未完成,请安装 LlamaIndex 并完成起步教程。遇到不熟悉的术语时,请参考高层次概念部分。

在这个章节中,我们将从您为起步示例编写的代码开始,展示您可能希望针对不同应用场景对其进行的常见定制方法:

python   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)

“我想将文档拆分为更小的片段”

python   # 全局设置 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)] )

“我想使用不同的向量存储”

首先,您可以安装您想使用的向量存储。例如,要使用 Chroma 作为向量存储,您可以使用 pip 进行安装:

bash   pip install llama-index-vector-stores-chroma

要了解所有可用集成,请访问 LlamaHub。

然后,在代码中使用它:

python   import chromadb from llama_index.vector_stores.chroma import ChromaVectorStore from llama_index.core import StorageContext chroma_client = chromadb.PersistentClient() chroma_collection = chroma_client.create_collection("quickstart") vector_store = ChromaVectorStore(chroma_collection=chroma_collection) storage_context = StorageContext.from_defaults(vector_store=vector_store) # 存储上下文定义了文档、嵌入和索引的存储后端。您可以了解更多关于存储及其定制方法。 from llama_index.core import VectorStoreIndex, SimpleDirectoryReader documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents( documents, storage_context=storage_context ) query_engine = index.as_query_engine() response = query_engine.query("What did the author do growing up?") print(response)

“查询时我想获取更多上下文”

python   from llama_index.core import VectorStoreIndex, SimpleDirectoryReader documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine(similarity_top_k=5) response = query_engine.query("What did the author do growing up?") print(response) # as_query_engine 在索引之上构建了一个默认的检索器和查询引擎。您可以通过传入关键字参数来配置检索器和查询引擎。这里我们配置检索器返回最相似的前5个文档(而非默认的2个)。您可以了解更多关于检索器和查询引擎的信息。

“我想使用不同的 LLM”

python   # 全局设置 from llama_index.core import Settings from llama_index.llms.ollama import Ollama Settings.llm = Ollama(model="mistral", request_timeout=60.0) # 局部设置 index.as_query_engine(llm=Ollama(model="mistral", request_timeout=60.0)) # 您可以了解更多关于定制 LLM 的信息。

“我想使用不同的响应模式”

python   from llama_index.core import VectorStoreIndex, SimpleDirectoryReader documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine(response_mode="tree_summarize") response = query_engine.query("What did the author do growing up?") print(response) # 您可以了解更多关于查询引擎和响应模式的信息。

“我想以流式方式返回响应”

python   from llama_index.core import VectorStoreIndex, SimpleDirectoryReader documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_query_engine(streaming=True) response = query_engine.query("What did the author do growing up?") response.print_response_stream() # 您可以了解更多关于流式响应的信息。

“我想要一个聊天机器人而非问答系统”

python   from llama_index.core import VectorStoreIndex, SimpleDirectoryReader documents = SimpleDirectoryReader("data").load_data() index = VectorStoreIndex.from_documents(documents) query_engine = index.as_chat_engine() response = query_engine.chat("What did the author do growing up?") print(response) response = query_engine.chat("Oh interesting, tell me more.") print(response) # 了解更多关于聊天引擎的信息。

后续步骤

  • 全面了解几乎所有的可配置项:从“理解 LlamaIndex”开始深入学习。
  • 深入了解特定模块:查阅组件指南。

 

AI 新世代

ToolChatAi

Ref:https://docs.llamaindex.ai/en/stable/getting_started/customization/

Link:https://www.cnblogs.com/farwish/p/18133698

标签:engine,index,documents,FAQ,LlamaIndex,llama,query,问题解答,response
From: https://www.cnblogs.com/farwish/p/18133698

相关文章

  • RAG 工具和框架介绍: Haystack、 LangChain 和 LlamaIndex
     Haystack、LangChain和LlamaIndex,以及这些工具是如何让我们轻松地构建RAG应用程序的? 我们将重点关注以下内容:HaystackLangChainLlamaIndex增强LLM那么,为什么会有这些工具存在呢?如你所知,ChatGPT和其他LLM是在某个时间点之前的一组数据上进行训练的。更重要的是,它......
  • 分享30个外贸常见的问题解答
    顶易四月海关众筹活动实时参与人数已达1835,剩余名额不多。33国海关数据仅需300,一年只卖一次,需要续费/新购请抓紧时间!1、客户:我不会再为这笔订单支付更多的费用,也不接受其他条款。外贸人:下周交货期如果你能找得到其他供货商的话,我们很乐意把生产了一半的货送到另外一个供货......
  • 【FAQ】HarmonyOS SDK 闭源开放能力 —Push Kit(3)
    1.问题描述:调用HarmonyOSAPI发送通知,能查到状态是送达终端设备,但是终端设备上没收到通知卡片。解决方案:通知应用大图标不能超过30kb,通知参数限制,参考如下:https://gitee.com/openharmony/docs/blob/a4772406c6d12809edc9bb407a9a2858b6b19e08/zh-cn/application-dev/reference/......
  • 【FAQ】HarmonyOS SDK 闭源开放能力 —Asset Store Kitx
    1.问题描述使用关键资产API需要配置SystemCapability.Security.Asset,但不知道syscap.json文件应该配置在哪里,文档也没找到。解决方案新增关键资产等API可以直接参考开发指南里的示例代码进行调用:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/asset-js-add-......
  • 问题解答:ABAP 关键字 ANY TABLE 的使用场合深入剖析
    本教程下面这篇讲述ABAP动态编程的文章,有朋友提问:127.答网友疑问:ABAPFunctionModule如何支持内表结构不确定的动态输入参数汪老师,我这边定义了一个ANYTABLE,但是报错,说是没有这个类型,我在SE38定义的时候也报错,只有用FIELD-symbols定义才不会报错,所以就很好奇为什......
  • 一次性搞定!思源字体安装、使用及常见问题解答
    环境Windows11Pro23H2Microsoft365Word2402思源宋体:v2.002思源黑体:v2.0041.结论本人非专业字体工作者,个人建议,仅供参考;先说结论,链接以及详细说明见后文安装SC版本,无其余后缀HW,VF,CN等关于HW,思源宋体没有HW版本,个人实测,非HW版本,英文数字采用比例......
  • 【RAG实践】基于 LlamaIndex 和Qwen1.5搭建基于本地知识库的问答机器人
    什么是RAGLLM会产生误导性的“幻觉”,依赖的信息可能过时,处理特定知识时效率不高,缺乏专业领域的深度洞察,同时在推理能力上也有所欠缺。正是在这样的背景下,检索增强生成技术(Retrieval-AugmentedGeneration,RAG)应时而生,成为AI时代的一大趋势。RAG通过在语言模型生成答案......
  • RAG实战6-如何在LlamaIndex中使用自己搭建的API
    RAG实战6-如何在LlamaIndex使用自己搭建的大模型API在搭建一个大模型API服务中,我们介绍了如何使用SWIFT框架搭建一个大模型API服务。在RAG实战1-5中,我们一直使用的是本地加载大模型的方式来调用大模型,本文将介绍如何在LlamaIndex中使用自己搭建的大模型API。LlamaIndex支持部分......
  • ChatGPT提问技巧——问题解答提示
    ChatGPT提问技巧——问题解答提示问题解答提示是一种允许模型生成回答特定问题或任务的文本的技术。要做到这一点,需要向模型提供一个问题或任务作为输入,以及与该问题或任务相关的任何附加信息。一些提示示例及其公式如下:示例1:回答事实性问题任务:回答一个事实性问题说......
  • APatch常见问题解答
    常见问题解答什么是APatch?APatch是一种类似于Magisk或KernelSU的root解决方案,但APatch提供更多功能。APatch分别结合了Magisk方便易用的通过boot.img安装的方法,和KernelSU强大的内核修补能力。APatch与Magisk的区别?Magisk对启动映像中的ramdisk进行补丁,以修改init系统。而AP......