How to Integrate OpenAI for investment banking with Pinecone for AI agents
OpenAI gives you the reasoning layer for banking workflows. Pinecone gives you low-latency retrieval over deal docs, filings, research notes, and internal policy so your agent can answer with context instead of guessing.
For investment banking, that combination is useful when you need an agent that can read a pitch deck, pull comparable transactions, summarize risk flags, and draft a client-ready response using firm-approved knowledge.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key
- •A Pinecone index created with the right embedding dimension
- •
pipinstalled - •Basic familiarity with embeddings and retrieval-augmented generation
- •Access to the documents you want to index:
- •earnings transcripts
- •CIMs
- •research notes
- •internal playbooks
- •SEC filings
Install the SDKs:
pip install openai pinecone python-dotenv
Set environment variables:
export OPENAI_API_KEY="your-openai-key"
export PINECONE_API_KEY="your-pinecone-key"
export PINECONE_INDEX_NAME="ib-agent-index"
Integration Steps
- •Create embeddings with OpenAI
Use OpenAI embeddings to turn banking documents into vectors. For production, chunk documents before embedding them.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
text = """
Acme Corp reported revenue growth of 18% YoY.
Management expects EBITDA margin expansion in H2.
"""
embedding_response = client.embeddings.create(
model="text-embedding-3-small",
input=text
)
vector = embedding_response.data[0].embedding
print(len(vector))
- •Connect to Pinecone and create or open an index
Make sure the index dimension matches the embedding model output. text-embedding-3-small returns 1536 dimensions.
import os
from pinecone import Pinecone, ServerlessSpec
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index_name = os.environ["PINECONE_INDEX_NAME"]
existing_indexes = [idx["name"] for idx in pc.list_indexes()]
if index_name not in existing_indexes:
pc.create_index(
name=index_name,
dimension=1536,
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-east-1")
)
index = pc.Index(index_name)
print(f"Connected to index: {index_name}")
- •Upsert banking content into Pinecone
Store metadata that matters for retrieval: source, ticker, date, document type, and section. That makes filtering useful later when your agent needs only filings or only internal notes.
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
chunks = [
{
"id": "acme-q2-transcript-001",
"text": "Revenue increased 18% year over year. EBITDA margin improved by 220 basis points.",
"metadata": {"ticker": "ACME", "doc_type": "transcript", "source": "Q2_2025"}
},
{
"id": "acme-risk-note-001",
"text": "Key risks include customer concentration and refinancing exposure in 2026.",
"metadata": {"ticker": "ACME", "doc_type": "risk_note", "source": "internal"}
}
]
vectors = []
for chunk in chunks:
emb = client.embeddings.create(
model="text-embedding-3-small",
input=chunk["text"]
).data[0].embedding
vectors.append({
"id": chunk["id"],
"values": emb,
"metadata": {
**chunk["metadata"],
"text": chunk["text"]
}
})
index.upsert(vectors=vectors)
print("Upsert complete")
- •Retrieve relevant context from Pinecone for a user query
This is the retrieval step your AI agent will use before calling OpenAI for the final answer.
query = "What are the main risks and performance highlights for ACME?"
query_embedding = 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,
filter={"ticker": {"$eq": "ACME"}}
)
for match in results["matches"]:
print(match["score"], match["metadata"]["doc_type"], match["metadata"]["text"])
- •Generate the final response with OpenAI using retrieved context
Pass retrieved chunks into the model as grounding context. In banking workflows, keep the prompt tight and force the model to cite only what it sees.
context_blocks = []
for match in results["matches"]:
md = match["metadata"]
context_blocks.append(f"[{md['doc_type']}] {md['text']}")
context_text = "\n".join(context_blocks)
response = client.responses.create(
model="gpt-4.1-mini",
input=f"""
You are an investment banking assistant.
Answer using only the context below.
Context:
{context_text}
Question:
{query}
"""
)
print(response.output_text)
Testing the Integration
Run a simple end-to-end test: embed a query, retrieve from Pinecone, then generate an answer from OpenAI.
test_query = "Summarize ACME's performance and key risk factors."
q_emb = client.embeddings.create(
model="text-embedding-3-small",
input=test_query
).data[0].embedding
hits = index.query(
vector=q_emb,
top_k=2,
include_metadata=True,
filter={"ticker": {"$eq": "ACME"}}
)
context = "\n".join([h["metadata"]["text"] for h in hits["matches"]])
answer = client.responses.create(
model="gpt-4.1-mini",
input=f"Use this context only:\n{context}\n\nQuestion: {test_query}"
)
print(answer.output_text)
Expected output:
ACME reported 18% revenue growth and EBITDA margin expansion.
Key risks include customer concentration and refinancing exposure in 2026.
If you get irrelevant answers, check these first:
- •embedding dimension matches your Pinecone index
- •metadata filters are correct
- •document chunks are not too large
- •you are actually passing retrieved text into the model prompt
Real-World Use Cases
- •
Deal team copilot
- •Search pitch books, comps, transcripts, and internal notes.
- •Draft investment memos with grounded citations from indexed sources.
- •
Client Q&A assistant
- •Answer questions about portfolio companies using approved research and filings.
- •Filter by ticker, sector, or document type to control scope.
- •
Risk and diligence agent
- •Pull red flags from diligence materials.
- •Summarize concentration risk, covenant issues, refinancing pressure, and management commentary before analyst review.
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