How to Integrate OpenAI for insurance with Pinecone for startups
Combining OpenAI for insurance with Pinecone gives you a practical pattern for building AI agents that answer policy questions, retrieve claims context, and ground responses in approved documents. OpenAI handles the reasoning and response generation; Pinecone gives the agent fast semantic retrieval over policy PDFs, underwriting notes, claims histories, and knowledge base articles.
For startups, this is the difference between a generic chatbot and an assistant that can actually support brokers, adjusters, and customer service teams with company-specific answers.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key
- •A Pinecone index created in advance
- •Access to your insurance knowledge base:
- •policy documents
- •claims guidelines
- •FAQ articles
- •underwriting playbooks
- •Installed packages:
- •
openai - •
pinecone - •
python-dotenv
- •
pip install openai pinecone python-dotenv
Integration Steps
- •Load credentials and initialize both clients
Keep secrets in environment variables. For production, use a secret manager, but .env is fine for local development.
import os
from dotenv import load_dotenv
from openai import OpenAI
from pinecone import Pinecone
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
PINECONE_API_KEY = os.getenv("PINECONE_API_KEY")
PINECONE_INDEX_NAME = os.getenv("PINECONE_INDEX_NAME", "insurance-agent-index")
client = OpenAI(api_key=OPENAI_API_KEY)
pc = Pinecone(api_key=PINECONE_API_KEY)
index = pc.Index(PINECONE_INDEX_NAME)
- •Create embeddings for your insurance content
Use OpenAI embeddings to convert policy text into vectors. For insurance workflows, chunk content by section: exclusions, coverage limits, deductibles, claim steps.
def embed_text(text: str) -> list[float]:
response = client.embeddings.create(
model="text-embedding-3-small",
input=text
)
return response.data[0].embedding
policy_chunk = """
If water damage results from a sudden pipe burst inside the insured premises,
the loss is covered up to $25,000 after the deductible.
Damage caused by gradual leakage is excluded.
"""
vector = embed_text(policy_chunk)
print(len(vector))
- •Upsert vectors into Pinecone
Store each chunk with metadata so you can filter by document type, product line, or jurisdiction later.
from uuid import uuid4
chunk_id = str(uuid4())
index.upsert(
vectors=[
{
"id": chunk_id,
"values": vector,
"metadata": {
"source": "homeowners_policy_2025.pdf",
"section": "water_damage",
"product": "homeowners",
"jurisdiction": "US"
}
}
]
)
print(f"Upserted vector: {chunk_id}")
- •Retrieve relevant context for a user query
When a user asks a question, embed the query and search Pinecone for the closest matches. This is where your agent gets grounded context instead of guessing.
def retrieve_context(query: str, top_k: int = 3) -> str:
query_vector = embed_text(query)
results = index.query(
vector=query_vector,
top_k=top_k,
include_metadata=True
)
chunks = []
for match in results["matches"]:
meta = match["metadata"]
chunks.append(
f"Source: {meta.get('source')}\n"
f"Section: {meta.get('section')}\n"
f"Score: {match['score']}\n"
)
return "\n---\n".join(chunks)
query = "Does the policy cover a burst pipe that flooded the kitchen?"
context = retrieve_context(query)
print(context)
- •Generate an insurance-safe answer with OpenAI
Pass retrieved context into the model and instruct it to answer only from the provided material. This is how you reduce hallucinations in claims and policy support flows.
def answer_question(query: str) -> str:
context = retrieve_context(query)
prompt = f"""
You are an insurance assistant.
Answer only using the provided context.
If the context does not contain enough information, say so clearly.
Context:
{context}
Question:
{query}
"""
response = client.responses.create(
model="gpt-4.1-mini",
input=prompt
)
return response.output_text
answer = answer_question("Does the policy cover a burst pipe that flooded the kitchen?")
print(answer)
Testing the Integration
Run a quick end-to-end test with one known policy fact and one query that should match it.
test_query = "Is sudden water damage from a pipe burst covered?"
test_answer = answer_question(test_query)
print("QUERY:", test_query)
print("\nANSWER:", test_answer)
Expected output:
QUERY: Is sudden water damage from a pipe burst covered?
ANSWER: Yes. Based on the retrieved policy section, sudden water damage caused by a pipe burst inside the insured premises is covered up to $25,000 after the deductible.
If you get an empty or vague answer:
- •check that your embedding dimensions match your Pinecone index configuration
- •confirm vectors were actually upserted
- •verify your query text is close enough semantically to stored chunks
- •inspect metadata filters if you’re using them
Real-World Use Cases
- •
Claims triage agent
- •Classify incoming claims emails or FNOL messages
- •Retrieve relevant claim rules and respond with next steps
- •
Policy Q&A assistant
- •Answer coverage questions from brokers or customers
- •Ground every response in approved policy language
- •
Underwriting support agent
- •Retrieve prior submissions, risk notes, and appetite guidelines
- •Help underwriters assess whether a submission fits internal criteria
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