How to Integrate OpenAI for retail banking with Pinecone for multi-agent systems
Combining OpenAI for retail banking with Pinecone gives you a practical pattern for multi-agent banking systems: one agent handles conversation and reasoning, while Pinecone holds the retrieval layer for policies, product docs, transaction context, and customer history. That means your agents can answer banking questions with grounded context instead of guessing, which is what you want in regulated environments.
This setup is useful when you need multiple agents to coordinate across tasks like customer support, fraud triage, product recommendation, and compliance lookup. OpenAI handles the language and orchestration; Pinecone gives each agent fast semantic access to the right memory.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key
- •A Pinecone index created with the correct embedding dimension
- •
pipinstalled - •Basic familiarity with async Python and REST APIs
- •Banking content ready to ingest:
- •FAQ documents
- •product terms
- •compliance snippets
- •internal support playbooks
Install the SDKs:
pip install openai pinecone tiktoken python-dotenv
Set environment variables:
export OPENAI_API_KEY="your-openai-key"
export PINECONE_API_KEY="your-pinecone-key"
export PINECONE_INDEX_NAME="retail-banking-agent"
Integration Steps
- •Initialize both clients
Use OpenAI for chat and embeddings, and Pinecone for vector storage. For multi-agent systems, keep this setup in a shared service layer so every agent uses the same retrieval backend.
import os
from openai import OpenAI
from pinecone import Pinecone
openai_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index(os.environ["PINECONE_INDEX_NAME"])
- •Create embeddings for banking knowledge
You need embeddings for your bank docs before agents can retrieve them. Use OpenAI’s embedding endpoint and store vectors in Pinecone with metadata that supports filtering by document type or business unit.
from openai import OpenAI
client = OpenAI()
documents = [
{
"id": "doc-001",
"text": "Retail savings accounts require a minimum balance of $500 to avoid monthly fees.",
"metadata": {"source": "product_policy", "category": "savings"}
},
{
"id": "doc-002",
"text": "Suspicious card activity should be escalated to fraud operations within 5 minutes.",
"metadata": {"source": "fraud_playbook", "category": "fraud"}
}
]
texts = [d["text"] for d in documents]
embeddings = client.embeddings.create(
model="text-embedding-3-small",
input=texts
)
vectors = []
for doc, item in zip(documents, embeddings.data):
vectors.append({
"id": doc["id"],
"values": item.embedding,
"metadata": {**doc["metadata"], "text": doc["text"]}
})
index.upsert(vectors=vectors)
- •Build a retrieval function for each agent
Each agent should query Pinecone before calling OpenAI so responses stay grounded. In a retail banking workflow, this is how you keep answers tied to policy instead of free-form generation.
def retrieve_context(query: str, top_k: int = 3):
query_embedding = client.embeddings.create(
model="text-embedding-3-small",
input=[query]
).data[0].embedding
results = index.query(
vector=query_embedding,
top_k=top_k,
include_metadata=True
)
chunks = []
for match in results.matches:
md = match.metadata or {}
chunks.append(md.get("text", ""))
return "\n\n".join(chunks)
- •Wire retrieval into an OpenAI agent response
For multi-agent systems, one agent can specialize in customer service while another handles fraud or compliance. The pattern below shows a single agent using retrieved context from Pinecone before generating an answer with OpenAI’s Responses API.
def answer_banking_question(user_question: str) -> str:
context = retrieve_context(user_question)
prompt = f"""
You are a retail banking assistant.
Use only the provided context when answering.
If the context is insufficient, say you need more information.
Context:
{context}
Question:
{user_question}
"""
response = client.responses.create(
model="gpt-4.1-mini",
input=prompt
)
return response.output_text
print(answer_banking_question("What fee applies to savings accounts if the balance drops below minimum?"))
- •Add agent-to-agent routing
In real systems, one orchestrator agent routes work to specialist agents based on intent. Use Pinecone as shared memory and OpenAI as the reasoning layer for routing decisions.
def route_intent(user_message: str) -> str:
response = client.responses.create(
model="gpt-4.1-mini",
input=f"""
Classify this retail banking request into one of:
- support
- fraud
- compliance
Message: {user_message}
Return only one label.
"""
)
return response.output_text.strip().lower()
intent = route_intent("My debit card has two charges I don't recognize.")
print(intent)
Testing the Integration
Run a retrieval-plus-generation test against a known policy question. If Pinecone returns the right chunk and OpenAI uses it in the answer, your integration is working.
question = "How long do we have to escalate suspicious card activity?"
answer = answer_banking_question(question)
print("QUESTION:", question)
print("ANSWER:", answer)
Expected output:
QUESTION: How long do we have to escalate suspicious card activity?
ANSWER: Suspicious card activity should be escalated to fraud operations within 5 minutes.
If you get a generic answer, check these first:
- •The document was actually upserted into Pinecone
- •The embedding model used for indexing matches the query embedding model
- •Your prompt tells OpenAI to use retrieved context only
- •Metadata includes the source text you want returned
Real-World Use Cases
- •
Customer support copilot
- •One agent answers account questions.
- •Another retrieves product policy from Pinecone.
- •OpenAI turns that into a clear customer-facing response.
- •
Fraud triage assistant
- •A detection agent flags suspicious activity.
- •A policy agent retrieves escalation rules.
- •The orchestrator decides whether to route to human review.
- •
Compliance-aware product advisor
- •A sales agent recommends products.
- •A compliance agent checks disclosures and eligibility rules from Pinecone.
- •OpenAI generates an explanation that stays within policy boundaries.
This pattern scales well because you separate concerns cleanly: Pinecone stores bank knowledge, and OpenAI turns that knowledge into usable actions across agents. In regulated retail banking systems, that separation is what keeps your multi-agent stack maintainable and auditable.
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