community: enable SupabaseVectorStore to support extended table fields (#21762)

Thank you for contributing to LangChain!

- [x] **PR title**: "community: enable SupabaseVectorStore to support
extended table fields"

- [x] **PR message**: 
- Added extension fields to the function _add_vectors so that users can
add other custom fields when insert a record into the database. eg:
    

![image](https://github.com/langchain-ai/langchain/assets/10885578/e1d5ca20-936e-4cab-ba69-8fdd23b8ce8f)

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
缨缨 2024-05-21 07:32:26 +08:00 committed by GitHub
parent 2316635add
commit bd39b2ccdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,7 +151,9 @@ class SupabaseVectorStore(VectorStore):
embeddings = embedding.embed_documents(texts)
ids = [str(uuid.uuid4()) for _ in texts]
docs = cls._texts_to_documents(texts, metadatas)
cls._add_vectors(client, table_name, embeddings, docs, ids, chunk_size)
cls._add_vectors(
client, table_name, embeddings, docs, ids, chunk_size, **kwargs
)
return cls(
client=client,
@ -324,6 +326,7 @@ class SupabaseVectorStore(VectorStore):
documents: List[Document],
ids: List[str],
chunk_size: int,
**kwargs: Any,
) -> List[str]:
"""Add vectors to Supabase table."""
@ -333,10 +336,10 @@ class SupabaseVectorStore(VectorStore):
"content": documents[idx].page_content,
"embedding": embedding,
"metadata": documents[idx].metadata, # type: ignore
**kwargs,
}
for idx, embedding in enumerate(vectors)
]
id_list: List[str] = []
for i in range(0, len(rows), chunk_size):
chunk = rows[i : i + chunk_size]