Supabase class

Vector store for Supabase Vector embedding database.

It assumes a database with the pg_vector extension, containing a tableName (default: documents) and a postgresFunctionName (default: match_documents) defined as follows:

 -- Enable the "vector" extension
create extension vector
with
  schema extensions;

-- Create table to store the documents
create table documents (
  id bigserial primary key,
  content text,
  metadata jsonb,
  embedding vector(1536)
);

-- Create PostgreSQL function to query documents
create or replace function match_documents (
  query_embedding vector(1536),
  match_count int,
  match_threshold float,
  filter jsonb
) returns table (
  id bigint,
  content text,
  metadata jsonb,
  similarity float
)
language sql stable
as $$
  select
    documents.id,
    documents.content,
    documents.metadata,
    1 - (documents.embedding <=> query_embedding) as similarity
from documents
where metadata @> filter
  and 1 - (documents.embedding <=> query_embedding) > match_threshold
order by (documents.embedding <=> query_embedding) asc
    limit match_count;
$$;

See documentation for more details:

Constructors

Supabase({String tableName = 'documents', required String supabaseUrl, required String supabaseKey, Map<String, String> headers = const {}, Client? client, required Embeddings embeddings})
Creates a new Supabase instance.

Properties

embeddings → Embeddings
The embeddings model used to embed documents.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
postgresFunctionName String
The name of the PostgreSQL function that executes the query.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tableName String
The Supabase table name.
final

Methods

addDocuments({required List<Document> documents}) Future<List<String>>
Runs more documents through the embeddings and add to the vector store.
inherited
addVectors({required List<List<double>> vectors, required List<Document> documents}) Future<List<String>>
Runs more texts through the embeddings and add to the vector store.
asRetriever({VectorStoreRetrieverOptions defaultOptions = const VectorStoreRetrieverOptions()}) → VectorStoreRetriever<VectorStore>
Returns a VectorStoreRetriever that uses this vector store.
inherited
delete({required List<String> ids}) Future<void>
Delete by vector ID.
maxMarginalRelevanceSearch({required String query, VectorStoreMMRSearch config = const VectorStoreMMRSearch()}) Future<List<Document>>
Returns docs selected using the maximal marginal relevance algorithm (MMR) for the given query.
inherited
maxMarginalRelevanceSearchByVector({required List<double> embedding, VectorStoreMMRSearch config = const VectorStoreMMRSearch()}) List<Document>
Returns docs selected using the maximal marginal relevance algorithm (MMR) for the given embedding vector.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
Returns docs most similar to query using specified search type.
inherited
similaritySearch({required String query, VectorStoreSimilaritySearch config = const VectorStoreSimilaritySearch()}) Future<List<Document>>
Returns docs most similar to query using similarity.
inherited
similaritySearchByVector({required List<double> embedding, VectorStoreSimilaritySearch config = const VectorStoreSimilaritySearch()}) Future<List<Document>>
Returns docs most similar to embedding vector using similarity.
inherited
similaritySearchByVectorWithScores({required List<double> embedding, VectorStoreSimilaritySearch config = const VectorStoreSimilaritySearch()}) Future<List<(Document, double)>>
Returns docs and relevance scores in the range [0, 1], 0 is dissimilar, 1 is most similar.
similaritySearchWithScores({required String query, VectorStoreSimilaritySearch config = const VectorStoreSimilaritySearch()}) Future<List<(Document, double)>>
Returns docs and relevance scores in the range [0, 1]. 0 is dissimilar, 1 is most similar.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited