How to Integrate LangGraph for banking with Redis for RAG
Combining LangGraph for banking with Redis gives you a practical RAG stack for regulated workflows: LangGraph handles the orchestration, state, and branching logic, while Redis gives you low-latency vector retrieval and session storage. That means your agent can answer customer or analyst questions using bank policy docs, product manuals, and case notes without rebuilding context on every turn.
This is the pattern I use when an agent needs to reason over internal knowledge, keep conversation state, and stay fast enough for production banking workloads.
Prerequisites
- •Python 3.10+
- •A running Redis instance with Redis Stack enabled for vector search
- •LangGraph installed and configured for your banking agent project
- •OpenAI or another embedding/chat model provider
- •Access to your banking knowledge base documents
- •Environment variables set:
- •
REDIS_URL - •
OPENAI_API_KEY
- •
Install the Python packages:
pip install langgraph redis langchain-openai langchain-community tiktoken
Integration Steps
1) Connect to Redis and create a vector index
Start by connecting to Redis and creating a vector store namespace for your banking documents.
import os
from redis import Redis
from langchain_community.vectorstores import Redis as RedisVectorStore
from langchain_openai import OpenAIEmbeddings
redis_url = os.environ["REDIS_URL"]
redis_client = Redis.from_url(redis_url)
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
vector_store = RedisVectorStore(
redis_url=redis_url,
index_name="banking-rag",
embedding=embeddings,
)
print(redis_client.ping())
If you already have Redis Stack running, the RedisVectorStore will manage document storage and similarity search against the banking-rag index.
2) Load banking documents into Redis
Use chunked documents from policy PDFs, FAQs, or product terms. Keep chunks small enough for retrieval precision.
from langchain_core.documents import Document
docs = [
Document(
page_content="Wire transfers above $10,000 require enhanced due diligence and approval.",
metadata={"source": "policy-wire-transfers", "section": "limits"}
),
Document(
page_content="Credit card chargebacks must be filed within 60 days of the transaction date.",
metadata={"source": "policy-chargebacks", "section": "disputes"}
),
]
vector_store.add_documents(docs)
print("Loaded docs:", len(docs))
At this point, Redis is acting as your retrieval layer. The agent will query it whenever it needs bank-specific context.
3) Build a LangGraph workflow that retrieves from Redis
Now wire retrieval into a LangGraph state machine. For banking use cases, keep the graph simple: classify intent, retrieve context, then generate an answer.
from typing import TypedDict, List
from langgraph.graph import StateGraph, END
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
class AgentState(TypedDict):
question: str
context: List[str]
answer: str
def retrieve_context(state: AgentState):
results = vector_store.similarity_search(state["question"], k=3)
return {"context": [doc.page_content for doc in results]}
def generate_answer(state: AgentState):
prompt = f"""
You are a banking assistant.
Use only the context below.
Question: {state['question']}
Context:
{chr(10).join(state['context'])}
"""
response = llm.invoke(prompt)
return {"answer": response.content}
graph = StateGraph(AgentState)
graph.add_node("retrieve", retrieve_context)
graph.add_node("generate", generate_answer)
graph.set_entry_point("retrieve")
graph.add_edge("retrieve", "generate")
graph.add_edge("generate", END)
app = graph.compile()
This is the core integration point. LangGraph orchestrates the flow; Redis supplies the retrieved evidence.
4) Add conversation memory in Redis for repeat banking sessions
For customer service or relationship-manager workflows, store session state in Redis so follow-up questions retain context.
from redis import Redis
session_store = Redis.from_url(redis_url)
def save_session(session_id: str, question: str, answer: str):
key = f"banking-session:{session_id}"
session_store.hset(key, mapping={
"last_question": question,
"last_answer": answer,
})
session_store.expire(key, 3600)
def load_session(session_id: str):
key = f"banking-session:{session_id}"
return session_store.hgetall(key)
In production, this keeps your agent stateless at the app layer while still preserving short-lived conversational memory in Redis.
5) Run the graph end-to-end
Send a question through LangGraph and persist the result back to Redis.
result = app.invoke({
"question": "What is required for wire transfers above $10,000?",
"context": [],
"answer": ""
})
print(result["answer"])
save_session("session-123", "What is required for wire transfers above $10,000?", result["answer"])
Testing the Integration
Use a known policy question and verify that retrieval returns grounded content from Redis.
test_input = {
"question": "How long do customers have to file a credit card chargeback?",
"context": [],
"answer": ""
}
result = app.invoke(test_input)
print("Answer:", result["answer"])
session_data = load_session("session-123")
print("Session keys:", list(session_data.keys()))
Expected output:
Answer: Customers must file credit card chargebacks within 60 days of the transaction date.
Session keys: [b'last_question', b'last_answer']
If the answer does not reflect your stored policy text, check these first:
- •The document was actually inserted into the correct Redis index
- •Your embeddings model matches between ingestion and retrieval
- •The similarity search
kvalue is high enough for your corpus size
Real-World Use Cases
- •
Policy Q&A for bankers and support teams
Let internal users ask questions about lending rules, transfer limits, KYC steps, or dispute windows with answers grounded in approved documents. - •
Customer service assistants with session memory
Store recent interactions in Redis so agents can handle multi-turn conversations without losing context between requests. - •
Compliance review copilots
Retrieve relevant policy clauses before generating responses or summaries so compliance teams can audit which source text influenced an answer.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit