How to Integrate LlamaIndex for fintech with Supabase for startups
Why this integration matters
If you’re building an AI agent for a fintech startup, you need two things: retrieval over your financial data and a place to persist state, metadata, and audit trails. LlamaIndex gives you the retrieval layer; Supabase gives you Postgres, auth, and storage without standing up your own backend.
The useful pattern here is simple: index financial documents, transaction notes, policy docs, or support tickets with LlamaIndex, then store embeddings metadata, user state, and agent outputs in Supabase. That gives you a production-friendly foundation for agents that answer questions, route cases, and keep a trace of what happened.
Prerequisites
- •Python 3.10+
- •A Supabase project with:
- •
SUPABASE_URL - •
SUPABASE_SERVICE_ROLE_KEYor anon key for testing
- •
- •A Postgres database in Supabase
- •Access to an embedding model provider used by LlamaIndex
- •Installed packages:
- •
llama-index - •
llama-index-vector-stores-supabase - •
supabase - •
python-dotenv
- •
- •A
.envfile with your secrets - •Basic familiarity with:
- •LlamaIndex
VectorStoreIndex - •Supabase Python client
- •Postgres tables and permissions
- •LlamaIndex
Integration Steps
1) Install the dependencies
Start by installing the core packages. For fintech use cases, I recommend keeping the vector store in Supabase so your app has one source of truth for documents and metadata.
pip install llama-index supabase python-dotenv llama-index-vector-stores-supabase
If you’re using OpenAI embeddings or another provider through LlamaIndex, install that integration too.
pip install llama-index-embeddings-openai llama-index-llms-openai
2) Configure environment variables
Keep credentials out of code. Load them from .env and initialize both clients from the same config file.
import os
from dotenv import load_dotenv
load_dotenv()
SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_SERVICE_ROLE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
assert SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY and OPENAI_API_KEY
For startup teams, this matters because your agent will likely run in multiple environments: local dev, staging, and production. Don’t hardcode keys into notebooks or scripts.
3) Create the Supabase client and vector store
Use the official Supabase Python client for app-level writes and the LlamaIndex Supabase vector store for retrieval. This split is clean: Supabase handles operational data; LlamaIndex handles semantic search.
from supabase import create_client
from llama_index.vector_stores.supabase import SupabaseVectorStore
supabase = create_client(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY)
vector_store = SupabaseVectorStore(
postgres_connection_string=(
f"postgresql://postgres:{os.getenv('SUPABASE_DB_PASSWORD')}"
f"@{os.getenv('SUPABASE_HOST')}:{os.getenv('SUPABASE_PORT')}/postgres"
),
collection_name="fintech_docs",
)
If you already have a managed Postgres connection string from Supabase, use that directly. The important part is that LlamaIndex writes vectors into Postgres-backed storage while your application still uses the standard Supabase SDK for everything else.
4) Build an index from fintech documents
Now ingest documents such as loan policies, KYC procedures, support playbooks, or risk memos. Use VectorStoreIndex.from_documents() so LlamaIndex can chunk, embed, and persist them into your Supabase vector store.
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.embeddings.openai import OpenAIEmbedding
documents = SimpleDirectoryReader("./fintech_docs").load_data()
index = VectorStoreIndex.from_documents(
documents,
vector_store=vector_store,
embed_model=OpenAIEmbedding(model="text-embedding-3-small"),
)
In a startup environment, this is usually run as a background job whenever new policy docs or product notes land in your system. You can also attach metadata like document type or team ownership before indexing.
5) Query through LlamaIndex and persist agent state in Supabase
Once indexed, query through a retriever or query engine. Then write the result back to Supabase so your agent has an audit trail of what it answered.
from datetime import datetime
query_engine = index.as_query_engine()
response = query_engine.query(
"What are the approval rules for high-risk merchant accounts?"
)
supabase.table("agent_interactions").insert({
"user_id": "user_123",
"question": "What are the approval rules for high-risk merchant accounts?",
"answer": str(response),
"created_at": datetime.utcnow().isoformat()
}).execute()
print(response)
That pattern is useful because retrieval alone is not enough in fintech. You usually need traceability for compliance reviews, customer support escalation, or internal QA.
Testing the Integration
Run a quick smoke test against one known document. This verifies three things: embeddings work, vectors are stored in Supabase-backed infrastructure, and the agent can retrieve relevant text.
test_query = "Summarize our KYC requirements for business accounts."
result = query_engine.query(test_query)
print("QUERY:", test_query)
print("ANSWER:", result)
Expected output will look like this:
QUERY: Summarize our KYC requirements for business accounts.
ANSWER: Business accounts require government-issued ID...
If you also want to verify persistence in Supabase:
rows = supabase.table("agent_interactions").select("*").limit(1).execute()
print(rows.data)
Expected output:
[{'user_id': 'user_123', 'question': 'What are the approval rules...', 'answer': '...', 'created_at': '...'}]
Real-World Use Cases
- •
Fintech support copilot
- •Index policy docs, fee schedules, dispute procedures, and product FAQs.
- •Store every answer in Supabase so support leads can review responses later.
- •
Compliance assistant
- •Retrieve KYC/AML procedures from indexed internal docs.
- •Persist case notes and decision history in Supabase tables for auditability.
- •
Customer onboarding agent
- •Use LlamaIndex to answer onboarding questions from internal knowledge bases.
- •Use Supabase to track onboarding status per customer and keep workflow state.
The clean architecture here is: LlamaIndex handles semantic retrieval; Supabase handles persistence and operational data. That split keeps your agent system understandable when you move from prototype to production.
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