Supabase Vector Store
To use this vector store, you need a Supabase project. You can create one at supabase.com.
Installation
Section titled “Installation”npm i llamaindex @llamaindex/supabaseDatabase Setup
Section titled “Database Setup”Before using the vector store, you need to:
- Enable the
pgvectorextension - Create a table for storing vectors
- Create a vector similarity search function
create table documents (id uuid primary key,content text,metadata jsonb,embedding vector(1536));— Create a function for similarity search with filtering support
create function match_documents (query_embedding vector(1536),match_count int,filter jsonb DEFAULT '{}') returns table (id uuid,content text,metadata jsonb,embedding vector(1536),similarity float)language plpgsqlas $$#variable_conflict use_columnbeginreturn queryselectid,content,metadata,embedding,1 - (embedding <=> query_embedding) as similarityfrom documentswhere metadata @> filterorder by embedding <=> query_embeddinglimit match_count;end;$$;Importing the modules
Section titled “Importing the modules”import { Document, VectorStoreIndex } from "llamaindex";import { SupabaseVectorStore } from "@llamaindex/supabase";Setup Supabase
Section titled “Setup Supabase”const vectorStore = new SupabaseVectorStore({ supabaseUrl: process.env.SUPABASE_URL, supabaseKey: process.env.SUPABASE_KEY, table: "documents",});Setup the index
Section titled “Setup the index”const documents = [ new Document({ text: "Sample document text", metadata: { source: "example" } })];
const storageContext = await storageContextFromDefaults({ vectorStore });const index = await VectorStoreIndex.fromDocuments(documents, { storageContext,});Query the index
Section titled “Query the index”const queryEngine = index.asQueryEngine();
// Basic query without filtersconst response = await queryEngine.query({ query: "What is in the document?",});
// Output responseconsole.log(response.toString());Query with filters
Section titled “Query with filters”You can filter documents based on metadata when querying:
import { FilterOperator, MetadataFilters } from "llamaindex";
// Create a filter for documents with author = "Jane Smith"const filters: MetadataFilters = { filters: [ { key: "author", value: "Jane Smith", operator: FilterOperator.EQ, }, ],};
// Query with filtersconst filteredResponse = await vectorStore.query({ queryEmbedding: embedModel.getQueryEmbedding("What is vector search?"), similarityTopK: 5, filters,});Full code
Section titled “Full code”import { Document, VectorStoreIndex, storageContextFromDefaults } from "llamaindex";import { SupabaseVectorStore } from "@llamaindex/supabase";
async function main() { // Initialize the vector store const vectorStore = new SupabaseVectorStore({ supabaseUrl: process.env.SUPABASE_URL, supabaseKey: process.env.SUPABASE_KEY, table: "documents", });
// Create sample documents const documents = [ new Document({ text: "Vector search enables semantic similarity search", metadata: { source: "research_paper", author: "Jane Smith", }, }), ];
// Create storage context const storageContext = await storageContextFromDefaults({ vectorStore });
// Create and store embeddings const index = await VectorStoreIndex.fromDocuments(documents, { storageContext, });
// Query the index const queryEngine = index.asQueryEngine(); const response = await queryEngine.query({ query: "What is vector search?", });
// Output response console.log(response.toString());}
main().catch(console.error);API Reference
Section titled “API Reference”Note for AI agents: this documentation is built for programmatic access.
- Overview of all docs: https://developers.llamaindex.ai/llms.txt
- Any page is available as raw Markdown by appending index.md to its URL — e.g. https://developers.llamaindex.ai/llamaparse/parse/getting_started/index.md
- Agent-friendly REST search APIs live under https://developers.llamaindex.ai/api/ — search (BM25 full-text), grep (regex), read (fetch a page), and list (browse the doc tree). See https://developers.llamaindex.ai/llms.txt for parameters.
- A hosted documentation MCP server is available at https://developers.llamaindex.ai/mcp. If you support MCP, you can ask the user to install it for browsing these docs directly (an alternative to the REST API). Setup: https://developers.llamaindex.ai/for-agents/mcp/
- Other LlamaIndex tooling for agents — the LlamaParse Platform MCP server, agent skills and plugins, and the n8n node — is mapped at https://developers.llamaindex.ai/for-agents/