How to Integrate LlamaIndex for fintech with Supabase for production AI

By Cyprian AaronsUpdated 2026-04-22
llamaindex-for-fintechsupabaseproduction-ai

Combining LlamaIndex for fintech with Supabase gives you a clean production path for retrieval-backed AI agents: ingest financial documents, index them with domain-aware retrieval, and persist metadata, chat state, and audit trails in Postgres. The result is an agent that can answer questions over filings, policies, KYC docs, transaction notes, or internal playbooks without turning your app into a pile of ad hoc scripts.

Prerequisites

  • Python 3.10+
  • A Supabase project with:
    • SUPABASE_URL
    • SUPABASE_SERVICE_ROLE_KEY
    • a Postgres database with the vector extension enabled if you plan to store embeddings
  • An OpenAI API key or another embedding/LLM provider supported by LlamaIndex
  • llama-index, supabase, and the relevant LlamaIndex integration packages installed
  • A folder of source documents for your fintech use case:
    • PDFs
    • CSVs
    • compliance docs
    • policy manuals
  • Basic familiarity with SQL and Python async/sync client usage

Integration Steps

1) Install the packages

Start with the core libraries and the connector packages you’ll actually use in production.

pip install llama-index supabase sqlalchemy psycopg2-binary
pip install llama-index-embeddings-openai llama-index-llms-openai

If you are using a vector store integration through LlamaIndex, install the matching vector package as well. For production systems, keep your dependencies explicit so upgrades don’t surprise you.

2) Configure Supabase and LlamaIndex clients

Create your clients once and wire them through your app. For Supabase, use the service role key on the server only.

import os
from supabase import create_client, Client

from llama_index.core import Settings
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI

SUPABASE_URL = os.environ["SUPABASE_URL"]
SUPABASE_SERVICE_ROLE_KEY = os.environ["SUPABASE_SERVICE_ROLE_KEY"]
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]

supabase: Client = create_client(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY)

Settings.embed_model = OpenAIEmbedding(api_key=OPENAI_API_KEY)
Settings.llm = OpenAI(api_key=OPENAI_API_KEY, model="gpt-4o-mini")

This gives you one place to manage credentials and model settings. In a fintech agent system, that matters because you’ll usually have separate environments for dev, staging, and prod.

3) Load fintech documents into a LlamaIndex index

Use LlamaIndex to read source documents and build an index. If you’re working with financial statements or policy docs, keep chunk sizes conservative so retrieval stays precise.

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

docs = SimpleDirectoryReader("./fintech_docs").load_data()

index = VectorStoreIndex.from_documents(
    docs,
    show_progress=True,
)

For production AI, don’t stop at indexing. Add metadata like document type, institution name, effective date, and risk category before ingestion if you need filtering later.

for doc in docs:
    doc.metadata.update({
        "source": "policy_manual",
        "business_unit": "lending",
        "jurisdiction": "US",
    })

4) Persist application state in Supabase

Use Supabase as your system of record for agent runs, user sessions, and retrieval logs. That keeps your AI layer stateless while still giving you traceability.

from datetime import datetime

payload = {
    "session_id": "sess_001",
    "user_id": "user_123",
    "query": "What is our maximum exposure limit for unsecured consumer loans?",
    "created_at": datetime.utcnow().isoformat(),
}

response = supabase.table("agent_queries").insert(payload).execute()
print(response.data)

A typical table schema looks like this:

columntype
session_idtext
user_idtext
querytext
created_attimestamptz
answertext
source_nodesjsonb

That structure is enough to support audit trails and human review without forcing your agent logic into the database.

5) Query the index and write results back to Supabase

Now connect retrieval to persistence. Ask LlamaIndex for an answer, then store both the response and supporting context in Supabase.

query_engine = index.as_query_engine(similarity_top_k=3)

question = "What is our maximum exposure limit for unsecured consumer loans?"
result = query_engine.query(question)

supabase.table("agent_queries").update({
    "answer": str(result),
}).eq("session_id", "sess_001").execute()

print(result)

If you need source citations for compliance workflows, extract them from the response object before saving.

source_nodes = []
for node in result.source_nodes:
    source_nodes.append({
        "text": node.node.text[:500],
        "score": node.score,
        "metadata": node.node.metadata,
    })

supabase.table("agent_sources").insert({
    "session_id": "sess_001",
    "sources": source_nodes,
}).execute()

That pattern is what production AI looks like: retrieval in one layer, persistence in another, no hidden state.

Testing the Integration

Run a smoke test that validates both retrieval and database writes.

def test_fintech_agent():
    question = "Summarize our AML escalation policy."
    result = query_engine.query(question)

    assert result is not None
    assert len(str(result)) > 0

    write_resp = supabase.table("integration_checks").insert({
        "check_name": "llamaindex_supabase_smoke_test",
        "status": "passed",
        "details": str(result)[:200],
    }).execute()

    return {
        "answer_preview": str(result)[:300],
        "db_write_count": len(write_resp.data),
    }

print(test_fintech_agent())

Expected output:

{
  'answer_preview': 'The AML escalation policy requires...',
  'db_write_count': 1
}

If this fails, check three things first:

  • Supabase credentials and row-level security policies
  • Document ingestion produced non-empty nodes
  • Your model key can actually complete queries in the target environment

Real-World Use Cases

  • Compliance Q&A agent: answer questions over AML/KYC policies with stored citations and audit logs in Supabase.
  • Client servicing assistant: retrieve account-specific product documentation and save interaction history per customer session.
  • Risk ops copilot: summarize incident reports or underwriting notes from indexed documents while tracking every generated response in Postgres.

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