0Pricing
LangChain / RAG / Vector DBs · 강의

LangChain의 메모리와 대화 맥락

LangChain 메모리가 대화 기록을 추적해 체인과 챗봇이 일관된 여러 차례의 대화를 이어 가도록 하는 방법을 학습해 보세요.

LangChain의 메모리와 대화 맥락은(는) CoddyKit의 무료 LangChain / RAG / Vector DBs 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 LangChain / RAG / Vector DBs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

LLMs Are Stateless

A language model has no memory between calls. Each request is independent — it only knows what you put in the current prompt. To build a chatbot that remembers, you must feed prior turns back in yourself.

What LangChain Memory Does

LangChain memory automates this: it stores the conversation and injects relevant history into the prompt on each new turn. Your chain stays simple while the model appears to remember.

Conversation Buffer Memory

The simplest memory keeps the full transcript and prepends it to every prompt. Great for short chats, but it grows with every turn.

from langchain.memory import ConversationBufferMemory
memory = ConversationBufferMemory()
memory.save_context({'input': 'Hi, I am Sam'}, {'output': 'Hello Sam!'})
print(memory.load_memory_variables({}))

The Context Window Limit

Every model has a finite context window (a token budget). A growing buffer eventually overflows it, causing errors or truncation. Managing history size is the central challenge of memory.

turns = 50
tokens_per_turn = 200
total = turns * tokens_per_turn
print('history tokens:', total)

Window Memory

ConversationBufferWindowMemory keeps only the last k turns. It bounds token usage at the cost of forgetting older context — a simple, effective trade-off for many chatbots.

from langchain.memory import ConversationBufferWindowMemory
memory = ConversationBufferWindowMemory(k=3)
# only the most recent 3 exchanges are kept

Summary Memory

ConversationSummaryMemory uses the LLM to compress old turns into a running summary. You keep the gist of a long conversation in far fewer tokens, sacrificing exact wording for breadth.

Summary Buffer: Best of Both

ConversationSummaryBufferMemory keeps recent turns verbatim and summarizes everything older. Recent context stays precise while distant context is condensed — a popular default for production chatbots.

Wiring Memory into a Chain

You attach memory to a conversational chain. On each call, the chain loads history, builds the prompt, calls the model, and saves the new turn back to memory automatically.

from langchain.chains import ConversationChain
chain = ConversationChain(llm=llm, memory=memory)
chain.predict(input='What is my name?')

Memory Variables and Prompts

Memory exposes its content as a variable (often history or chat_history) that your prompt template references. The placeholder is where the stored conversation gets injected.

template = 'Conversation so far:\n{history}\nHuman: {input}\nAI:'

Persisting Memory

In-process memory vanishes when the app restarts. For real users, back memory with a store — Redis, a database, or a chat-message-history backend keyed by session id — so conversations survive across requests and servers.

Choosing a Memory Type

Match memory to need: buffer for short chats, window when you only care about recent turns, summary for long sessions on a budget, and summary-buffer for the common case. Always persist memory for multi-user apps.

Quick Check

Test your understanding of LangChain memory.

Recap

You learned how LangChain gives chatbots memory:

  • LLMs are stateless; memory re-injects history each turn
  • Buffer, window, summary, and summary-buffer trade detail against tokens
  • Memory exposes a history variable that the prompt template uses
  • Persist memory per session for multi-user, multi-server apps

자주 묻는 질문

“LangChain의 메모리와 대화 맥락” 강의는 무료인가요?

네 — “LangChain의 메모리와 대화 맥락” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 LangChain / RAG / Vector DBs 강의 전체를 잠금 해제할 수 있습니다. LangChain / RAG / Vector DBs 강의에는 총 4개의 강의가 포함되어 있습니다.

“LangChain의 메모리와 대화 맥락”에서 뭘 배우나요?

LangChain 메모리가 대화 기록을 추적해 체인과 챗봇이 일관된 여러 차례의 대화를 이어 가도록 하는 방법을 학습해 보세요. 브라우저에서 직접 실행하는 실습 코드로 LangChain / RAG / Vector DBs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

LangChain / RAG / Vector DBs을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 LangChain / RAG / Vector DBs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“LangChain의 메모리와 대화 맥락” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 LangChain / RAG / Vector DBs 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 LangChain / RAG / Vector DBs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. LangChain 환경 설정
  2. 프롬프트, LLM, 기본 체인
  3. 출력 파서와 콜백
  4. LangChain의 메모리와 대화 맥락
← LangChain / RAG / Vector DBs(으)로 돌아가기