@ -61,6 +61,7 @@ class SupabaseVectorStore(VectorStore):
client = supabase_client ,
client = supabase_client ,
table_name = " documents " ,
table_name = " documents " ,
query_name = " match_documents " ,
query_name = " match_documents " ,
chunk_size = 500 ,
)
)
To load from an existing table :
To load from an existing table :
@ -88,6 +89,7 @@ class SupabaseVectorStore(VectorStore):
client : supabase . client . Client ,
client : supabase . client . Client ,
embedding : Embeddings ,
embedding : Embeddings ,
table_name : str ,
table_name : str ,
chunk_size : int = 500 ,
query_name : Union [ str , None ] = None ,
query_name : Union [ str , None ] = None ,
) - > None :
) - > None :
""" Initialize with supabase client. """
""" Initialize with supabase client. """
@ -103,6 +105,9 @@ class SupabaseVectorStore(VectorStore):
self . _embedding : Embeddings = embedding
self . _embedding : Embeddings = embedding
self . table_name = table_name or " documents "
self . table_name = table_name or " documents "
self . query_name = query_name or " match_documents "
self . query_name = query_name or " match_documents "
self . chunk_size = chunk_size or 500
# According to the SupabaseVectorStore JS implementation, the best chunk size
# is 500. Though for large datasets it can be too large so it is configurable.
@property
@property
def embeddings ( self ) - > Embeddings :
def embeddings ( self ) - > Embeddings :
@ -130,6 +135,7 @@ class SupabaseVectorStore(VectorStore):
client : Optional [ supabase . client . Client ] = None ,
client : Optional [ supabase . client . Client ] = None ,
table_name : Optional [ str ] = " documents " ,
table_name : Optional [ str ] = " documents " ,
query_name : Union [ str , None ] = " match_documents " ,
query_name : Union [ str , None ] = " match_documents " ,
chunk_size : int = 500 ,
ids : Optional [ List [ str ] ] = None ,
ids : Optional [ List [ str ] ] = None ,
* * kwargs : Any ,
* * kwargs : Any ,
) - > " SupabaseVectorStore " :
) - > " SupabaseVectorStore " :
@ -144,13 +150,14 @@ class SupabaseVectorStore(VectorStore):
embeddings = embedding . embed_documents ( texts )
embeddings = embedding . embed_documents ( texts )
ids = [ str ( uuid . uuid4 ( ) ) for _ in texts ]
ids = [ str ( uuid . uuid4 ( ) ) for _ in texts ]
docs = cls . _texts_to_documents ( texts , metadatas )
docs = cls . _texts_to_documents ( texts , metadatas )
cls . _add_vectors ( client , table_name , embeddings , docs , ids )
cls . _add_vectors ( client , table_name , embeddings , docs , ids , chunk_size )
return cls (
return cls (
client = client ,
client = client ,
embedding = embedding ,
embedding = embedding ,
table_name = table_name ,
table_name = table_name ,
query_name = query_name ,
query_name = query_name ,
chunk_size = chunk_size ,
)
)
def add_vectors (
def add_vectors (
@ -159,7 +166,9 @@ class SupabaseVectorStore(VectorStore):
documents : List [ Document ] ,
documents : List [ Document ] ,
ids : List [ str ] ,
ids : List [ str ] ,
) - > List [ str ] :
) - > List [ str ] :
return self . _add_vectors ( self . _client , self . table_name , vectors , documents , ids )
return self . _add_vectors (
self . _client , self . table_name , vectors , documents , ids , self . chunk_size
)
def similarity_search (
def similarity_search (
self ,
self ,
@ -300,6 +309,7 @@ class SupabaseVectorStore(VectorStore):
vectors : List [ List [ float ] ] ,
vectors : List [ List [ float ] ] ,
documents : List [ Document ] ,
documents : List [ Document ] ,
ids : List [ str ] ,
ids : List [ str ] ,
chunk_size : int ,
) - > List [ str ] :
) - > List [ str ] :
""" Add vectors to Supabase table. """
""" Add vectors to Supabase table. """
@ -313,9 +323,6 @@ class SupabaseVectorStore(VectorStore):
for idx , embedding in enumerate ( vectors )
for idx , embedding in enumerate ( vectors )
]
]
# According to the SupabaseVectorStore JS implementation, the best chunk size
# is 500
chunk_size = 500
id_list : List [ str ] = [ ]
id_list : List [ str ] = [ ]
for i in range ( 0 , len ( rows ) , chunk_size ) :
for i in range ( 0 , len ( rows ) , chunk_size ) :
chunk = rows [ i : i + chunk_size ]
chunk = rows [ i : i + chunk_size ]