noban
July 19, 2024, 8:22am
1
Description
I literally can’t find documentation on how to use (create and perform vector search) namedVectors (like 2 vectors per collection) using my custom vectors. Can anyone point me to the sample script showing how to do that, preferably using V4 syntax?
hi @noban !!
Welcome to our community!
Sorry! Missed this message.
Just discovered some messages that went under my radar
Hope you were able to solve this already
Luckly, I have just crafted some sample code that can help you on this topic (or for other in the future):
hi @Anna_Caroline_Symond !!
Welcome to our community
This message comes directly from hugging face Api. It indicates that your Hugging Face api token is wrong, not Weaviate’s.
Also, there are some other issues with this code, like not passing the vectors your encoded yourself. This will trigger Weaviate to vectorize your object using the Hugging Face.
You also created a named vector that uses title property as source, but was using text as the property receiving the data.
I also ch…
This example shows how to use a custom embed model (running locally), that is also offered by Hugging face.
Now, if you provide the named vectors, like in here:
batch.add_object(
properties={"title": line},
vector={
"title_vector": vector
}
)
Weaviate will not reach out to Hugging face to vectorize the object.
While performing searches, you can do the same. For example:
client.connect()
collection = client.collections.get("Test")
query_vector = model.encode(["pet animals"])
objects = collection.query.near_vector(
near_vector=query_vector[0],
return_metadata=wvc.query.MetadataQuery(distance=True),
include_vector=True,
target_vector="title_vector"
).objects
for object in objects:
print("#" * 10)
print(object.metadata.distance)
print(object.properties)
Let me know if this helps!
Thanks!