How to Integrate OpenAI for wealth management with Pinecone for production AI
Why this integration matters
If you’re building AI for wealth management, the hard part is not generating text. It’s grounding answers in client-specific data: portfolio notes, investment policy statements, suitability rules, market commentary, and prior advisor interactions.
OpenAI handles reasoning and response generation. Pinecone gives you fast semantic retrieval over your private wealth-management corpus. Combined, you get an agent that can answer with context instead of hallucinating from general finance knowledge.
Prerequisites
Before you wire this up, make sure you have:
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key
- •A Pinecone index created with the right vector dimension for your embedding model
- •A document store or source files for:
- •client meeting notes
- •investment policy statements
- •product brochures
- •internal research summaries
- •Installed packages:
- •
openai - •
pinecone - •
python-dotenv
- •
Install them:
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="wealth-management-index"
Integration Steps
1) Initialize OpenAI and Pinecone clients
Use the official SDKs and keep credentials out of code. In production, load secrets from your vault or secret manager.
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)
At this point you have two primitives:
- •OpenAI for embeddings and generation
- •Pinecone for vector search
2) Convert wealth documents into embeddings
For wealth management use cases, chunk documents by section or paragraph. Don’t embed entire PDFs as one blob.
from typing import List
docs = [
{
"id": "ips_001_chunk_01",
"text": "Client prefers capital preservation, moderate income, and ESG screens.",
"metadata": {"client_id": "client_001", "source": "IPS", "doc_type": "policy"}
},
{
"id": "note_014_chunk_02",
"text": "Advisor discussed tax-loss harvesting opportunities in Q4 rebalancing.",
"metadata": {"client_id": "client_001", "source": "meeting_note", "doc_type": "note"}
}
]
def embed_text(text: str) -> List[float]:
response = openai_client.embeddings.create(
model="text-embedding-3-small",
input=text
)
return response.data[0].embedding
vectors = []
for doc in docs:
vectors.append({
"id": doc["id"],
"values": embed_text(doc["text"]),
"metadata": {
**doc["metadata"],
"text": doc["text"]
}
})
For production AI, keep the original text in metadata only if it fits your governance policy. If not, store a reference ID and fetch the source from your document system.
3) Upsert vectors into Pinecone
Now push the chunks into the index.
upsert_response = index.upsert(vectors=vectors)
print(upsert_response)
If you are indexing at scale, batch your upserts.
def batched(items, batch_size=100):
for i in range(0, len(items), batch_size):
yield items[i:i + batch_size]
for batch in batched(vectors, batch_size=50):
index.upsert(vectors=batch)
A few production rules here:
- •Use stable IDs so updates overwrite cleanly
- •Store
client_id,doc_type, andtimestampin metadata - •Separate tenant data by namespace if multiple advisors or firms share the same index
4) Query Pinecone with a user question and build grounded context
When a user asks a question, embed the query first, then retrieve relevant chunks.
query = "What does this client prefer regarding risk and portfolio construction?"
query_embedding = embed_text(query)
results = index.query(
vector=query_embedding,
top_k=3,
include_metadata=True,
filter={"client_id": {"$eq": "client_001"}}
)
matches = results["matches"]
context_blocks = []
for match in matches:
meta = match["metadata"]
context_blocks.append(f"- {meta['text']}")
context = "\n".join(context_blocks)
print(context)
This is where Pinecone earns its keep. You are no longer asking the model to guess; you are giving it client-specific evidence.
5) Generate the final answer with OpenAI Responses API
Use retrieved context as grounding input. Keep the prompt strict so the model stays inside the retrieved material.
system_prompt = (
"You are a wealth management assistant. "
"Answer only using the provided context. "
"If the context is insufficient, say what is missing."
)
user_prompt = f"""
Question: {query}
Context:
{context}
Answer concisely and cite which context lines support your answer.
"""
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)
That pattern is production-friendly because it separates retrieval from generation. If compliance asks why the agent answered something, you can trace it back to Pinecone matches.
Testing the Integration
Run a simple end-to-end test: embed a known note, retrieve it with a related query, then generate an answer.
test_query = "Does the client care more about capital preservation or aggressive growth?"
test_embedding = embed_text(test_query)
test_results = index.query(
vector=test_embedding,
top_k=1,
include_metadata=True,
filter={"client_id": {"$eq": "client_001"}}
)
top_match = test_results["matches"][0]["metadata"]["text"]
test_response = openai_client.responses.create(
model="gpt-4.1-mini",
input=f"Context: {top_match}\n\nQuestion: {test_query}\nAnswer:"
)
print("Retrieved:", top_match)
print("Model answer:", test_response.output_text)
Expected output:
Retrieved: Client prefers capital preservation, moderate income, and ESG screens.
Model answer: The client prioritizes capital preservation over aggressive growth.
If retrieval returns irrelevant chunks, fix chunking or metadata filters before touching the prompt.
Real-World Use Cases
- •
Advisor copilot
- •Answer client questions using portfolio notes, IPS documents, and prior meeting history.
- •Draft follow-up emails grounded in actual account context.
- •
Suitability and policy assistant
- •Check whether a proposed recommendation conflicts with documented risk tolerance or restrictions.
- •Surface missing KYC/AML details before an advisor proceeds.
- •
Research retrieval for internal teams
- •Let analysts query market commentary, house views, and fund notes through natural language.
- •Keep responses tied to approved internal sources instead of free-form model guesses.
If you’re building this for production AI in wealth management, keep one rule in mind: OpenAI generates language, but Pinecone decides what facts enter the conversation. That separation is what makes the system usable under real compliance constraints.
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