Syed Mujeeb H
Syed Mujeeb H

Reputation: 81

Langchain doesn't work with Weaviate vector database - Getting ValueError

from langchain.vectorstores.weaviate import Weaviate
from langchain.llms import OpenAI
from langchain.chains import ChatVectorDBChain,ConversationalRetrievalChain,RetrievalQAWithSourcesChain,RetrievalQA
import weaviate
from langchain.prompts.prompt import PromptTemplate
# API Key needs to be passed in playground
OPEN_API_KEY="sk-"

# Connect to Weaviate server - API Key needs to be passed in playground
auth_config = weaviate.auth.AuthApiKey(
    api_key="api_key")
client = weaviate.Client(
    url="https://abc.weaviate.network",
    auth_client_secret=auth_config,
    additional_headers={
        "X-OpenAI-Api-Key": OPEN_API_KEY
    }
)
vectorstore = Weaviate(client, "Products", "description")
llm = OpenAI(model_name="text-davinci-003", temperature=0,
             max_tokens=200, openai_api_key=OPEN_API_KEY)

template = """
Return product and price information 
--------------------
{summaries}
"""

prompt = PromptTemplate(
    input_variables=["summaries"],
    template=template,
)

chain = RetrievalQAWithSourcesChain.from_chain_type(llm=llm,  retriever=vectorstore.as_retriever(),
                                                     return_source_documents=False,
                                                 chain_type_kwargs = {"prompt": prompt}
       )


result = chain("top rated watches", return_only_outputs=True)
print(result)

raise ValueError(f"Error during query: {result['errors']}")

ValueError: Error during query: [{'locations': [{'column': 24, 'line': 1}], 'message': 'Unknown argument "nearText" on field "Products" of type "GetObjectsObj". Did you mean "nearVector" or "nearObject"?', 'path': None}]

Tried various Chain Methods like

ChatVectorDBChain,ConversationalRetrievalChain,RetrievalQAWithSourcesChain,RetrievalQA

Upvotes: 0

Views: 3324

Answers (1)

Jp Hwang
Jp Hwang

Reputation: 159

Update (May/2023)

If using weaviate with langchain, it is now not necessary to configure weaviate to use a vectorizer as langchain will take care of it.

Original answer below:


If you're getting this error - that means that Weaviate is getting a text input but it doesn't have a vectorizer set up to convert that input to a vector. So it can't perform a vector search.

ValueError: Error during query: [{'locations': [{'column': 24, 'line': 1}], 'message': 'Unknown argument "nearText" on field "Products" of type "GetObjectsObj". Did you mean "nearVector" or "nearObject"?', 'path': None}]

If you're using a WCS instance, it should have the text2vec-openai module enabled, but I would ask you to check if you've set it up as the vectorizer in the schema.

See, for example, how to do so here: https://weaviate.io/developers/weaviate/configuration/schema-configuration#specify-a-vectorizer

Upvotes: 3

Related Questions