langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92k stars 14.64k forks source link

AttributeError: 'WeaviateClient' object has no attribute 'schema' #18809

Closed zohaibdr closed 1 month ago

zohaibdr commented 6 months ago

Checked other resources

Example Code


from langchain_community.vectorstores import Weaviate
from langchain_openai import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
vectorstore = Weaviate.from_documents(
    text_chunks, 
    embeddings, 
    client=client, 
    by_text=False
)

document_content_description = "description"

### Error Message and Stack Trace (if applicable)

```python
AttributeError: 'WeaviateClient' object has no attribute 'schema'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File <command-3980657862137734>, line 6
      2 from langchain_openai import OpenAIEmbeddings
      4 embeddings = OpenAIEmbeddings()
----> 6 vectorstore = Weaviate.from_documents(
      7     text_chunks, 
      8     embeddings, 
      9     client=client, 
     10     by_text=False
     11 )
     13 document_content_description = "telecom documentation"

File /local_disk0/.ephemeral_nfs/envs/pythonEnv-bb42155d-01ee-4da3-9c8c-ce4489c59c93/lib/python3.10/site-packages/langchain_core/vectorstores.py:528, in VectorStore.from_documents(cls, documents, embedding, **kwargs)
    526 texts = [d.page_content for d in documents]
    527 metadatas = [d.metadata for d in documents]
--> 528 return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs)

File /local_disk0/.ephemeral_nfs/envs/pythonEnv-bb42155d-01ee-4da3-9c8c-ce4489c59c93/lib/python3.10/site-packages/langchain_community/vectorstores/weaviate.py:465, in Weaviate.from_texts(cls, texts, embedding, metadatas, client, weaviate_url, weaviate_api_key, batch_size, index_name, text_key, by_text, relevance_score_fn, **kwargs)
    463 schema = _default_schema(index_name, text_key)
    464 # check whether the index already exists
--> 465 if not client.schema.exists(index_name):
    466     client.schema.create_class(schema)
    468 embeddings = embedding.embed_documents(texts) if embedding else None

AttributeError: 'WeaviateClient' object has no attribute 'schema'

### Description

Trying to ingest langchain Document classes into Weaviate Cloud. 
Using the up-to-date version of all libs. 
Followed the tutorial here: https://python.langchain.com/docs/integrations/vectorstores/weaviate
### System Info

langchain==0.1.7
weaviate-client==4.5.1 
weaviate cloud ver. 1.24.1 and 1.23.10 (2 different clusters)

Running in Windows as well on databricks. 
gingters commented 5 months ago

Langchain currently still uses the Weaviate client version 3. You have installed the Weaviate client in version 4, which had many breaking changes in its API.

So when downgrading the client to the latest 3.x, that should work.

xindexer commented 5 months ago

This is true, but V4 is the future of python Weaviate and they have officially moved it out of Beta and are have deprecated V3.

This is the connection message using v3

DeprecationWarning: Dep016: You are using the Weaviate v3 client, which is deprecated. Consider upgrading to the new and improved v4 client instead! See here for usage: https://weaviate.io/developers/weaviate/client-libraries/python

zohaibdr commented 5 months ago

I ended up creating my own retriever wrapping weaviate methods inside langchain's base class.

jansaidashaik1995 commented 5 months ago

@zohaibdr can you please share more details how exactly solved

gingters commented 4 months ago

The new weaviate client is on v4: https://python.langchain.com/docs/integrations/vectorstores/weaviate/