Pra*_*ell 7 information-retrieval artificial-intelligence chaining large-language-model py-langchain
我正在使用Langchainversion 0.218,并且想知道是否有人能够在运行时动态过滤种子向量库?例如当由代理运行时。
我的动机是将这个动态过滤器放入对话检索 QA 链中,在其中我使用filename从对话输入中提取的内容来过滤检索器并检索其所有块(使用映射器文件k设置为属于search_kwargs中文件名的块的计数)。
我可以手动过滤种子向量库(如 Chroma) ,例如:
from langchain.chains import ConversationalRetrievalChain
from langchain.memory import ConversationBufferMemory
# init a vectorstore and seed documents
vectorstore = Chroma.from_documents(..)
# 'somehow' I get hands on the filename from user input or chat history
found_filename = "report.pdf"
# filter using a search arg, such as 'filename' provided in the metadata of all chunks
file_chunk_mapper = {"report.pdf" : ["chunk1", "chunk2", ... ]
one_doc_retiever = vectorstore.as_retriever(search_kwargs={"where" : {"filename": found_filename}, 'k': len(file_chunk_mapper})
# QA Chain which will be used as a Tool by Agents
QA_chain = ConversationalRetrievalChain(.., retriever=one_doc_retiever, memory=memory)
# this would be run by an Agent
QA_chain.run("all person names in file report")
## ANSWER
## I found all the names like: ...
Run Code Online (Sandbox Code Playgroud)
我尝试过使用无过滤器和其他方法,例如自查询检索和压缩查询检索,但当模型有一组特定且明确的块要查看时,没有一个方法像这样工作。
据我阅读的文档,我认为创建一个具有两个链的 CustomChain,首先提取文件名,过滤检索器,然后使用该新检索器执行第二个链似乎是唯一的选择。
我在这里错过了什么吗?有没有更简单或更聪明的方法?
但是我如何在链自动化的代理执行中使用它。过去两天的事情让我很困惑。