The*_*Man 5 artificial-intelligence nlp-question-answering huggingface-transformers langchain gpt4all
我将privateGPT与默认的GPT4All模型 ( ggml-gpt4all-j-v1.3-groovy.bin ) 一起使用,但也与最新的 Falcon 版本一起使用。我的问题是,我期望仅从本地文档中获取信息,而不是从模型已经“知道”的信息中获取信息。
示例:如果唯一的本地文档是软件的参考手册,我预计 privateGPT 无法回答以下问题:“德国的首都是哪一个?” 或“什么是苹果?” 因为它的内容不在本地文档本身中。
privateGPT 使用本地 Chroma 矢量存储来存储本地文档中的嵌入。langchain检索器不应该只从这些中获取信息吗?我缺少什么?
小智 1
Privategpt 响应由 3 个组成部分组成:(1) 解释问题 (2) 从本地参考文档中获取来源,以及 (3) 使用本地源文档 + 它已知的内容来生成类似人类答案的响应。
您可以通过注释掉原始代码中下面显示的几行并定义来关闭(3)
docs = db.as_retriever(search_type="similarity", search_kwargs={"k":5}).get_relevant_documents(query)
Run Code Online (Sandbox Code Playgroud)
如下所示。您可以调整参数{"k":5}以获得 5 个或任意数量的列出源。
缺点是,如果执行上述步骤,privategpt 只会执行 (1) 和 (2),但不会以类似人类的响应生成最终答案。因此,本质上 privategpt 的作用就像一个信息检索器,它只会列出本地文档中的相关来源。
修改代码
while True:
query = input("\nEnter a query: ")
if query == "exit":
break
# Get the answer from the chain
####res = qa(query)
####answer, ####
docs = db.as_retriever(search_type="similarity", search_kwargs={"k":5}).get_relevant_documents(query)
# # Print the result
# print("\n\n> Question:")
# print(query)
# print("\n> Answer:")
# print(answer)
# Print the relevant sources used for the answer
for document in docs:
print("\n> " + document.metadata["source"] + ":")
print(document.page_content)
Run Code Online (Sandbox Code Playgroud)