Dear all,
I’m completely a newbie. I would like to configure to use text2vec-palm (Google PaLM instead of open ai, as given in Weaviate’s example). Refer to my code fragments below, I get error when executing in code fragment 3: batch.add_data_object…
My CoLaboratory notebook complains that google authentication is missing, suggesting to provide oauth token etc.
I’m stuck at this point. Grateful if someone can shown you sample code that uses text2vec-palm.
Thanks a lot!
code segment 1 - client config
import weaviate
auth_config = weaviate.AuthApiKey(api_key=“MY_WEAVIATE_KEY”)
client = weaviate.Client(
url=“https://my_weaviate.weaviate.network”,
auth_client_secret=auth_config,
additional_headers = {
"X-Palm-Api-Key": "MY_GOOGLE_PROJ_API_KEY" # Replace with your API key
}
)
code fragment 2 - class def.
class_obj = {
“class”: “Question”,
"moduleConfig": {
"vectorizeClassName": "true",
"text2vec-palm": {"projectId": "MY_GOOGLE_PROJ_ID }, # projectId is required
"generative-palm": { "projectId": "MY_GOOGLE_PROJ_ID" } # Ensure the `generative-palm` module is used for generative queries, projectId is required
}
}
client.schema.create_class(class_obj)
code fragment 3 - add objects
import requests
import json
resp = requests.get(‘MY_DATA.json’)
data = json.loads(resp.text) # Load data
client.batch.configure(batch_size=100) # Configure batch
with client.batch as batch: # Initialize a batch process
for i, d in enumerate(data): # Batch import data
print(f"importing question: {i+1}“)
properties = {
“answer”: d[“Answer”],
“question”: d[“Question”],
“category”: d[“Category”],
}
print(f"property: {properties}”)
batch.add_data_object(
data_object=properties,
class_name=“Question”
)