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 )