How to Integrate LlamaIndex for banking with Supabase for RAG
Combining LlamaIndex for banking with Supabase gives you a practical RAG stack for regulated knowledge retrieval. You get LlamaIndex handling document ingestion, chunking, embeddings, and query orchestration, while Supabase gives you Postgres-backed storage with pgvector for persistent retrieval over policies, product docs, KYC procedures, and internal support runbooks.
For banking teams, this is the difference between a chat demo and an agent that can answer questions from approved source material with traceable retrieval.
Prerequisites
- •Python 3.10+
- •A Supabase project with:
- •
SUPABASE_URL - •
SUPABASE_SERVICE_ROLE_KEY - •a Postgres database with
pgvectorenabled
- •
- •A LlamaIndex-compatible embedding model provider:
- •OpenAI, Azure OpenAI, or another supported embedder
- •Installed packages:
- •
llama-index - •
llama-index-vector-stores-supabase - •
supabase - •
python-dotenv
- •
- •A folder of source documents for banking RAG:
- •policy PDFs
- •product FAQs
- •compliance notes
- •support playbooks
Install the packages:
pip install llama-index llama-index-vector-stores-supabase supabase python-dotenv
Integration Steps
- •Set up environment variables and connect to Supabase.
import os
from dotenv import load_dotenv
from supabase import create_client
load_dotenv()
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)
print("Supabase client ready")
- •Create or verify the vector table in Supabase.
If you are using the LlamaIndex Supabase vector store, your table needs a vector column and metadata fields. A common setup looks like this:
create extension if not exists vector;
create table if not exists bank_documents (
id bigserial primary key,
content text,
metadata jsonb,
embedding vector(1536)
);
If your embedding model uses a different dimension, match it here.
- •Load banking documents into LlamaIndex and push them into Supabase.
This example uses the LlamaIndex document loader and Supabase vector store integration.
import os
from dotenv import load_dotenv
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex, StorageContext
from llama_index.core.node_parser import SentenceSplitter
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.vector_stores.supabase import SupabaseVectorStore
load_dotenv()
documents = SimpleDirectoryReader("./bank_docs").load_data()
embed_model = OpenAIEmbedding(model="text-embedding-3-small")
vector_store = SupabaseVectorStore(
postgres_connection_string=os.environ["SUPABASE_POSTGRES_CONNECTION_STRING"],
table_name="bank_documents",
embed_dim=1536,
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents,
storage_context=storage_context,
embed_model=embed_model,
transformations=[SentenceSplitter(chunk_size=512, chunk_overlap=50)],
)
print("Documents indexed into Supabase")
- •Build a query engine for RAG responses.
LlamaIndex will retrieve relevant chunks from Supabase and synthesize an answer from them.
from llama_index.core.query_engine import RetrieverQueryEngine
query_engine = index.as_query_engine(
similarity_top_k=5,
response_mode="compact",
)
response = query_engine.query(
"What is the procedure for escalating a suspicious wire transfer?"
)
print(response)
- •Add metadata filters for banking-specific access control.
In banking systems, not every user should see every document. Use metadata like business unit, region, or policy type to constrain retrieval.
from llama_index.core.vector_stores import MetadataFilters, ExactMatchFilter
filters = MetadataFilters(filters=[
ExactMatchFilter(key="department", value="compliance"),
ExactMatchFilter(key="region", value="eu"),
])
query_engine = index.as_query_engine(
similarity_top_k=3,
filters=filters,
)
response = query_engine.query("How do we handle SAR escalation timelines?")
print(response)
That pattern matters because it keeps your agent scoped to approved content instead of pulling from the entire corpus.
Testing the Integration
Run a smoke test against a known question whose answer exists in your indexed documents.
test_query = "What documents are required to open a business account?"
result = query_engine.query(test_query)
print("QUERY:", test_query)
print("ANSWER:", result.response)
print("SOURCES:")
for node in result.source_nodes[:3]:
print("-", node.node.metadata.get("file_name", "unknown"), "| score:", node.score)
Expected output should look like this:
QUERY: What documents are required to open a business account?
ANSWER: The required documents include government-issued ID, proof of address, business registration certificate, and beneficial ownership details.
SOURCES:
- onboarding_policy.pdf | score: 0.91
- kyc_playbook.md | score: 0.87
If you get empty sources or low-quality answers, check these first:
- •embedding dimension matches the Supabase vector column
- •documents were actually inserted into
bank_documents - •the query uses the same embedding model as ingestion
- •your metadata filters are not too restrictive
Real-World Use Cases
- •
Compliance assistant
- •Answer internal questions about AML, KYC, SAR escalation, retention rules, and policy exceptions using only approved documents.
- •
Customer support copilot
- •Let agents ask natural-language questions about account opening, card disputes, loan eligibility, and fee schedules while retrieving from controlled knowledge bases.
- •
Operations runbook agent
- •Search incident playbooks, payment failure procedures, reconciliation steps, and branch operations docs without exposing raw database access.
This stack works well when you need durable retrieval with clear control over what gets indexed and queried. LlamaIndex handles the agent side cleanly; Supabase gives you persistence and operational simplicity without introducing another search system to manage.
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