본문 바로가기

프로젝트

[프로젝트#2025-1]RAG w/ local LLM

최근 검색-증강 생성, RAG(Retrieval-Augmented Generation)가 핫합니다. 

널리 활용되고 있는 LLM의 신뢰성, 최신성, 정확성을 향상시키기 위한 접근 방법인 RAG는
기존의 LLM을 잘 활용할 수 있는 기법 중 하나입니다. 

 

2025년 7월 현재, RAG를 활용한 다양한 서비스들이 많이 제공되고 있지만,
일단 필요에 의해서 local LLM을 활용한 RAG를 구현해봐야 하네요.

 

1) 준비물.. 

RAG를 손쉽게 구현하기 위해서는 플랫폼을 이용하는게 편하겠죠?

LlamaIndex와 LangChain의 널리 활용되는 플랫폼들이 있습니다. 이 중 LangChain을  활용해 봅니다. 

https://www.langchain.com/

 

LangChain

LangChain’s suite of products supports developers along each step of their development journey.

www.langchain.com

※ LangChain은 다양한 서드파티(langchain-openai, langchain-anthropic, langchain-huggingface, langchain-ollama 등)도 제공되며 
     LangGraph , LangSmith와 같은 도구들도 활용할 수 있습니다.  

 

1-1)  LangChain의 설치

더보기

LangChain 설치는 pip를 이용해 설치할 수 있습니다. 

> pip install langchain 

> pip install langchain-core

> pip install langchain-community

 

> pip install langchain-openai 

> pip install langchain-huggingface langchain-ollama

 

1-2) LangSmith 가입 - API Key 발급 

  LLM 응용의 개발, 모니터링, 테스트를 위한 플랫폼으로, 특히 LLM 응용의 동작 이해를 도와주는 도구입니다. 

더보기

https://smith.langchain.com/

LangSmith 가입LangSmith 가입LangSmith 가입LangSmith 가입
LangSmith API Key 생성LangSmith API Key 생성LangSmith API Key 생성
LangSmith API Key 생성

생성된 API Key는 LangChain의 추적에 활용하게 되므로 잘 보관하여야 합니다.

 

import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
os.environ["LANGCHAIN_PROJECT"] = "LangChain 프로젝트명"
os.environ["LANGCHAIN_API_KEY"] = "LangChain API KEY 입력"

 

 

참고) 

  1 RAG 설명

  https://aws.amazon.com/ko/what-is/retrieval-augmented-generation/

  https://aws.amazon.com/what-is/generative-ai/

  2 LangChain 설명

  https://www.langchain.com/
  https://www.ibm.com/kr-ko/think/topics/llamaindex-vs-langchain

  https://www.samsungsds.com/kr/insights/what-is-langchain.html

  2-2 LangChain Tutorials

  https://python.langchain.com/docs/tutorials/llm_chain/

 

 

 

 

반응형