How to Integrate LlamaIndex for banking with Supabase for startups
Combining LlamaIndex for banking with Supabase gives you a clean pattern for building internal banking copilots, compliance assistants, and customer support agents that can both retrieve regulated knowledge and persist state. LlamaIndex handles retrieval, indexing, and agent orchestration; Supabase gives you Postgres, auth, and storage for app data, conversation history, and audit trails.
Prerequisites
- •Python 3.10+
- •A Supabase project with:
- •
SUPABASE_URL - •
SUPABASE_ANON_KEYor service role key for backend use
- •
- •A Postgres database in Supabase
- •Access to your banking data sources:
- •PDFs, policy docs, product docs, FAQs, or internal runbooks
- •Installed packages:
- •
llama-index - •
llama-index-vector-stores-supabase - •
supabase - •
python-dotenv
- •
- •An embedding model API key if your LlamaIndex setup requires one
- •Basic familiarity with Python async/sync calls and environment variables
Integration Steps
- •Install the dependencies and load configuration.
pip install llama-index supabase python-dotenv llama-index-vector-stores-supabase
from dotenv import load_dotenv
import os
load_dotenv()
SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
- •Connect to Supabase and create a place to store agent state.
For startups, don’t keep chat memory in local files. Put session state in Supabase so you can recover conversations across workers and deploys.
from supabase import create_client, Client
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
# Example: create a table externally in Supabase SQL editor:
# create table if not exists agent_sessions (
# id uuid primary key default gen_random_uuid(),
# user_id text not null,
# session_id text not null,
# message jsonb not null,
# created_at timestamptz default now()
# );
- •Build a LlamaIndex vector index backed by Supabase.
This is the core integration point. Use Supabase as the vector store so your banking documents are searchable from the agent.
from llama_index.core import VectorStoreIndex, StorageContext, SimpleDirectoryReader
from llama_index.vector_stores.supabase import SupabaseVectorStore
vector_store = SupabaseVectorStore(
postgres_connection_string=os.getenv("SUPABASE_POSTGRES_CONNECTION_STRING"),
collection_name="banking_docs",
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
documents = SimpleDirectoryReader("./banking_docs").load_data()
index = VectorStoreIndex.from_documents(
documents,
storage_context=storage_context,
)
If you already have indexed content, you can load it through the same storage context later without rebuilding everything.
- •Create a query engine and wrap it in an agent workflow.
For banking use cases, keep the retrieval layer narrow. The agent should answer from approved sources only, then persist the interaction in Supabase for auditability.
from llama_index.core import Settings
from llama_index.core.agent import ReActAgent
query_engine = index.as_query_engine(similarity_top_k=3)
agent = ReActAgent.from_tools(
tools=[],
llm=Settings.llm,
verbose=True,
)
response = query_engine.query(
"What is the escalation path for suspicious transaction alerts?"
)
print(response)
If you want tool-based orchestration, add a custom tool that writes every user query and response to Supabase:
from llama_index.core.tools import FunctionTool
def save_session_message(user_id: str, session_id: str, role: str, content: str):
supabase.table("agent_sessions").insert({
"user_id": user_id,
"session_id": session_id,
"message": {
"role": role,
"content": content
}
}).execute()
return {"status": "ok"}
save_message_tool = FunctionTool.from_defaults(fn=save_session_message)
- •Store retrieval results and metadata back into Supabase.
This gives you traceability for compliance reviews and debugging. You can store document IDs, confidence scores, and the final answer alongside each interaction.
def log_agent_answer(user_id: str, session_id: str, question: str, answer: str):
supabase.table("agent_sessions").insert({
"user_id": user_id,
"session_id": session_id,
"message": {
"role": "assistant",
"question": question,
"content": answer
}
}).execute()
answer_text = str(response)
log_agent_answer(
user_id="u_123",
session_id="s_456",
question="What is the escalation path for suspicious transaction alerts?",
answer=answer_text,
)
Testing the Integration
Run a simple end-to-end check: query indexed content and confirm both retrieval and persistence work.
test_question = "How do we handle customer KYC exceptions?"
result = query_engine.query(test_question)
supabase.table("agent_sessions").insert({
"user_id": "test_user",
"session_id": "test_session",
"message": {
"role": "assistant",
"content": str(result)
}
}).execute()
print("Answer:", result)
print("Saved to Supabase:", True)
Expected output:
Answer: [retrieved response from your banking docs]
Saved to Supabase: True
If this fails, check these first:
- •Supabase connection string format
- •Table permissions on
agent_sessions - •Whether your document embeddings were created successfully
- •Whether the collection name matches what you configured in Supabase
Real-World Use Cases
- •
Internal policy copilot
- •Staff ask questions about KYC rules, AML escalation paths, or product policies.
- •LlamaIndex retrieves from approved banking docs.
- •Supabase stores conversation history and audit logs.
- •
Customer support assistant
- •The agent answers account-opening or loan-product questions from curated knowledge.
- •Supabase keeps ticket context and user metadata.
- •You can hand off unresolved cases to humans with full traceability.
- •
Compliance review assistant
- •Analysts search across procedures, controls, and regulatory notes.
- •The system logs every query-response pair into Postgres for review.
- •This makes it easier to prove what information was surfaced to an operator.
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