分类目录:《大模型从入门到应用》总目录
LangChain系列文章:
- 基础知识
- 快速入门
- 安装与环境配置
- 链(Chains)、代理(Agent:)和记忆(Memory)
- 快速开发聊天模型
- 模型(Models)
- 基础知识
- 大型语言模型(LLMs)
- 基础知识
- LLM的异步API、自定义LLM包装器、虚假LLM和人类输入LLM(Human Input LLM)
- 缓存LLM的调用结果
- 加载与保存LLM类、流式传输LLM与Chat Model响应和跟踪tokens使用情况
- 聊天模型(Chat Models)
- 基础知识
- 使用少量示例和响应流式传输
- 文本嵌入模型
- Aleph Alpha、Amazon Bedrock、Azure OpenAI、Cohere等
- Embaas、Fake Embeddings、Google Vertex AI PaLM等
- 提示(Prompts)
- 基础知识
- 提示模板
- 基础知识
- 连接到特征存储
- 创建自定义提示模板和含有Few-Shot示例的提示模板
- 部分填充的提示模板和提示合成
- 序列化提示信息
- 示例选择器(Example Selectors)
- 输出解析器(Output Parsers)
- 记忆(Memory)
- 基础知识
- 记忆的类型
- 会话缓存记忆、会话缓存窗口记忆和实体记忆
- 对话知识图谱记忆、对话摘要记忆和会话摘要缓冲记忆
- 对话令牌缓冲存储器和基于向量存储的记忆
- 将记忆添加到LangChain组件中
- 自定义对话记忆与自定义记忆类
- 聊天消息记录
- 记忆的存储与应用
- 索引(Indexes)
- 基础知识
- 文档加载器(Document Loaders)
- 文本分割器(Text Splitters)
- 向量存储器(Vectorstores)
- 检索器(Retrievers)
- 链(Chains)
- 基础知识
- 通用功能
- 自定义Chain和Chain的异步API
- LLMChain和RouterChain
- SequentialChain和TransformationChain
- 链的保存(序列化)与加载(反序列化)
- 链与索引
- 文档分析和基于文档的聊天
- 问答的基础知识
- 图问答(Graph QA)和带来源的问答(Q&A with Sources)
- 检索式问答
- 文本摘要(Summarization)、HyDE和向量数据库的文本生成
- 代理(Agents)
- 基础知识
- 代理类型
- 自定义代理(Custom Agent)
- 自定义MRKL代理
- 带有ChatModel的LLM聊天自定义代理和自定义多操作代理(Custom MultiAction Agent)
- 工具
- 基础知识
- 自定义工具(Custom Tools)
- 多输入工具和工具输入模式
- 人工确认工具验证和Tools作为OpenAI函数
- 工具包(Toolkit)
- 代理执行器(Agent Executor)
- 结合使用Agent和VectorStore
- 使用Agents的异步API和创建ChatGPT克隆
- 处理解析错误、访问中间步骤和限制最大迭代次数
- 为代理程序设置超时时间和限制最大迭代次数和为代理程序和其工具添加共享内存
- 计划与执行
- 回调函数(Callbacks)
Vectorstores是构建索引的最重要组件之一。本文展示了与VectorStores相关的基本功能。在使用VectorStores时,创建要放入其中的向量是一个关键部分,通常通过嵌入来创建。
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Chroma
with open('../../state_of_the_union.txt') as f:
state_of_the_union = f.read()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_text(state_of_the_union)
embeddings = OpenAIEmbeddings()
docsearch = Chroma.from_texts(texts, embeddings)
query = "What did the president say about Ketanji Brown Jackson"
docs = docsearch.similarity_search(query)
日志输出:
Running Chroma using direct local API. Using DuckDB in-memory for database. Data will be transient.
输入:
print(docs[0].page_content)
输出:文章来源:https://www.toymoban.com/news/detail-731145.html
In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections.
We cannot let this happen.
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
添加文本
我们可以使用add_texts
方法轻松地将文本添加到VectorStore中。它将返回一个文档ID的列表(以防我们需要在下游使用它们)。
docsearch.add_texts(["Ankush went to Princeton"])
输出:
['a05e3d0c-ab40-11ed-a853-e65801318981']
输入:
query = "Where did Ankush go to college?"
docs = docsearch.similarity_search(query)
docs[0]
Document(page_content='Ankush went to Princeton', lookup_str='', metadata={}, lookup_index=0)
从文档初始化
我们还可以直接从文档初始化一个Vectorstore。当我们在文本分割器上使用该方法直接获取文档时,这非常有用(当原始文档具有相关联的元数据时非常方便)。
documents = text_splitter.create_documents([state_of_the_union], metadatas=[{"source": "State of the Union"}])
docsearch = Chroma.from_documents(documents, embeddings)
query = "What did the president say about Ketanji Brown Jackson"
docs = docsearch.similarity_search(query)
日志输出:
Running Chroma using direct local API. Using DuckDB in-memory for database. Data will be transient.
输入:
print(docs[0].page_content)
输出:
In state after state, new laws have been passed, not only to suppress the vote, but to subvert entire elections.
We cannot let this happen.
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court.
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
参考文献:
[1] LangChain官方网站:https://www.langchain.com/
[2] LangChain 🦜️🔗 中文网,跟着LangChain一起学LLM/GPT开发:https://www.langchain.com.cn/
[3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架:http://www.cnlangchain.com/文章来源地址https://www.toymoban.com/news/detail-731145.html
到了这里,关于大模型从入门到应用——LangChain:索引(Indexes)-[向量存储器(Vectorstores)]的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!