thesis rag chatbot gemini
1.0.0

已经制作了一个基于兰链的抹布应用程序,它使用矢量嵌入和Google Gemini Pro LLM模型来工作。
export GOOGLE_API_KEY= " your api key "langchain.document-loaders已使用了非结构性Excelloader,用于将Excel电子表格数据加载到文档中。
Google Gemini Pro模型已用于获得上下文聊天完成。
llm = ChatGoogleGenerativeAI ( model = "gemini-pro" , google_api_key = os . environ [ "GOOGLE_API_KEY" ])
embeddings = GoogleGenerativeAIEmbeddings ( model = "models/embedding-001" )Faiss(Facebook AI相似性搜索)矢量存储已用于为已加载的文档创建和存储语义嵌入。然后,可以通过相似性搜索查询矢量商店以获取最相关的信息。
vectordb = FAISS . from_documents ( documents = docs , embedding = embeddings )
# save db as pickle file
with open ( "vectorstore.pkl" , "wb" ) as f :
pickle . dump ( vectordb , f )
#load db from pickle file
with open ( "vectorstore.pkl" , "rb" ) as f :
my_vector_database = pickle . load ( f )
# get 5 most relevant similar results
retriever = my_vector_database . as_retriever ( search_kwargs = { "k" : 5 })提示网板已从Langchain使用来制作有效的提示,后来将传递给模型。该提示还包含输入变量,这些变量表明该模型将通过用户传递某些信息。
template = """
You are a very helpful AI assistant.
You answer every question and apologize polietly if you dont know the answer.
The context contains information about a person,
title of their thesis,
the abstract of their thesis
and a link to their thesis.
Your task is to answer based on that information.
context: {context}
input: {input}
answer:
"""
prompt = PromptTemplate . from_template ( template )Retreival Chain已被用来将文档/嵌入到模型中,作为Retreival增强发电的背景。
combine_docs_chain = create_stuff_documents_chain ( llm , prompt )
retrieval_chain = create_retrieval_chain ( retriever , combine_docs_chain )