How to Integrate LlamaIndex for fintech with Supabase for AI agents

By Cyprian AaronsUpdated 2026-04-22
llamaindex-for-fintechsupabaseai-agents

Combining LlamaIndex for fintech with Supabase gives you a practical stack for agentic finance workflows: LlamaIndex handles retrieval over financial documents, transaction data, and policy knowledge, while Supabase gives you Postgres, auth, storage, and realtime state for the agent. That means you can build assistants that answer compliance questions, summarize portfolio activity, and persist agent memory without bolting together half a dozen services.

Prerequisites

  • Python 3.10+
  • A Supabase project with:
    • SUPABASE_URL
    • SUPABASE_ANON_KEY or service role key for server-side jobs
  • A PostgreSQL table for agent memory or financial records
  • Access to your LlamaIndex setup:
    • llama-index
    • an embedding model provider
    • an LLM provider for generation
  • Optional but useful:
    • python-dotenv
    • supabase-py
    • pandas for loading tabular finance data

Install the core packages:

pip install llama-index supabase python-dotenv pandas

Integration Steps

  1. Set up Supabase as the persistence layer

Use Supabase to store documents, embeddings metadata, or conversation state. For fintech agents, I usually keep raw source records in one table and agent memory in another.

import os
from supabase import create_client, Client

SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY")

supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)

# Example: write a finance note into Supabase
response = supabase.table("agent_memory").insert({
    "user_id": "user_123",
    "session_id": "sess_456",
    "memory_type": "portfolio_summary",
    "content": "Client prefers low-risk fixed income exposure.",
}).execute()

print(response.data)
  1. Load fintech data into LlamaIndex

LlamaIndex works best when you normalize source data into documents. For a fintech use case, that might be PDFs from filings, CSVs of transactions, or internal policy docs.

import pandas as pd
from llama_index.core import Document

df = pd.read_csv("transactions.csv")

documents = []
for _, row in df.iterrows():
    text = (
        f"Transaction ID: {row['transaction_id']}\n"
        f"Account: {row['account_id']}\n"
        f"Amount: {row['amount']}\n"
        f"Merchant: {row['merchant']}\n"
        f"Category: {row['category']}\n"
        f"Date: {row['date']}"
    )
    documents.append(Document(text=text))

print(f"Loaded {len(documents)} transaction documents")
  1. Build a vector index and connect it to your agent workflow

This is where LlamaIndex does the retrieval work. Use a vector store-backed index if you want persistence; use Supabase to store metadata or chat state alongside it.

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

Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
Settings.llm = OpenAI(model="gpt-4o-mini", temperature=0)

index = VectorStoreIndex.from_documents(documents)

query_engine = index.as_query_engine(similarity_top_k=3)

answer = query_engine.query(
    "Which transactions look like recurring subscription charges?"
)
print(answer)

If you want the agent to remember prior decisions or compliance notes, write them back to Supabase after each turn.

memory_record = {
    "user_id": "user_123",
    "session_id": "sess_456",
    "memory_type": "retrieval_answer",
    "content": str(answer),
}

supabase.table("agent_memory").insert(memory_record).execute()
  1. Use Supabase as the system-of-record for agent context

For production agents, don’t keep context only in RAM. Pull session state from Supabase before each query so your assistant can resume conversations across requests.

def load_session_memory(session_id: str):
    result = (
        supabase.table("agent_memory")
        .select("*")
        .eq("session_id", session_id)
        .order("created_at", desc=False)
        .execute()
    )
    return result.data

session_memory = load_session_memory("sess_456")
for item in session_memory:
    print(item["memory_type"], item["content"])

You can then inject that context into your prompt or use it to filter what gets retrieved from LlamaIndex.

  1. Wire retrieval + persistence into one agent loop

This pattern is what you actually ship: fetch state from Supabase, retrieve relevant finance knowledge with LlamaIndex, generate an answer, then persist the interaction back to Supabase.

def answer_finance_question(session_id: str, question: str):
    history = load_session_memory(session_id)

    context_snippets = "\n".join(
        f"- {item['memory_type']}: {item['content']}" for item in history[-5:]
    )

    prompt = f"""
You are a fintech assistant.
Use prior session context when relevant.

Session context:
{context_snippets}

Question:
{question}
"""

    response = query_engine.query(prompt)

    supabase.table("agent_memory").insert({
        "user_id": "user_123",
        "session_id": session_id,
        "memory_type": "qa_turn",
        "content": f"Q: {question}\nA: {response}",
    }).execute()

    return response

print(answer_finance_question(
    "sess_456",
    "Summarize risk signals from recent card transactions."
))

Testing the Integration

Run a simple end-to-end check: insert memory into Supabase, query LlamaIndex over sample finance docs, then persist the answer back.

test_question = "List suspicious patterns in these transactions."
result = answer_finance_question("test_session", test_question)

print("RESULT:", result)

saved = (
    supabase.table("agent_memory")
    .select("*")
    .eq("session_id", "test_session")
    .eq("memory_type", "qa_turn")
    .order("created_at", desc=True)
    .limit(1)
    .execute()
)

print("SAVED ROW:", saved.data[0]["content"])

Expected output:

RESULT: Transactions on the same merchant appear weekly with near-identical amounts.
SAVED ROW: Q: List suspicious patterns in these transactions.
A: Transactions on the same merchant appear weekly with near-identical amounts.

Real-World Use Cases

  • Compliance copilot
    Answer questions against policy docs, KYC notes, and transaction histories while storing audit trails in Supabase.

  • Fraud triage assistant
    Retrieve similar historical cases with LlamaIndex and persist analyst decisions and labels in Supabase for later review.

  • Client portfolio assistant
    Summarize holdings, flag concentration risk, and keep session memory so advisors can resume conversations without losing context.


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