I am trying to use Weaviate with Hugging Face to create vectors to compare semantic similarity, but I keep getting this error: “Every object failed during insertion. Here is the set of all errors: failed with status: 400 error: Authorization header is correct, but the token seems invalid”
When I test to make sure my client is properly connected, it returns true, so I’m confused how the token can be invalid. I’m trying to convert each line in a txt file into a vector, but the error arises when I try to insert the objects themselves. All of my env variables match the keys I was given on WCD and Hugging Face. Also, on Hugging Face, I edited permissions like this:
Here’s my code. The error arises from the line: test.data.insert_many(objs).
import weaviate, os
import weaviate.classes as wvc
from sentence_transformers import SentenceTransformer
client = weaviate.connect_to_weaviate_cloud(
cluster_url= os.getenv("WEAVIATE_INSTANCE_URL"),
auth_credentials=weaviate.auth.AuthApiKey(os.getenv("W_API_KEY")),
headers={
"X-HuggingFace-Api-Key": "H_F_API_KEY"
}
)
print(os.getenv("H_F_API_KEY"))
print(client.is_ready())
client.collections.delete("Test")
try:
test = client.collections.create(
name="Test",
vectorizer_config=[
wvc.config.Configure.NamedVectors.text2vec_huggingface(
name="title_vector",
source_properties=["title"],
model="sentence-transformers/all-MiniLM-L6-v2",
)
],
)
model = SentenceTransformer("all-MiniLM-L6-v2")
with open('test1.txt', 'r') as file:
lines = [line.strip() for line in file.readlines()]
vectors = model.encode(lines)
objs = []
for line,vector in zip(lines, vectors):
objs.append({
"text": line,
})
test = client.collections.get("Test")
test.data.insert_many(objs)
finally:
client.close()