RAG의 작동 순서도

image.png

  1. 가장 먼저 결정해야할 것: 모델의 종류
  2. RAG에 담을 문서에 따라 적합한 Document Loader를 선정해야 함
  3. 문서를 적절한 크기의 텍스트 청크로 분할하기 위해서 Text Splitter를 선언해야 함
  4. 분할된 청크를 임베딩 벡터로 변환하기 위해 알맞은 임베딩 모델을 활용해야 함
  5. 임베딩 벡터를 저장할 벡터 스토어를 정해야 함
  6. 사용자의 질문과 유사한 문장을 검색하기 위한 Retriever를 결정해야 함
  7. LCEL(랭체인을 표현하는 언어)을 기반으로 앞선 구성 요소들을 하나로 묶어 구성함

대화 컨텍스트 처리

contextualize_q_system_prompt = """Given a chat history and the latest user question \\
which might reference context in the chat history, formulate a standalone question \\
which can be understood without the chat history. Do NOT answer the question, \\
just reformulate it if needed and otherwise return it as is."""
chat_history = [
    HumanMessage(content='대통령의 임기는 몇년이야?'),
    AIMessage(content='대통령의 임기는 5년입니다.')
]

# 불완전한 후속 질문 "국회의원은?"를 맥락화
contextualize_q_prompt.invoke({"input":"국회의원은?", "chat_history": chat_history})

추가: 평가 및 모니터링 시스템