블로그 이미지
Peter Note
AI & Web FullStacker, Application Architecter, KnowHow Dispenser and Bike Rider

Publication

Category

Recent Post

2024. 8. 4. 14:00 LLM FullStacker/LangChain

LangChain은 LLM 애플리케이션을 구축하기 위한 개발 프레임워크로써 다양한 컴포넌트를 제공한다. 프러덕션 애플리케이션 개발시 RAG(Retrieval Augmented Generation)를 기반으로 할 때 LangChain 컴포넌트를 통해 일관된 코드 인터페이스를 유지할 수 있다.

LangChain Components

Prompts

  • Prompt Templates
  • Output Parsers: 5+ implementations
    • Retry/fixing logic
  • Example Selectors: 5+ implementations

Models

  • LLM's: 20+ integrations
  • Chat Models
  • Text Embedding Models: 10+ integrations

Indexes

  • Document Loaders: 50+ implementations
  • Text Splitters: 10+ implementations
  • Vector stores: 10+ integrations
  • Retrievers: 5+ integrations/implementations

Chains

  • Can be used as building blocks for other chains
  • More application specific cahins: 20+ different types

Agents

  • Agent Types: 5+ types
    • Algorithms for getting LLMs to use tools
  • Agent Tookkits: 10+ implementations
    • Agents armed with specific tools for a specific application

LangChain API

각 컴포넌트는 구현된 패키지와 API랑 함께 볼 필요가 있다.

langchain

  • document_loaders
  • text_splitter
  • embeddings
  • retrievers
  • prompts
  • chat_models
  • output_parsers
  • chains
  • agents

등의 패키지에서 langchain_community, langchain_core 패키지의 모듈을 re-export 하고 있다. 중요 패키지는 langchain.* 으로 import 할 수 있다.

  • text_splitter.py : text-splitters를 re-export하고 있다.
  • text_splitter 별도 패키지

langchain-core

langchain-community


RAG Step

RAG는 크게 2단계로 볼 수 있다. 사전에 프라이빗 정보를 로딩->쪼개기->임베딩벡터->저장하기 단계를 거쳐서 준비를 한다. 이때 LangChain의 Indexes 영역의 컴포넌트를 사용한다. 다음으로 사용자가 질의를 하게되면 프라이빗 정보를 기반으로 증강검색->프롬프트생성->LLM응답->응답처리 등의 과정을 거쳐, 유의미한 응답을 생성한다. 이때 LangChain의 Prompts, Models, Chains, Agents 영역의 컴포넌트를 사용한다.

 

출처: DeepLearning.ai

1 단계

  • Document Loader
    • Structured/Unstructured 미디어를 로딩한다.
      • 문서, 이미지, 동영상, 음성
  • Splitting
  • Embedding
  • Vector Storing

2단계

  • Retrieval
  • Prompting
  • LLM
  • Output Parsing
posted by Peter Note