Read objects
Instead of querying your database, you can use an ID to retrieve individual objects.
Additional information
Collections act like namespaces, so two different collections could have duplicate IDs between them.
Prior to Weaviate v1.14 you can manipulate objects without specifying the collection name. This method is deprecated. It will be removed in Weaviate v2.0.0.
Starting in v1.20, you can have multi-tenant datasets. When multi-tenancy is enabled, the tenant name is required.
Always include the collection name, and, when enabled, the tenant name.
Get an object by id
Use an ID to retrieve an object. If the id doesn't exist, Weaviate returns a 404 error.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
jeopardy = client.collections.use("JeopardyQuestion")
data_object = jeopardy.query.fetch_object_by_id("00ff6900-e64f-5d94-90db-c8cfa3fc851b")
print(data_object.properties)
Retrieve the object's vector
Object vectors can be retrieved by specifying its return.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
jeopardy = client.collections.use("JeopardyQuestion")
data_object = jeopardy.query.fetch_object_by_id(
"00ff6900-e64f-5d94-90db-c8cfa3fc851b",
include_vector=True
)
print(data_object.vector["default"])
Retrieve named vectors
Where named vectors are used, you can retrieve one or more of them by specifying their names.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
reviews = client.collections.use("WineReviewNV") # Collection with named vectors
vector_names = ["title", "review_body"]
data_object = reviews.query.fetch_object_by_id(
uuid=obj_uuid, # Object UUID
include_vector=vector_names # Specify names of the vectors to include
)
# The vectors are returned in the `vector` property as a dictionary
for n in vector_names:
print(f"Vector '{n}': {data_object.vector[n][:5]}...")
Check object existence
To efficiently check if an object with a given id exists without retrieving it, make a HEAD request to the /v1/objects/ REST endpoint, or use the following client code:
If a snippet doesn't work or you have feedback, please open a GitHub issue.
# generate uuid based on the key properties used during data insert
object_uuid = generate_uuid5({"name": "Author to fetch"})
authors = client.collections.use("Author")
author_exists = authors.data.exists(object_uuid)
print("Author exist: ", author_exists)
Related pages
Questions and feedback
If you have any questions or feedback, let us know in the user forum.
