Langchain/Weaviate

Description

Subject: Issue with weaviate.Client in LangChain: ValueError: client should be an instance of weaviate.Client, got <class ‘weaviate.client.WeaviateClient’>

Message:

Hi everyone,

I’ve been working on integrating Weaviate with LangChain to create a retriever for semantic search. However, I’m encountering an issue when trying to use the Weaviate class from LangChain to create a retriever. Here’s the error I’m getting:

ValueError: client should be an instance of weaviate.Client, got <class 'weaviate.client.WeaviateClient'>
Context

I’m using the following code to connect to Weaviate and create a retriever:

import os
from weaviate import connect_to_local
from weaviate.config import AdditionalConfig, Timeout
from langchain.vectorstores import Weaviate
from langchain.embeddings import OpenAIEmbeddings

# Connect to Weaviate
client = connect_to_local(
    headers={"X-OpenAI-Api-Key": os.getenv("OPENAI_APIKEY")},
    additional_config=AdditionalConfig(
        timeout=Timeout(init=10, query=60, insert=120)
    )
)

# Initialize embeddings
embeddings = OpenAIEmbeddings(openai_api_key=os.getenv("OPENAI_APIKEY"))

# Create a Weaviate retriever
retriever = Weaviate(
    client=client,
    index_name="EmailQuery",
    text_key=["subject", "beneficiary_email", "manager_response", "topic"],
    embedding=embeddings
).as_retriever()

Has anyone else encountered this issue when using LangChain with the latest Weaviate client?

Any additional Information

langchain-community== 0.2.11
langchain-weaviate==0.0.3
weaviate-client== 4.8.1

hi @Tatali !!

WElcome to our community :hugs:

I believe you are using the old Langchain integration.

Check here a nice recipe on how to use it:

Let me know if that helps!

THanks!

1 Like

Thanks @DudaNogueira for you reply.
I found the correct code to use in the Notebook.

1 Like

Awesome!

You can check the langchain module for this integration here:

Happy coding!