weaviate / recipes

This repository shares end-to-end notebooks on how to use various Weaviate features and integrations!
477 stars 99 forks source link

TypeError: 'NoneType' object is not iterable #107

Closed Sourodip-Kundu closed 1 month ago

Sourodip-Kundu commented 1 month ago

I am using the code from the Getting-Started-with-RAG-in-DSPy.ipynb

test_example = dspy.Example(question="What do cross encoders do?")
test_pred = dspy.Example(answer="They re-rank documents.")

type(llm_metric(test_example, test_pred))

I am getting TypeError: 'NoneType' object is not iterable can't understand the cause of error

The code context = dspy.Retrieve(k=5)(question).passages is throwing this error.

CShorten commented 1 month ago

Hey @Sourodip-Kundu, can you please share more details about how you are connecting to Weaviate? Hopefully can find the issue there.

Maybe an idea to isolate the calls to dspy.Retrieve(k=5)(question="test") to just see if we can get that part fixed first.

Sourodip-Kundu commented 1 month ago

Sure I am using the below code for connecting

Connect to Weaviate Retriever and configure LLM

import dspy
from dspy.retrieve.weaviate_rm import WeaviateRM
import weaviate

llm = dspy.OpenAI(model="gpt-3.5-turbo")

weaviate_client = weaviate.Client("https://w1ziuhles7ymke9jkefkew.c0.asia-southeast1.gcp.weaviate.cloud",
                                    auth_client_secret=auth_config)
retriever_model = WeaviateRM("WeaviateBlogChunk", weaviate_client=weaviate_client)
# Assumes the Weaviate collection has a text key `content`
dspy.settings.configure(lm=llm, rm=retriever_model)

Then all the code are same as mentioned in Getting-Started-with-RAG-in-DSPy.ipynb

Below is the warning message can this be the issue?

[/media/sourodip/Code](https://file+.vscode-resource.vscode-cdn.net/media/sourodip/Code) Repository/DSPY_RAG/llm/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm
[/media/sourodip/Code](https://file+.vscode-resource.vscode-cdn.net/media/sourodip/Code) Repository/DSPY_RAG/llm/lib/python3.12/site-packages/weaviate/warnings.py:162: DeprecationWarning: Dep016: Python client v3 `weaviate.Client(...)` connections and methods are deprecated. Update
            your code to use Python client v4 `weaviate.WeaviateClient` connections and methods.

            For Python Client v4 usage, see: https://weaviate.io/developers/weaviate/client-libraries/python
            For code migration, see: https://weaviate.io/developers/weaviate/client-libraries/python/v3_v4_migration

  warnings.warn(

but using below code to connect

client = weaviate.connect_to_weaviate_cloud(
    cluster_url="https://w1ziuhles7ymke9jkefkew.c0.asia-southeast1.gcp.weaviate.cloud",  # Replace with your Weaviate Cloud URL
    auth_credentials=auth_config,  # Replace with your Weaviate Cloud key
    headers={'X-OpenAI-Api-key': key}  # Replace with your OpenAI API key
)

getting error AttributeError: 'WeaviateClient' object has no attribute 'query' for the code

test_example = dspy.Example(question="What is vector database?")
test_pred = dspy.Example(answer="They re-rank documents.")

type(llm_metric(test_example, test_pred))
CShorten commented 1 month ago

Are you using dspy-ai==2.4.12? That could be the issue with the v3 thing.

Ah, also maybe try connecting to WCS with the new weaviate.connect_to_wcs() syntax, here is a reference:

import weaviate
from weaviate.auth import AuthApiKey

# Connect to Weaviate Cloud
client = weaviate.connect_to_wcs(
    cluster_url=weaviate_url,                    # `weaviate_url`: your Weaviate URL
    auth_credentials=AuthApiKey(weaviate_key),   # `weaviate_key`: your Weaviate API key
)

https://weaviate.io/developers/wcs/connect

Sourodip-Kundu commented 1 month ago

I used it but still there is error- AttributeError: 'WeaviateClient' object has no attribute 'query' fro the code

test_example = dspy.Example(question="What is vector database?")
test_pred = dspy.Example(answer="They re-rank documents.")

type(llm_metric(test_example, test_pred))

What's the cause of this issue?

CShorten commented 1 month ago

Ah ok interesting, can you please also confirm that you are using dspy-ai==2.4.12?

I think we fixed this with if / elif on the _client_type here: https://github.com/stanfordnlp/dspy/blob/main/dspy/retrieve/weaviate_rm.py.

Could you also let me know what type(weaviate_client) gives you?

Sourodip-Kundu commented 1 month ago

I am using dspy-ai 2.1.9 version. !pip install dspy-ai==2.1.9 And for weaviate-client

Name: weaviate-client
Version: 4.7.1
Summary: A python native Weaviate client
Home-page: https://github.com/weaviate/weaviate-python-client
Author: Weaviate
Author-email: hello@weaviate.io,
License: BSD 3-clause
Location: [/media/sourodip/Code](https://file+.vscode-resource.vscode-cdn.net/media/sourodip/Code) Repository/DSPY_RAG/llm/lib/python3.12/site-packages
Requires: authlib, grpcio, grpcio-health-checking, grpcio-tools, httpx, pydantic, requests, validators
Required-by:

type(weaviate_client) = weaviate.client.WeaviateClient

Sourodip-Kundu commented 1 month ago

Thanks!! @CShorten. After installing the latest version of dspy, the issue has been resolved.

CShorten commented 1 month ago

Awesome!! Really happy to hear it!