我已经使用了
pip install weaviate-client
,并且我检查了我的python版本是3.10.5。 docker 一直在使用 'weaviate' 和一个名为 't2v-transformers'images 的 text2vec 转换器运行
当我运行下面的代码时,它返回 from weaviate import * ModuleNotFoundError: No module named 'weaviate'
from weaviate import *
import json
client = Client(
url = "http://localhost:8080/",
)
# specify schema for the data we'll be using
client.schema.delete_class("SimSearch")
class_obj = {
"class": "SimSearch",
"vectorizer": "text2vec-transformers"
}
client.schema.create_class(class_obj)
# download data
import requests
url = 'http://localhost:8000/data.json'
resp = requests.get(url)
data = json.loads(resp.text)
# send data to weaviate, to vectorize
with client.batch as batch:
batch.batch_size=100
# Batch import all data
for i, d in enumerate(data):
print(f"\nimporting datum: {i}")
properties = {
"answer": d["Answer"],
"question": d["Question"],
"category": d["Category"],
}
print(f"properties: {properties}")
client.batch.add_data_object(properties, "SimSearch")
它回来了
from weaviate import * ModuleNotFoundError: No module named 'weaviate'
来自 Weaviate 的 Duda 这里。
这不是导入 weaviate 客户端(客户端 v3 和 v4)的正确方法
import weaviate
import weaviate.classes as wvc
import os
import requests
import json
client = weaviate.connect_to_wcs(
cluster_url=os.getenv("WCS_URL"),
auth_credentials=weaviate.auth.AuthApiKey(os.getenv("WCS_API_KEY")),
headers={
"X-OpenAI-Api-Key": os.environ["OPENAI_APIKEY"] # Replace with your inference API key
}
)
try:
pass # Replace with your code. Close client gracefully in the finally block.
finally:
client.close() # Close client gracefully
如果您使用的是本地实例,无需身份验证,您可以将
weaviate.connecto_to_wcs
替换为 weaviate.connect_to_local
,不带任何参数
如果有帮助请告诉我!
谢谢!