How to Integrate OpenAI for lending with Pinecone for startups
Combining OpenAI for lending with Pinecone gives you a practical pattern for startup credit workflows: generate structured lending decisions, then retrieve the right policy, customer context, and prior cases in milliseconds. That means your agent can answer loan questions, summarize applications, and ground decisions in the right documents instead of guessing.
Prerequisites
- •Python 3.10+
- •An OpenAI API key
- •A Pinecone API key and an existing index
- •
pip install openai pinecone - •A document set for lending context:
- •credit policy docs
- •underwriting rules
- •product FAQs
- •sample loan application records
- •Basic knowledge of embeddings and vector search
Integration Steps
- •Set up your environment variables.
import os
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
os.environ["PINECONE_API_KEY"] = "your-pinecone-api-key"
os.environ["PINECONE_INDEX_NAME"] = "lending-startup-index"
- •Create embedding vectors with OpenAI and prepare data for Pinecone.
Use OpenAI embeddings to turn lending documents into vectors before storing them in Pinecone.
from openai import OpenAI
client = OpenAI()
docs = [
{
"id": "policy_001",
"text": "Minimum credit score for unsecured startup loans is 680. Revenue must exceed $15k monthly.",
"metadata": {"type": "policy", "source": "underwriting_manual"}
},
{
"id": "faq_001",
"text": "Applicants can upload bank statements, tax returns, and incorporation documents.",
"metadata": {"type": "faq", "source": "support_center"}
}
]
texts = [d["text"] for d in docs]
response = client.embeddings.create(
model="text-embedding-3-small",
input=texts
)
vectors = []
for doc, item in zip(docs, response.data):
vectors.append({
"id": doc["id"],
"values": item.embedding,
"metadata": {**doc["metadata"], "text": doc["text"]}
})
- •Upsert vectors into Pinecone.
This stores your lending knowledge so your agent can retrieve relevant context later.
from pinecone import Pinecone
pc = Pinecone(api_key=os.environ["PINECONE_API_KEY"])
index = pc.Index(os.environ["PINECONE_INDEX_NAME"])
index.upsert(vectors=vectors)
print("Upsert complete")
- •Query Pinecone with a user question and pass the retrieved context to OpenAI.
This is the core RAG pattern: retrieve first, then generate.
query = "What are the requirements for an unsecured startup loan?"
query_embedding = 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)
prompt = f"""
You are a lending assistant.
Answer using only the provided context.
Context:
{context}
Question:
{query}
"""
completion = client.responses.create(
model="gpt-4o-mini",
input=prompt
)
print(completion.output_text)
- •Wrap it into a reusable agent function.
In production, keep retrieval and generation together so your app can serve consistent answers.
def answer_lending_question(question: str) -> str:
q_emb = client.embeddings.create(
model="text-embedding-3-small",
input=[question]
).data[0].embedding
res = index.query(
vector=q_emb,
top_k=3,
include_metadata=True
)
context = "\n\n".join(
match["metadata"]["text"] for match in res["matches"]
)
prompt = f"""
You are a lending operations assistant.
Use only this context to answer:
{context}
Question: {question}
"""
out = client.responses.create(
model="gpt-4o-mini",
input=prompt
)
return out.output_text
answer = answer_lending_question("Can a startup qualify with $12k monthly revenue?")
print(answer)
Testing the Integration
Run a simple end-to-end check: embed a query, retrieve from Pinecone, then generate an answer from OpenAI.
test_question = "What documents are required for a startup loan application?"
answer = answer_lending_question(test_question)
print("QUESTION:", test_question)
print("ANSWER:", answer)
Expected output:
QUESTION: What documents are required for a startup loan application?
ANSWER: Applicants can upload bank statements, tax returns, and incorporation documents.
If you get an answer grounded in your stored docs, the integration is working. If the response drifts outside the policy text, tighten your prompt and reduce temperature by using a more deterministic model choice or stricter instruction wording.
Real-World Use Cases
- •
Loan intake assistant
- •Collects applicant details, retrieves relevant underwriting rules, and drafts a structured summary for analysts.
- •
Policy-aware support bot
- •Answers borrower questions using approved lending documentation stored in Pinecone.
- •
Case similarity search
- •Finds prior applications similar to the current one so underwriters can review precedent before making decisions.
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