How to Integrate OpenAI for fintech with Pinecone for AI agents
Integrating OpenAI for fintech with Pinecone gives you a practical pattern for building AI agents that can answer domain-specific questions using your own financial knowledge base. OpenAI handles the reasoning and generation layer, while Pinecone gives your agent fast semantic retrieval over policies, product docs, KYC playbooks, market notes, and support transcripts.
That combination is useful when you need grounded answers, not generic chat. For fintech teams, it’s the difference between an assistant that hallucinates compliance guidance and one that retrieves the exact internal policy before responding.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key
- •A Pinecone index created with the correct vector dimension for your embedding model
- •
pipinstalled - •Basic familiarity with Python async or sync code
- •A folder of fintech documents to embed and store in Pinecone
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
1) Initialize OpenAI and Pinecone clients
Use OpenAI for embeddings and generation, and Pinecone for vector storage and retrieval.
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)
If your index does not exist yet, create it once from a provisioning script or console. Match the dimension to your embedding model output.
2) Embed fintech documents before upserting
For an AI agent, chunk your source material into small passages first. Then convert each chunk into embeddings with openai.embeddings.create().
documents = [
{
"id": "kyc_001",
"text": "Customer onboarding requires government ID verification, proof of address, and sanctions screening."
},
{
"id": "fraud_002",
"text": "Transactions above $10,000 require enhanced monitoring and manual review by compliance."
}
]
texts = [doc["text"] for doc in documents]
embedding_response = openai_client.embeddings.create(
model="text-embedding-3-small",
input=texts
)
vectors = []
for doc, item in zip(documents, embedding_response.data):
vectors.append({
"id": doc["id"],
"values": item.embedding,
"metadata": {"text": doc["text"], "source": "internal_fintech_policy"}
})
This is the core pattern: OpenAI turns text into vectors; Pinecone stores them with metadata so your agent can retrieve context later.
3) Upsert vectors into Pinecone
Push the embedded chunks into Pinecone using index.upsert().
upsert_result = index.upsert(vectors=vectors)
print(upsert_result)
At this point your knowledge base is live. Your agent can now query against compliance docs, product FAQs, risk policies, or support knowledge without hardcoding answers.
4) Retrieve relevant context for a user query
When a user asks a question, embed the query with the same OpenAI embedding model and search Pinecone with index.query().
query = "What checks are required before onboarding a new customer?"
query_embedding = openai_client.embeddings.create(
model="text-embedding-3-small",
input=[query]
).data[0].embedding
search_result = index.query(
vector=query_embedding,
top_k=3,
include_metadata=True
)
contexts = [match["metadata"]["text"] for match in search_result["matches"]]
print(contexts)
This returns the most relevant policy snippets. In production, you usually pass these snippets into the generation step as grounded context.
5) Generate the final answer with OpenAI
Use openai_client.responses.create() to produce a response that cites retrieved context instead of guessing.
context_block = "\n\n".join([f"- {c}" for c in contexts])
response = openai_client.responses.create(
model="gpt-4.1-mini",
input=f"""
You are a fintech operations assistant.
Answer only using the provided context.
Context:
{context_block}
Question:
{query}
"""
)
print(response.output_text)
This gives you a clean retrieval-augmented generation flow:
- •embed user question
- •retrieve from Pinecone
- •generate answer with OpenAI using retrieved context
Testing the Integration
Run an end-to-end test with one known compliance question. You want to verify that retrieval returns relevant chunks and that generation stays anchored to them.
test_query = "What verification is needed during customer onboarding?"
q_emb = openai_client.embeddings.create(
model="text-embedding-3-small",
input=[test_query]
).data[0].embedding
matches = index.query(vector=q_emb, top_k=1, include_metadata=True)["matches"]
assert len(matches) > 0
answer = openai_client.responses.create(
model="gpt-4.1-mini",
input=f"""
Use only this context:
{matches[0]["metadata"]["text"]}
Question: {test_query}
"""
)
print("Retrieved:", matches[0]["metadata"]["text"])
print("Answer:", answer.output_text)
Expected output:
Retrieved: Customer onboarding requires government ID verification, proof of address, and sanctions screening.
Answer: Customer onboarding requires government ID verification, proof of address, and sanctions screening.
If the retrieved text is unrelated, fix your chunking strategy or revisit your embedding/index setup. If the answer invents details not present in context, tighten your system prompt and reduce temperature by using a stricter response configuration in your application layer.
Real-World Use Cases
- •Compliance assistant: Answer AML/KYC questions from internal policy docs with traceable retrieval from Pinecone.
- •Customer support agent: Ground responses in product manuals, fee schedules, dispute handling rules, and escalation paths.
- •Risk ops copilot: Retrieve transaction monitoring procedures and generate analyst-ready summaries for suspicious activity reviews.
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