How to Integrate LangGraph for investment banking with Redis for RAG
Combining LangGraph for investment banking with Redis gives you a clean pattern for agentic RAG: LangGraph handles the orchestration, state, and decision flow, while Redis handles fast retrieval of embeddings, conversation memory, and cached market or policy context. For banking workflows, that means your agent can route between research, compliance checks, and answer generation without turning every request into a full re-index.
Prerequisites
- •Python 3.10+
- •A Redis Stack instance with RediSearch enabled
- •An OpenAI-compatible embedding model or another embedding provider
- •
langgraph,langchain,redis, andnumpyinstalled - •Access to your investment banking documents:
- •deal memos
- •pitch books
- •policy docs
- •earnings transcripts
- •Environment variables configured:
- •
REDIS_URL - •
OPENAI_API_KEY
- •
Install the packages:
pip install langgraph langchain redis langchain-openai numpy
Integration Steps
- •
Connect to Redis and create a vector index
Use Redis as your retrieval layer. In production, keep one index per document domain so you can separate research notes from compliance or client materials.
import os
from redis import Redis
redis_client = Redis.from_url(os.environ["REDIS_URL"], decode_responses=False)
# Optional: verify connectivity
print(redis_client.ping())
- •
Chunk and embed banking documents before storing them in Redis
The key part is storing both the text and the vector. If you are using Redis Stack, store embeddings in a hash and query them with vector search.
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
docs = [
{
"id": "deal_memo_001",
"text": "Company A is targeting acquisition of Company B. EBITDA multiple is 9.2x..."
},
{
"id": "policy_014",
"text": "For client-facing outputs, avoid unsupported forward-looking statements..."
},
]
for doc in docs:
vector = embeddings.embed_query(doc["text"])
redis_client.hset(
f"doc:{doc['id']}",
mapping={
b"text": doc["text"].encode("utf-8"),
b"vector": bytes(str(vector), "utf-8"),
},
)
For production, don’t store vectors as strings like this. Use Redis Stack vector fields through redis-py schema support or LangChain’s Redis vector store integration.
- •
Build a retriever backed by Redis
LangGraph needs a retrieval function it can call inside the graph. The cleanest approach is to use a Redis-backed retriever from LangChain or your own query wrapper around RediSearch.
from langchain_community.vectorstores import Redis as RedisVectorStore
vectorstore = RedisVectorStore.from_texts(
texts=[d["text"] for d in docs],
embedding=embeddings,
metadatas=[{"doc_id": d["id"]} for d in docs],
redis_url=os.environ["REDIS_URL"],
index_name="ib_rag_index",
)
retriever = vectorstore.as_retriever(search_kwargs={"k": 3})
- •
Wire retrieval into a LangGraph state graph
LangGraph’s
StateGraphgives you explicit control over retrieval, answer generation, and routing. That matters in banking because you often need to branch to compliance review or ask for more context.
from typing import TypedDict, List
from langgraph.graph import StateGraph, END
from langchain_core.documents import Document
class GraphState(TypedDict):
question: str
context: List[str]
answer: str
def retrieve_node(state: GraphState):
results = retriever.invoke(state["question"])
return {"context": [doc.page_content for doc in results]}
def generate_node(state: GraphState):
context_block = "\n\n".join(state["context"])
answer = f"Question: {state['question']}\n\nContext:\n{context_block}\n\nAnswer: Based on retrieved banking docs..."
return {"answer": answer}
workflow = StateGraph(GraphState)
workflow.add_node("retrieve", retrieve_node)
workflow.add_node("generate", generate_node)
workflow.set_entry_point("retrieve")
workflow.add_edge("retrieve", "generate")
workflow.add_edge("generate", END)
app = workflow.compile()
- •
Add conversation memory or result caching in Redis
This is where Redis becomes more than just a document store. Cache repeated prompts, recent answers, or session state so analysts don’t pay retrieval costs twice for the same question.
import json
def cache_key(question: str) -> str:
return f"rag_cache:{hash(question)}"
def get_cached_answer(question: str):
raw = redis_client.get(cache_key(question))
return json.loads(raw) if raw else None
def set_cached_answer(question: str, payload: dict):
redis_client.setex(cache_key(question), 3600, json.dumps(payload))
question = "What are the risks in this acquisition memo?"
cached = get_cached_answer(question)
if cached:
print(cached["answer"])
else:
result = app.invoke({"question": question, "context": [], "answer": ""})
set_cached_answer(question, result)
Testing the Integration
Run a simple end-to-end test with one banking question and confirm that LangGraph retrieves from Redis and returns an answer.
test প্রশ্ন = "Summarize the key risk factors in Company A's acquisition memo."
result = app.invoke({"question": test_question, "context": [], "answer": ""})
print("Answer:")
print(result["answer"])
Expected output:
Answer:
Question: Summarize the key risk factors in Company A's acquisition memo.
Context:
Company A is targeting acquisition of Company B. EBITDA multiple is 9.2x...
Answer: Based on retrieved banking docs...
If that works, validate three things:
- •Redis returns documents through the retriever
- •LangGraph passes retrieved context into the generation node
- •Cached responses are stored and reused on repeat queries
Real-World Use Cases
- •
Deal diligence assistant
- •Pulls relevant excerpts from CIMs, QoE reports, and legal docs.
- •Routes ambiguous questions to compliance or human review nodes in LangGraph.
- •
Investment committee prep bot
- •Retrieves prior memos, comparable transactions, and internal policy notes.
- •Generates structured answers with source-backed context from Redis.
- •
Client Q&A assistant
- •Answers questions about mandates, market comps, or transaction status.
- •Caches repeated queries in Redis to keep latency low during live calls.
If you want this pattern to hold up in production, keep retrieval deterministic, version your indexes by document source, and make every LangGraph node observable. In banking systems, traceability matters as much as answer quality.
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