How to Integrate OpenAI for wealth management with Pinecone for AI agents
OpenAI for wealth management gives you the reasoning layer: summarizing client context, drafting portfolio commentary, and answering questions in plain English. Pinecone gives you the retrieval layer: fast vector search over policy docs, investment memos, client notes, and market research. Put them together and you get an AI agent that can answer wealth-management questions with grounded context instead of guessing.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key
- •A Pinecone index created with the right embedding dimension
- •Access to your wealth-management knowledge base:
- •product docs
- •investment policy statements
- •client onboarding notes
- •compliance playbooks
- •Installed packages:
- •
openai - •
pinecone - •
python-dotenv
- •
pip install openai pinecone python-dotenv
Integration Steps
- •Set up environment variables and clients.
Use separate clients for OpenAI and Pinecone. Keep credentials out of code; load them from .env.
import os
from dotenv import load_dotenv
from openai import OpenAI
from pinecone import Pinecone
load_dotenv()
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 your wealth-management content.
For retrieval, you need vector embeddings for documents like fee schedules, portfolio guidelines, and advisor notes. Use OpenAI embeddings and store them in Pinecone with metadata.
from openai import OpenAI
docs = [
{
"id": "doc-001",
"text": "Client IPS: target allocation is 60% equities, 30% fixed income, 10% alternatives.",
"metadata": {"source": "ips", "client_id": "c123", "doc_type": "policy"}
},
{
"id": "doc-002",
"text": "Wealth plan note: client prefers low-volatility strategies and quarterly rebalancing.",
"metadata": {"source": "advisor_note", "client_id": "c123", "doc_type": "note"}
}
]
embeddings = openai_client.embeddings.create(
model="text-embedding-3-small",
input=[d["text"] for d in docs]
)
vectors = []
for doc, emb in zip(docs, embeddings.data):
vectors.append({
"id": doc["id"],
"values": emb.embedding,
"metadata": {
**doc["metadata"],
"text": doc["text"]
}
})
index.upsert(vectors=vectors)
- •Retrieve relevant context from Pinecone before calling OpenAI.
This is the core pattern for an AI agent: search first, then reason. Query Pinecone with the user question embedding, then pass the retrieved context into the model.
query = "What portfolio changes fit a low-volatility client who wants quarterly rebalancing?"
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
)
context_chunks = []
for match in results["matches"]:
context_chunks.append(match["metadata"]["text"])
context = "\n\n".join(context_chunks)
print(context)
- •Generate a grounded response with OpenAI.
Use the retrieved context as input to the model. For wealth management workflows, keep the prompt strict: answer only from retrieved facts and flag gaps clearly.
system_prompt = """
You are a wealth-management assistant.
Use only the provided context.
If the context is insufficient, say what is missing.
Do not invent holdings, risk scores, or compliance guidance.
"""
user_prompt = f"""
Question: {query}
Context:
{context}
Answer in concise client-facing language.
"""
response = openai_client.responses.create(
model="gpt-4.1-mini",
input=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
]
)
print(response.output_text)
- •Wrap it as an agent function.
In production, your agent should expose one function that handles retrieval plus generation. That keeps your orchestration layer simple and makes testing easier.
def answer_wealth_question(question: str) -> str:
q_emb = openai_client.embeddings.create(
model="text-embedding-3-small",
input=question
).data[0].embedding
matches = index.query(
vector=q_emb,
top_k=5,
include_metadata=True
)["matches"]
context = "\n\n".join(
m["metadata"]["text"] for m in matches if m.get("metadata")
)
resp = openai_client.responses.create(
model="gpt-4.1-mini",
input=[
{
"role": "system",
"content": (
"You are a wealth-management assistant. "
"Answer only from context. "
"If uncertain, say so."
)
},
{
"role": "user",
"content": f"Question: {question}\n\nContext:\n{context}"
}
]
)
return resp.output_text
print(answer_wealth_question("What does this client prefer for rebalancing?"))
Testing the Integration
Run a small end-to-end test with one query that should clearly match stored content.
test_question = "What allocation and rebalancing preference is documented for client c123?"
answer = answer_wealth_question(test_question)
print("ANSWER:")
print(answer)
Expected output:
ANSWER:
The documented preference for client c123 is a 60% equity / 30% fixed income / 10% alternatives allocation with quarterly rebalancing.
If you get vague output or hallucinated details, check these first:
- •Your Pinecone index dimension matches the embedding model output.
- •The document text is actually stored in metadata.
- •You are passing retrieved context into the prompt.
- •Your system prompt forbids inventing missing facts.
Real-World Use Cases
- •
Advisor copilot
- •Answer questions about IPS rules, client preferences, product suitability, and meeting notes using grounded retrieval.
- •
Portfolio commentary generator
- •Pull recent research notes from Pinecone and have OpenAI draft monthly performance commentary tailored to each client segment.
- •
Compliance-aware Q&A
- •Retrieve policy snippets and let the agent answer operational questions while refusing unsupported recommendations.
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