thesis rag chatbot gemini
1.0.0

벡터 임베드와 Google Gemini Pro LLM 모델을 사용하여 작동하는 Langchain 기반 Rag 앱이 만들어졌습니다.
export GOOGLE_API_KEY= " your api key "UnstructuredexCelloader는 Excel 스프레드 시트 데이터를 문서에로드하는 데 사용되는 Langchain.document-Loader에서 사용되었습니다.
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 })PromptTemplate은 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 )