Update supabase docstrings (#8443)

This commit is contained in:
William FH 2023-07-28 23:08:14 -07:00 committed by GitHub
parent f63240649c
commit 3314f54383
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,7 +28,7 @@ if TYPE_CHECKING:
class SupabaseVectorStore(VectorStore): class SupabaseVectorStore(VectorStore):
"""VectorStore for a Supabase postgres database. Assumes you have the `pgvector` """VectorStore for a Supabase postgres database. Assumes you have the `pgvector`
extension installed and a `match_documents` (or similar) function. For more details: extension installed and a `match_documents` (or similar) function. For more details:
https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase https://integrations.langchain.com/vectorstores?integration_name=SupabaseVectorStore
You can implement your own `match_documents` function in order to limit the search You can implement your own `match_documents` function in order to limit the search
space to a subset of documents based on your own authorization or business logic. space to a subset of documents based on your own authorization or business logic.
@ -37,15 +37,49 @@ class SupabaseVectorStore(VectorStore):
If you'd like to use `max_marginal_relevance_search`, please review the instructions If you'd like to use `max_marginal_relevance_search`, please review the instructions
below on modifying the `match_documents` function to return matched embeddings. below on modifying the `match_documents` function to return matched embeddings.
"""
_client: supabase.client.Client
# This is the embedding function. Don't confuse with the embedding vectors. Examples:
# We should perhaps rename the underlying Embedding base class to EmbeddingFunction
# or something .. code-block:: python
_embedding: Embeddings
table_name: str from langchain.embeddings.openai import OpenAIEmbeddings
query_name: str from langchain.schema import Document
from langchain.vectorstores import SupabaseVectorStore
from supabase.client import create_client
docs = [
Document(page_content="foo", metadata={"id": 1}),
]
embeddings = OpenAIEmbeddings()
supabase_client = create_client("my_supabase_url", "my_supabase_key")
vector_store = SupabaseVectorStore.from_documents(
docs,
embeddings,
client=supabase_client,
table_name="documents",
query_name="match_documents",
)
To load from an existing table:
.. code-block:: python
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import SupabaseVectorStore
from supabase.client import create_client
embeddings = OpenAIEmbeddings()
supabase_client = create_client("my_supabase_url", "my_supabase_key")
vector_store = SupabaseVectorStore(
client=supabase_client,
embedding=embeddings,
table_name="documents",
query_name="match_documents",
)
"""
def __init__( def __init__(
self, self,
@ -108,7 +142,7 @@ 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)
_ids = cls._add_vectors(client, table_name, embeddings, docs, ids) cls._add_vectors(client, table_name, embeddings, docs, ids)
return cls( return cls(
client=client, client=client,