How to Integrate OpenAI for fintech with Pinecone for production AI
OpenAI for fintech plus Pinecone gives you the core stack for production-grade retrieval in financial AI agents. OpenAI handles reasoning, classification, and response generation; Pinecone stores and retrieves the firm-specific context your agent needs to stay accurate on policies, products, transactions, and customer history.
Prerequisites
- •Python 3.10+
- •An OpenAI API key with access to the model you plan to use
- •A Pinecone account and API key
- •A Pinecone index created ahead of time
- •
pipinstalled - •Basic familiarity with embeddings and vector search
Install the SDKs:
pip install openai pinecone
Set environment variables:
export OPENAI_API_KEY="your-openai-key"
export PINECONE_API_KEY="your-pinecone-key"
export PINECONE_INDEX_NAME="fintech-agent-index"
Integration Steps
- •Initialize both clients
Start by wiring up the OpenAI and Pinecone clients in one place. Keep this in a shared module so your agent, ingestion job, and evaluation scripts all use the same configuration.
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_name = os.environ["PINECONE_INDEX_NAME"]
index = pc.Index(index_name)
- •Create embeddings with OpenAI
For fintech RAG, embed policy docs, product terms, KYC rules, support transcripts, and compliance guidance. Use OpenAI embeddings to turn text into vectors before storing them in Pinecone.
docs = [
{
"id": "doc-001",
"text": "Wire transfers above $10,000 require enhanced due diligence and manual review."
},
{
"id": "doc-002",
"text": "Savings accounts accrue interest daily and are paid monthly."
}
]
embedding_response = openai_client.embeddings.create(
model="text-embedding-3-small",
input=[d["text"] for d in docs]
)
vectors = []
for doc, item in zip(docs, embedding_response.data):
vectors.append({
"id": doc["id"],
"values": item.embedding,
"metadata": {
"text": doc["text"],
"source": "policy"
}
})
- •Upsert vectors into Pinecone
Store the embedded documents in your index with metadata that helps downstream filtering. In fintech systems, metadata matters because you often need to scope results by region, product line, or document type.
index.upsert(vectors=vectors)
print(f"Upserted {len(vectors)} vectors into {index_name}")
- •Query Pinecone from your agent flow
When a user asks a question, embed the query with the same OpenAI embedding model, then search Pinecone for the most relevant context. This is the retrieval step that keeps your agent grounded in firm data.
query = "Do transfers over 10k need approval?"
query_embedding = openai_client.embeddings.create(
model="text-embedding-3-small",
input=query
).data[0].embedding
results = index.query(
vector=query_embedding,
top_k=3,
include_metadata=True
)
for match in results.matches:
print(match.id, match.score, match.metadata["text"])
- •Generate a grounded answer with OpenAI
Pass the retrieved context into a chat completion call. For production AI, keep the prompt strict: answer only from retrieved context when possible and flag uncertainty when context is missing.
context_chunks = [
match.metadata["text"]
for match in results.matches
]
messages = [
{
"role": "system",
"content": (
"You are a fintech assistant. Answer using only the provided context. "
"If the context does not contain enough information, say so."
)
},
{
"role": "user",
"content": f"Context:\n- " + "\n- ".join(context_chunks) + f"\n\nQuestion: {query}"
}
]
response = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
temperature=0
)
print(response.choices[0].message.content)
Testing the Integration
Run a simple end-to-end test: embed two policy docs, store them in Pinecone, retrieve one with a query, then generate an answer from that context.
test_query = "What happens if a wire transfer is above $10,000?"
q_emb = openai_client.embeddings.create(
model="text-embedding-3-small",
input=test_query
).data[0].embedding
res = index.query(vector=q_emb, top_k=1, include_metadata=True)
context = res.matches[0].metadata["text"]
answer = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Answer from context only."},
{"role": "user", "content": f"Context: {context}\nQuestion: {test_query}"}
],
temperature=0
)
print("Retrieved:", context)
print("Answer:", answer.choices[0].message.content)
Expected output:
Retrieved: Wire transfers above $10,000 require enhanced due diligence and manual review.
Answer: Wire transfers above $10,000 require enhanced due diligence and manual review.
Real-World Use Cases
- •
Customer support agents
- •Answer questions about fees, transfer limits, card disputes, or account rules using indexed internal documentation.
- •
Compliance copilots
- •Retrieve KYC/AML policies and generate guided responses for analysts reviewing suspicious activity or onboarding cases.
- •
Advisor assistants
- •Surface product details, suitability rules, and portfolio notes so relationship managers can respond faster with fewer mistakes.
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