Schema for DSPY

Following the steps from 1.Getting-Started-with-RAG-in-DSPy.ipynb, unable to execute:

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))

Created a schema class that is based on the data, question and answer:

class_obj = {
    "class": "DSPY",
    "properties": [
        {
            "name": "data",
            "dataType": ["text"],
            # "indexInverted": True 
        },
        {
            "name": "question",
            "dataType": ["text"],
            # "indexInverted": True  
        },
        {
            "name": "answer",
            "dataType": ["text"],
            # "indexInverted": True 
        }
    ],
    "vectorizer": "text2vec-openai",
    "moduleConfig": {
        "text2vec-openai": {},
        "generative-openai": {}  
    }
}

weaviate_client.schema.create_class(class_obj)

###Error start:###

---> 79     results = results["data"]["Get"][self._weaviate_collection_name]
     80     parsed_results = [result["content"] for result in results]
     81     passages.extend(dotdict({"long_text": d}) for d in parsed_results)

KeyError: 'data'

###Error end:###

Server Setup Information

  • Weaviate Server Version: 3.26.2
  • Deployment Method: Cloud
  • Multi Node? Number of Running Nodes: 1
  • Client Language and Version: en

New to weaviate, trying to follow the cookbook on weaviate/dspy to start using it within our app. I think I am missing a step on preparing the db within weaviate before I can follow the cookbook. Any guidance is appreciated, thank you

Hey @EnkiEnil, happy to help! Can you please show me the code for how you initialize the WeaviateRM? If you don’t explicitly pass in a weaviate_collection_text_key it will default to “content”, which I see isn’t in your schema so that is most likely the problem with the Weaviate query.

Hello @CShorten, thanks for the response.

After this, I figured out how to explicitly define this argument:

rm = weaviate_client.schema.get()['classes'][0]['class']
retriever_model = WeaviateRM( rm , weaviate_client = weaviate_client, 
                                   #weaviate_collection_name=" ??? ",
                                   weaviate_collection_text_key="yourOwnTextProperty")

Note: What is weaviate_collection_name ? If I pass this name as a model property in the node name, it returns an error.