community: Fixed schema discrepancy in from_texts function for weaviate vectorstore (#16693)

* Description: Fixed schema discrepancy in **from_texts** function for
weaviate vectorstore which created a redundant property "key" inside a
class.
* Issue: Fixed: https://github.com/langchain-ai/langchain/issues/16692
* Twitter handle: @pashvamehta1
This commit is contained in:
Pashva Mehta 2024-01-29 06:23:31 +05:30 committed by GitHub
parent ba70630829
commit 22d90800c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,12 +25,12 @@ if TYPE_CHECKING:
import weaviate import weaviate
def _default_schema(index_name: str) -> Dict: def _default_schema(index_name: str, text_key: str) -> Dict:
return { return {
"class": index_name, "class": index_name,
"properties": [ "properties": [
{ {
"name": "text", "name": text_key,
"dataType": ["text"], "dataType": ["text"],
} }
], ],
@ -460,7 +460,7 @@ class Weaviate(VectorStore):
client.batch.configure(batch_size=batch_size) client.batch.configure(batch_size=batch_size)
index_name = index_name or f"LangChain_{uuid4().hex}" index_name = index_name or f"LangChain_{uuid4().hex}"
schema = _default_schema(index_name) schema = _default_schema(index_name, text_key)
# check whether the index already exists # check whether the index already exists
if not client.schema.exists(index_name): if not client.schema.exists(index_name):
client.schema.create_class(schema) client.schema.create_class(schema)