How to Integrate OpenAI for pension funds with Pinecone for multi-agent systems
Pension fund workflows are document-heavy, policy-driven, and full of repeat questions across teams. Pairing OpenAI for pension funds with Pinecone gives you a retrieval layer for investment policy docs, member communications, actuarial notes, and compliance procedures, so your agents can answer with grounded context instead of guessing.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key and an existing Pinecone index
- •
pipinstalled packages:- •
openai - •
pinecone - •
python-dotenv
- •
- •A vector embedding model configured in OpenAI
- •A Pinecone index dimension that matches your embedding model output
- •Access to the pension fund documents you want to index
Install dependencies:
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="pension-fund-agent-index"
Integration Steps
- •Initialize both clients
Start by loading credentials and creating SDK clients. Keep this in a shared config module if you have multiple agents.
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_name = os.environ["PINECONE_INDEX_NAME"]
index = pc.Index(index_name)
- •Create embeddings for pension fund content
Use OpenAI embeddings to convert policy text into vectors. In production, chunk documents first; here’s the core pattern.
docs = [
{
"id": "policy_001",
"text": "Members can request partial transfer values subject to trustee approval and scheme rules."
},
{
"id": "policy_002",
"text": "Annual benefit statements must be issued within regulatory deadlines."
}
]
texts = [d["text"] for d in docs]
embedding_response = openai_client.embeddings.create(
model="text-embedding-3-small",
input=texts
)
vectors = []
for doc, item in zip(docs, embedding_response.data):
vectors.append({
"id": doc["id"],
"values": item.embedding,
"metadata": {
"text": doc["text"],
"source": "pension_policy"
}
})
- •Upsert vectors into Pinecone
Push the embedded chunks into your index with metadata attached. That metadata is what your agent will use to cite or filter results later.
upsert_result = index.upsert(vectors=vectors)
print(upsert_result)
If you are building multi-agent systems, keep one namespace per domain or agent role.
index.upsert(
vectors=vectors,
namespace="member_services"
)
- •Query Pinecone from an agent workflow
When a user asks a question, embed the query with the same model, retrieve the top matches from Pinecone, then pass the retrieved context to OpenAI for generation.
user_query = "Can a member request a partial transfer value?"
query_embedding = openai_client.embeddings.create(
model="text-embedding-3-small",
input=user_query
).data[0].embedding
search_results = index.query(
vector=query_embedding,
top_k=3,
include_metadata=True,
namespace="member_services"
)
context_chunks = [
match["metadata"]["text"]
for match in search_results["matches"]
]
context = "\n\n".join(context_chunks)
- •Generate the final answer with grounded context
Use OpenAI chat completions with retrieved context injected into the prompt. This is the pattern you want in production: retrieve first, generate second.
messages = [
{
"role": "system",
"content": (
"You are a pension fund operations assistant. "
"Answer only using the provided context. "
"If the context is insufficient, say so."
)
},
{
"role": "user",
"content": f"Context:\n{context}\n\nQuestion: {user_query}"
}
]
response = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
temperature=0.2
)
print(response.choices[0].message.content)
Testing the Integration
Use a simple end-to-end test: embed a known policy sentence, store it, query it back, and verify the answer references that policy.
test_query = "What happens if a member requests a partial transfer value?"
q_embedding = openai_client.embeddings.create(
model="text-embedding-3-small",
input=test_query
).data[0].embedding
results = index.query(
vector=q_embedding,
top_k=1,
include_metadata=True,
namespace="member_services"
)
print("Top match:", results["matches"][0]["metadata"]["text"])
answer = openai_client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Answer only from context."},
{
"role": "user",
"content": f"Context: {results['matches'][0]['metadata']['text']}\nQuestion: {test_query}"
}
]
)
print("Agent answer:", answer.choices[0].message.content)
Expected output:
Top match: Members can request partial transfer values subject to trustee approval and scheme rules.
Agent answer: Members may request a partial transfer value subject to trustee approval and scheme rules.
Real-World Use Cases
- •
Member servicing agent
- •Answers benefit questions using indexed scheme rules, FAQs, and communications templates.
- •Reduces escalations to human support when the answer exists in policy docs.
- •
Compliance review agent
- •Retrieves relevant regulatory guidance and internal procedures before drafting responses.
- •Helps teams check whether outbound communications align with current policy language.
- •
Operations copilot for multi-agent systems
- •One agent handles retrieval from Pinecone.
- •Another agent drafts responses with OpenAI.
- •A supervisor agent routes queries by topic: benefits, contributions, transfers, or complaints.
The pattern is stable: embed once, store in Pinecone, retrieve on demand, then let OpenAI generate against verified context. That gives pension fund teams an agent system that is auditable enough for production and useful enough for real operations.
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