How to Integrate OpenAI for insurance with Pinecone for production AI

By Cyprian AaronsUpdated 2026-04-21
openai-for-insurancepineconeproduction-ai

OpenAI for insurance gives you the reasoning layer for policy questions, claims triage, underwriting support, and document extraction. Pinecone gives you the retrieval layer, so your agent can pull the right policy clauses, claim notes, or product docs before generating an answer.

That combination is what makes an insurance AI agent production-ready: grounded responses, lower hallucination risk, and fast access to domain knowledge at scale.

Prerequisites

  • Python 3.10+
  • An OpenAI API key
  • A Pinecone API key
  • A Pinecone index created with the correct vector dimension for your embedding model
  • Insurance documents chunked into text passages
  • pip install openai pinecone
  • Environment variables set:
    • OPENAI_API_KEY
    • PINECONE_API_KEY

Integration Steps

  1. Install dependencies and initialize clients

    Start by wiring up both SDKs in the same service. Keep this in a dedicated integration module so your agent runtime stays clean.

    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"])
    
  2. Create or connect to your Pinecone index

    For production AI, use one index per embedding model and namespace by business domain, like claims, policy_docs, or underwriting. That keeps retrieval scoped and easier to govern.

    index_name = "insurance-agent-index"
    index = pc.Index(index_name)
    
    # Optional: inspect index metadata if needed
    stats = index.describe_index_stats()
    print(stats)
    
  3. Generate embeddings with OpenAI for insurance and store them in Pinecone

    Use OpenAI embeddings on your insurance text chunks, then upsert vectors into Pinecone with IDs and metadata. In production, store source references so every answer can be traced back to the original document.

    from typing import List
    
    chunks: List[dict] = [
        {
            "id": "policy_001_chunk_01",
            "text": "Collision coverage pays for damage to your vehicle caused by a collision with another vehicle or object.",
            "metadata": {"doc_type": "policy", "product": "auto", "page": 12}
        },
        {
            "id": "claim_014_chunk_03",
            "text": "Claims must be reported within 30 days of the incident unless otherwise required by state law.",
            "metadata": {"doc_type": "claims_guideline", "region": "US", "page": 4}
        }
    ]
    
    texts = [c["text"] for c in chunks]
    
    embedding_response = openai_client.embeddings.create(
        model="text-embedding-3-small",
        input=texts
    )
    
    vectors = []
    for chunk, item in zip(chunks, embedding_response.data):
        vectors.append({
            "id": chunk["id"],
            "values": item.embedding,
            "metadata": {**chunk["metadata"], "text": chunk["text"]}
        })
    
    index.upsert(vectors=vectors, namespace="insurance")
    
  4. Retrieve relevant context from Pinecone for a user query

    When a user asks a question, embed the query with the same OpenAI embedding model, then search Pinecone for the top matches. This is the retrieval step that grounds your agent in actual policy content.

    query = "Does collision coverage pay if I hit a guardrail?"
    
    query_embedding = openai_client.embeddings.create(
        model="text-embedding-3-small",
        input=[query]
    ).data[0].embedding
    
    results = index.query(
        namespace="insurance",
        vector=query_embedding,
        top_k=3,
        include_metadata=True
    )
    
    context_blocks = []
    for match in results.matches:
        context_blocks.append(match.metadata["text"])
    
    context = "\n\n".join(context_blocks)
    print(context)
    
  5. Generate the final answer with OpenAI using retrieved context

    Pass the retrieved passages into a chat completion call. The key pattern here is simple: retrieve first, then generate. Do not let the model answer insurance questions without grounding data.

     messages = [
         {
             "role": "system",
             "content": (
                 "You are an insurance assistant. Answer only using the provided context. "
                 "If the context is insufficient, say you do not have enough information."
             )
         },
         {
             "role": "user",
             "content": f"Context:\n{context}\n\nQuestion:\n{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 known policy question and verify that Pinecone returns relevant passages before OpenAI generates the answer.

test_query = "How long do I have to report a claim?"

test_embedding = openai_client.embeddings.create(
    model="text-embedding-3-small",
    input=[test_query]
).data[0].embedding

test_results = index.query(
    namespace="insurance",
    vector=test_embedding,
    top_k=1,
    include_metadata=True
)

print("Top match:", test_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: {test_results.matches[0].metadata['text']}\nQuestion: {test_query}"}
    ]
)

print("Answer:", answer.choices[0].message.content)

Expected output:

Top match: Claims must be reported within 30 days of the incident unless otherwise required by state law.
Answer: Claims must be reported within 30 days of the incident unless state law says otherwise.

Real-World Use Cases

  • Policy Q&A assistant

    • Answer coverage questions using retrieved policy clauses instead of generic model output.
  • Claims intake copilot

    • Pull prior claim notes, triage rules, and documentation requirements to help agents route cases correctly.
  • Underwriting document assistant

    • Search submission packets, loss runs, and underwriting guidelines to support faster review decisions.

Keep learning

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

Related Guides