How to Integrate LlamaIndex for retail banking with Supabase for AI agents
LlamaIndex gives your retail banking agent structured access to documents, policies, product catalogs, and customer context. Supabase gives you a Postgres-backed system of record for auth, vector storage, metadata, and conversation state. Put them together and you get an agent that can answer banking questions from internal knowledge, persist memory, and retrieve customer-specific context without duct-taping services together.
Prerequisites
- •Python 3.10+
- •A Supabase project with:
- •
SUPABASE_URL - •
SUPABASE_SERVICE_ROLE_KEY
- •
- •A LlamaIndex setup with:
- •
llama-index - •a chat model provider installed, such as OpenAI
- •embeddings provider configured
- •
- •A Postgres table or vector store in Supabase for storing:
- •banking documents
- •chunk embeddings
- •agent memory or session state
- •Basic retail banking content ready to index:
- •product brochures
- •fee schedules
- •loan policy docs
- •FAQ content
Install the packages:
pip install llama-index supabase python-dotenv psycopg2-binary sqlalchemy
Integration Steps
- •Connect to Supabase and load your banking data
Start by connecting to Supabase and pulling the source material your agent will use. In retail banking, this is usually PDFs, FAQs, policy docs, or rows from internal tables.
import os
from supabase import create_client
SUPABASE_URL = os.environ["SUPABASE_URL"]
SUPABASE_SERVICE_ROLE_KEY = os.environ["SUPABASE_SERVICE_ROLE_KEY"]
supabase = create_client(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY)
# Example: pull approved retail banking knowledge base rows
response = supabase.table("banking_knowledge_base").select("*").eq("status", "approved").execute()
rows = response.data
documents = []
for row in rows:
documents.append({
"id": row["id"],
"text": row["content"],
"metadata": {
"title": row["title"],
"product": row["product_type"],
"source": "supabase"
}
})
print(f"Loaded {len(documents)} approved records")
- •Turn Supabase data into LlamaIndex documents
LlamaIndex works best when your source data is normalized into Document objects. That gives you a clean path into indexing, retrieval, and later agent reasoning.
from llama_index.core import Document
llama_documents = [
Document(
text=item["text"],
metadata=item["metadata"]
)
for item in documents
]
print(llama_documents[0].metadata)
- •Build an index with LlamaIndex and persist vectors in Supabase
For production banking workflows, keep vectors in a database you already operate. If you're using Supabase’s Postgres backend with pgvector enabled, you can store embeddings there and keep retrieval close to your app data.
from llama_index.core import VectorStoreIndex, StorageContext
from llama_index.vector_stores.supabase import SupabaseVectorStore
# Assumes you have a Supabase vector table already created.
vector_store = SupabaseVectorStore(
postgres_connection_string=os.environ["SUPABASE_POSTGRES_CONNECTION_STRING"],
collection_name="retail_banking_docs"
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
llama_documents,
storage_context=storage_context,
)
query_engine = index.as_query_engine(similarity_top_k=3)
- •Add a retrieval layer for bank-specific questions
Now you can ask questions like a customer service agent would: fees, eligibility, account rules, or loan terms. This is where LlamaIndex does the heavy lifting while Supabase stores the source of truth.
response = query_engine.query(
"What is the overdraft fee for this checking account?"
)
print(str(response))
If you need customer-aware answers, fetch profile context from Supabase first and pass it into the prompt or query pipeline.
customer = supabase.table("customers").select("segment,tier,state").eq("customer_id", "cust_123").single().execute().data
prompt = f"""
Customer segment: {customer['segment']}
Tier: {customer['tier']}
State: {customer['state']}
Question: What savings products are eligible for this customer?
"""
response = query_engine.query(prompt)
print(str(response))
- •Persist conversation memory back into Supabase
Retail banking agents usually need auditability. Store user messages, retrieved document IDs, and final answers in Supabase so compliance teams can inspect what happened later.
from datetime import datetime
supabase.table("agent_conversations").insert({
"conversation_id": "conv_001",
"user_id": "cust_123",
"question": "What is the overdraft fee?",
"answer": str(response),
"retrieved_at": datetime.utcnow().isoformat(),
}).execute()
Testing the Integration
Run a simple end-to-end check: fetch approved knowledge base rows from Supabase, build a LlamaIndex query engine, ask a retail banking question, then verify the answer is returned and logged.
test_question = "How much is the monthly maintenance fee on the basic checking account?"
test_answer = query_engine.query(test_question)
print("QUESTION:", test_question)
print("ANSWER:", test_answer)
supabase.table("integration_tests").insert({
"test_name": "llamaindex_supabase_retail_banking",
"question": test_question,
"answer_preview": str(test_answer)[:500],
"passed": True,
}).execute()
Expected output:
QUESTION: How much is the monthly maintenance fee on the basic checking account?
ANSWER: The monthly maintenance fee is $5 unless the minimum balance requirement is met.
Real-World Use Cases
- •
Retail banking support agent
- •Answer product questions from approved policy docs stored in Supabase.
- •Log every interaction for audit and QA.
- •
Personalized product recommendation assistant
- •Pull customer tier, region, and existing accounts from Supabase.
- •Use LlamaIndex retrieval to recommend eligible savings or loan products.
- •
Internal banker copilot
- •Let branch staff ask natural-language questions over fee schedules, KYC rules, and lending policies.
- •Keep source documents indexed while storing usage history in Supabase for compliance review.
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